-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.lua
executable file
·141 lines (100 loc) · 2.65 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
require 'level.lua'
require 'player.lua'
require 'vector.lua'
require 'eraser.lua'
require 'camera.lua'
require 'background.lua'
require 'assets.lua'
require 'block.lua'
local g = love.graphics
local k = love.keyboard
local m = love.mouse
local f = love.filesystem
Game = GameState:addState('Game')
levelNumber = 1
function Game:enterState()
cursor = Assets.LoadImage('cursor.png')
if world then
world:setCallbacks(nil, nil, nil, nil)
end
self.background = Background:new(1600)
self.level = Level:new()
f.load('level' .. levelNumber .. '.lua')()
LoadLevel(self.level)
player = Player:new(self.level.player)
self.eraser = Eraser:new(Vector:new(200,200), Vector:new(40,40))
self.camera = Camera:new(0, 0, self.level.w, self.level.h)
m.setVisible(false)
mouseX, mouseY = m.getPosition()
self.eraser:setPosition(Vector:new(mouseX-self.camera:getTranslation().x, mouseY))
self.intro = self.level.postit ~= nil
end
function Game:exitState()
if music then
music:stop()
end
end
function Game:keypressed(key)
if key == 'escape' then
gameState:gotoState('Menu')
end
end
function Game:keyreleased(key)
end
function Game:update(dt)
if self.intro then
mouseX, mouseY = m.getPosition()
local mDown = m.isDown('l') or m.isDown('r')
if mDown and self.level:postitClose(Vector:new(mouseX, mouseY)) then
self.intro = false
return
end
end
if self.intro then return end
mouseX, mouseY = m.getPosition()
self.eraser:setPosition(Vector:new(mouseX-self.camera:getTranslation().x, mouseY))
self.eraser:update(dt)
if self.eraser:hasCutLine() then
local cutLine = self.eraser:getAndClearCutLine()
self.level:erase(cutLine, 80)
end
self.level:update(dt)
player:update(dt)
if player.dead then
self:enterState()
return
end
if self.level:atExit(player:getPosition()) then
levelNumber = levelNumber + 1
if levelNumber == 6 then
gameState:gotoState('EndScreen')
else
self:enterState()
end
return
end
local mDown = m.isDown('l') or m.isDown('r')
if self.level:retryTest(Vector:new(mouseX-self.camera:getTranslation().x, mouseY), -self.camera:getTranslation().x) and mDown then
self:enterState()
return
end
end
function Game:draw()
g.setBackgroundColor(255,255,255,255)
self.camera:set(player:getPosition())
self.background:draw()
self.level:draw()
player:draw()
if not self.intro then
self.level:drawRetry(-self.camera:getTranslation().x)
self.eraser:draw()
end
self.camera:clear()
if self.intro then
g.setColor(0,0,0, 200)
g.rectangle("fill", 0, 0, g.getWidth(), g.getHeight())
g.setColor(255,255,255,255)
self.level:drawPostit()
g.draw(cursor, mouseX, mouseY)
end
end