-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
69 lines (54 loc) · 1.43 KB
/
main.lua
File metadata and controls
69 lines (54 loc) · 1.43 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
60
61
62
63
64
65
66
67
68
69
Gamestate = require("lib.hump.gamestate")
require("lib.starfield")
-- one gamestate for each type of starfield
local cartesian = {}
local polar = {}
function cartesian:init()
self.stars = Starfield()
self.move_x = 0
self.move_y = 1
end
function cartesian:mousepressed(x, y, button)
Gamestate.switch(polar)
end
function cartesian:draw()
self.stars:draw()
love.graphics.print("Cartesian Starfield", 10, love.graphics.getHeight() - 17)
end
function cartesian:update(dt)
cx = love.graphics.getWidth() / 2
cy = love.graphics.getHeight() / 2
mx = love.mouse.getX()
my = love.mouse.getY()
if mx < cx - 10 or mx > cx + 10 then
self.move_x = math.ceil((mx - cx) / 100)
else
self.move_x = 0
end
if my < cy - 10 or my > cy + 10 then
self.move_y = math.ceil((my - cy) / 100)
else
self.move_y = 0
end
self.stars:updateCartesian(dt, self.move_x, self.move_y)
end
function polar:init()
self.stars = Starfield(200, 0.02)
end
function polar:mousepressed(x, y, button)
Gamestate.switch(cartesian)
end
function polar:draw()
self.stars:draw()
love.graphics.print("Polar Starfield", 10, love.graphics.getHeight() - 17)
end
function polar:update(dt)
mx = love.mouse.getX()
my = love.mouse.getY()
self.stars:updateCenter(mx, my)
self.stars:updatePolar(dt)
end
function love.load()
Gamestate.registerEvents()
Gamestate.switch(cartesian)
end