| 1 | local v2 = require 'dokidoki.v2' |
| 2 | |
| 3 | local SPEED = 0.2 |
| 4 | local LIFETIME = 10 |
| 5 | local FADE_TIME = 2 |
| 6 | |
| 7 | local random_direction = v2(math.random() < 0.5 and 1 or -1, 0) |
| 8 | local random_scale = math.random() * 0.75 + 0.5 |
| 9 | local random_speed = math.random() + 0.5 |
| 10 | local random_opacity = math.random() * 0.1 + 0.1 |
| 11 | |
| 12 | local since_alive = 0 |
| 13 | |
| 14 | function update() |
| 15 | since_alive = since_alive + 1/60 |
| 16 | |
| 17 | self.transform.scale_x = random_scale |
| 18 | self.transform.scale_y = random_scale |
| 19 | |
| 20 | self.transform.facing = random_direction |
| 21 | |
| 22 | self.transform.pos = self.transform.pos + random_direction * SPEED * random_speed |
| 23 | |
| 24 | if since_alive < FADE_TIME then |
| 25 | self.sprite.color[4] = since_alive / FADE_TIME * random_opacity |
| 26 | else |
| 27 | self.sprite.color[4] = math.min(1 - (since_alive - LIFETIME + FADE_TIME) / FADE_TIME, 1) * random_opacity |
| 28 | end |
| 29 | if since_alive > LIFETIME then self.dead = true end |
| 30 | end |