Skip to content

Commit 508a03f

Browse files
committed
removed fade from droplet and plant
1 parent bcf4f0d commit 508a03f

2 files changed

Lines changed: 37 additions & 18 deletions

File tree

watch/app/src/main/java/com/imsproject/watch/Properties.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ var GRASS_PLANT_STROKE_WIDTH = 4.5f
123123
//shared
124124
var GRASS_WATER_RADIUS = 0f //initialized later
125125
var GRASS_WATER_ANGLE = 36
126+
var GRASS_WATER_VISIBILITY_THRESHOLD = 450
126127

127128
// ================== After game questions =============== |
128129
const val FIRST_QUESTION = "עד כמה חשת תחושת \"ביחד\" עם השותפ/ה במשחקון הזה?"

watch/app/src/main/java/com/imsproject/watch/view/FlowerGardenActivity.kt

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.imsproject.watch.view
22

33
import android.annotation.SuppressLint
44
import android.os.Bundle
5+
import android.util.Log
56
import androidx.activity.compose.setContent
67
import androidx.activity.viewModels
78
import androidx.compose.foundation.BorderStroke
@@ -46,6 +47,7 @@ import com.imsproject.watch.SCREEN_RADIUS
4647
import com.imsproject.watch.GRASS_PLANT_BASE_HEIGHT
4748
import com.imsproject.watch.GRASS_PLANT_BASE_WIDTH
4849
import com.imsproject.watch.GRASS_PLANT_STROKE_WIDTH
50+
import com.imsproject.watch.GRASS_WATER_VISIBILITY_THRESHOLD
4951
import com.imsproject.watch.WATER_BLUE_COLOR
5052
import com.imsproject.watch.WATER_DROPLET_FADE_COEFFICIENT
5153
import com.imsproject.watch.WATER_DROPLET_FADE_THRESHOLD
@@ -54,6 +56,7 @@ import com.imsproject.watch.viewmodel.FlowerGardenViewModel
5456
import com.imsproject.watch.viewmodel.FlowerGardenViewModel.Flower
5557
import com.imsproject.watch.viewmodel.GameViewModel
5658
import kotlinx.coroutines.delay
59+
import kotlin.math.abs
5760
import kotlin.math.cos
5861
import kotlin.math.exp
5962
import kotlin.math.max
@@ -208,38 +211,53 @@ class FlowerGardenActivity : GameActivity(GameType.FLOWER_GARDEN) {
208211
val it = viewModel.waterDropletSets.iterator()
209212
while (it.hasNext()) {
210213
val waterDropletSet = it.next()
214+
val currTimestamp = viewModel.getCurrentGameTime()
211215

212-
// decrease the opacity
213-
val currDropletColor = waterDropletSet.color
214-
val nextAlpha = currDropletColor.alpha * exp(WATER_DROPLET_FADE_COEFFICIENT
215-
* waterDropletSet.time)
216-
waterDropletSet.time++
217-
waterDropletSet.color = currDropletColor.copy(nextAlpha)
218-
219-
//remove done water droplets
220-
if(waterDropletSet.color.alpha <= WATER_DROPLET_FADE_THRESHOLD) {
216+
//remove done water droplets after 250ms, no fade
217+
if(abs(waterDropletSet.timestamp - currTimestamp) >= GRASS_WATER_VISIBILITY_THRESHOLD) {
218+
waterDropletSet.color = waterDropletSet.color.copy(alpha=0f) //trigger redraw
221219
it.remove()
222220
continue
223221
}
222+
223+
// fade effect
224+
// val currDropletColor = waterDropletSet.color
225+
// val nextAlpha = currDropletColor.alpha * exp(WATER_DROPLET_FADE_COEFFICIENT
226+
// * waterDropletSet.time)
227+
// waterDropletSet.time++
228+
// waterDropletSet.color = currDropletColor.copy(nextAlpha)
229+
//
230+
// //remove done water droplets
231+
// if(waterDropletSet.color.alpha <= WATER_DROPLET_FADE_THRESHOLD) {
232+
// it.remove()
233+
// continue
234+
// }
224235
}
225236

226237
// animate plant grass
227238
val it2 = viewModel.grassPlantSets.iterator()
228239
while (it2.hasNext()) {
229240
val grassPlantSet = it2.next()
241+
val currTimestamp = viewModel.getCurrentGameTime()
230242

231-
// decrease the opacity
232-
val currPlantColor = grassPlantSet.color
233-
val nextAlpha = currPlantColor.alpha * exp(GRASS_PLANT_FADE_COEFFICIENT
234-
* grassPlantSet.time)
235-
grassPlantSet.time++
236-
grassPlantSet.color = currPlantColor.copy(nextAlpha)
237-
238-
//remove done water droplets
239-
if(grassPlantSet.color.alpha <= GRASS_PLANT_FADE_THRESHOLD) {
243+
//remove done water droplets after 250ms, no fade
244+
if(abs(grassPlantSet.timestamp - currTimestamp) >= GRASS_WATER_VISIBILITY_THRESHOLD) {
245+
grassPlantSet.color = grassPlantSet.color.copy(alpha=0f) //trigger redraw
240246
it2.remove()
241247
continue
242248
}
249+
// fade effect
250+
// val currPlantColor = grassPlantSet.color
251+
// val nextAlpha = currPlantColor.alpha * exp(GRASS_PLANT_FADE_COEFFICIENT
252+
// * grassPlantSet.time)
253+
// grassPlantSet.time++
254+
// grassPlantSet.color = currPlantColor.copy(nextAlpha)
255+
//
256+
// //remove done water droplets
257+
// if(grassPlantSet.color.alpha <= GRASS_PLANT_FADE_THRESHOLD) {
258+
// it2.remove()
259+
// continue
260+
// }
243261
}
244262
delay(16)
245263
}

0 commit comments

Comments
 (0)