-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_tester.lua
91 lines (70 loc) · 1.85 KB
/
state_tester.lua
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require("class")
require("spatialgrid")
require("emitter")
require("particles/hydrogen")
require("particles/oxygen")
require("particles/lava")
require("particles/block")
StateTester = class()
function StateTester:_init()
self.paused = false
-- The grid which is used for broad-phased collision detection.
self.spatialGrid = SpatialGrid()
self.mousePosition = {
x = 0,
y = 0,
}
-- TODO: fix the bug with the collision left/right. It's doing some weird stuff.
self.p1 = Lava()
self.p1.x = 150
self.p1.y = 500
self.p1.dx = -150
self.p2 = Lava()
self.p2.x = 200
self.p2.y = 480
self.p2.dx = -50
self.p2.color = {1, 0,0, 1}
end
function StateTester:mousePressed(x, y, button, istouch, presses)
end
function StateTester:mouseReleased(x, y, button, istouch, presses)
end
function StateTester:mouseMoved(x, y, dx, dy, istouch)
self.mousePosition = { x = x, y = y }
self.spatialGrid.mousePosition = { x, y }
end
function StateTester:mouseWheelMoved(x, y)
if y > 0 then
self.spatialGrid.gridSize = self.spatialGrid.gridSize + 1
elseif y < 0 then
self.spatialGrid.gridSize = math.max(1, self.spatialGrid.gridSize - 1)
end
self.spatialGrid:reinitialize()
end
function StateTester:keyPressed(key)
if key == 'escape' then
love.event.quit()
elseif key == 'd' then
print(self.spatialGrid.particleCount)
self.spatialGrid:print()
elseif key == 'b' then
self.statusPlaceBlock = not self.statusPlaceBlock
elseif key == 'p' then
self.paused = not self.paused
end
end
function StateTester:update(dt)
-- always reinitialize the grid for now
if self.paused then return end
self.spatialGrid:reinitialize()
self.p1:update(dt)
self.p2:update(dt)
self.spatialGrid:addParticle(self.p1)
self.spatialGrid:addParticle(self.p2)
self.spatialGrid:checkCollisions()
end
function StateTester:draw()
self.spatialGrid:draw()
self.p1:draw()
self.p2:draw()
end