@@ -2,6 +2,7 @@ package com.imsproject.watch.view
22
33import android.annotation.SuppressLint
44import android.os.Bundle
5+ import android.util.Log
56import androidx.activity.compose.setContent
67import androidx.activity.viewModels
78import androidx.compose.foundation.BorderStroke
@@ -46,6 +47,7 @@ import com.imsproject.watch.SCREEN_RADIUS
4647import com.imsproject.watch.GRASS_PLANT_BASE_HEIGHT
4748import com.imsproject.watch.GRASS_PLANT_BASE_WIDTH
4849import com.imsproject.watch.GRASS_PLANT_STROKE_WIDTH
50+ import com.imsproject.watch.GRASS_WATER_VISIBILITY_THRESHOLD
4951import com.imsproject.watch.WATER_BLUE_COLOR
5052import com.imsproject.watch.WATER_DROPLET_FADE_COEFFICIENT
5153import com.imsproject.watch.WATER_DROPLET_FADE_THRESHOLD
@@ -54,6 +56,7 @@ import com.imsproject.watch.viewmodel.FlowerGardenViewModel
5456import com.imsproject.watch.viewmodel.FlowerGardenViewModel.Flower
5557import com.imsproject.watch.viewmodel.GameViewModel
5658import kotlinx.coroutines.delay
59+ import kotlin.math.abs
5760import kotlin.math.cos
5861import kotlin.math.exp
5962import 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