-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchip.lua
More file actions
59 lines (47 loc) · 1.29 KB
/
Copy pathchip.lua
File metadata and controls
59 lines (47 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- chips are small collectibles that build up the player's bomb meter
local M = {}
local SIZE = 4
local FRICTION = 3
local PULL_STRENGTH = 1400
M.PULL_RADIUS_IDLE = 80
M.PULL_RADIUS_FIRING = 28
function M.drop(count, x, y)
for i = 1, count do
local angle = math.random() * math.pi * 2
local speed = 50 + math.random() * 40
table.insert(State.chips, {
x = x,
y = y,
vel = { x = math.cos(angle) * speed, y = math.sin(angle) * speed },
r = SIZE / 2,
alive = true,
})
end
end
function M.update(dt, c, player, player_firing)
if not c.alive then
return
end
c.vel.x -= c.vel.x * FRICTION * dt
c.vel.y -= c.vel.y * FRICTION * dt
local px = player.x + SPR_SIZE / 2
local py = player.y + SPR_SIZE / 2
local dx = px - c.x
local dy = py - c.y
local dist = math.sqrt(dx * dx + dy * dy)
local pull_radius = player_firing and M.PULL_RADIUS_FIRING or M.PULL_RADIUS_IDLE
if player.alive and dist > 0 and dist < pull_radius then
c.vel.x += (dx / dist) * PULL_STRENGTH * dt
c.vel.y += (dy / dist) * PULL_STRENGTH * dt
end
c.x += c.vel.x * dt
c.y += c.vel.y * dt
end
M.color = gfx.COLOR_YELLOW
function M.draw(c)
if not c.alive then
return
end
gfx.rect_fill(c.x - SIZE / 2, c.y - SIZE / 2, SIZE, SIZE, M.color)
end
return M