-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.lua
86 lines (75 loc) · 1.64 KB
/
game.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
local game = {}
local HC = require "hardoncollider"
function collide(dt, shape_one, shape_two, dx, dy)
shape_one:move(dx/2, dy/2)
shape_two:move(-dx/2, -dy/2)
end
function game:addBtRetry()
if env.game.start == 1 then
return
end
env.menu.buttons = env.butt.new(
env.menu.buttons,
{
txt = "Retry",
aligne = "center",
y = 400,
paddingLeft = 40,
callback = function()
env.page = 1
love.audio.stop(env.sounds.sound1)
env.game = dofile("game.lua"):new()
end
}
)
end
function game:new()
game:addBtRetry()
self.start = 1
env.collider = HC.new(150)
env.map = env.collider:addRectangle(0,0, love.window.getHeight(),love.window.getWidth())
env.collision = dofile("collision.lua")
env.portals = dofile('portal.lua'):load()
env.balls = dofile('ball.lua'):load()
env.bricks = dofile('brick.lua'):load()
game:loadMap("maps/map1.lua")
return self
end
function game:loadMap(map)
local tiles = dofile(map)
for index, tile in pairs(tiles) do
env.bricks:new(tile)
end
end
function game:update(dt)
env.collider:update(dt)
env.collision:update(dt)
env.portals:update(dt)
env.balls:update(dt)
env.bricks:update(dt)
if env.sound == 1 then
love.audio.play(env.sounds.sound2)
end
end
function game:keyreleased(button)
end
function game:keypressed(button)
if button == 'escape' then
if env.sound == 1 then
love.audio.stop(env.sounds.sound2)
end
env.page = 0
return
end
env.portals:keypressed(button)
end
function game:mousepressed(x, y, button)
env.portals:mousepressed(x, y, button)
end
function game:draw()
env.collision:draw()
env.portals:draw()
env.balls:draw()
env.bricks:draw()
end
return game