Debian Codegraph @

scripts/debris.lua

raw symbols SCIP
1 local v2 = require 'dokidoki.v2'
2
3 local SPEED = 0.2
4 local LIFETIME = 8
5 local FADE_TIME = 2
6
7 local random_direction = v2.unit(math.random() * 2 * math.pi)
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.25 + 0.4
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 + v2.rotate(random_direction, math.sin(since_alive) * 0.5) * 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