-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
215 lines (173 loc) · 5.29 KB
/
main.lua
File metadata and controls
215 lines (173 loc) · 5.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
game = {}
require("game.map")
require("game.creatures")
require("game.towerPlacement")
require("game.tMenu")
require("game.manager")
require("game.enemyAi")
require("game.tutorial")
game.powerUps = require("game.powerUps")
local mainMenu = require("game.mainMenu")
local gameOverScreen = require("game.gameOverScreen")
local currentState = "menu"
local tutorialDirty = false
function switchToGame()
if not tutorialDirty then
currentState = "tutorial"
tutorialDirty = true
else
currentState = "game"
end
music1:stop()
music2:play()
end
function switchToPause()
currentState = "pause"
end
function switchToTutorial()
currentState = "tutorial"
end
function endGame()
currentState = "gameover"
end
function switchToMainMenu()
mainMenu.currentMenu = "main"
end
screenWidth = 1080
screenHeight = 720
music1 = love.audio.newSource("game/SFX/Audio/Music/LOOP_1_LD56.mp3", "stream")
music2 = love.audio.newSource("game/SFX/Audio/Music/LOOP_2_LD56.mp3", "stream")
function love.load()
print("running on " .. love.system.getOS())
--check if resolution could be set to 1920x1080
local width, height = love.window.getDesktopDimensions( 1 )
if width >= 1920 and height >= 1080 then
screenWidth = 1920
screenHeight = 1080
mapsize = 2
end
love.window.setMode(screenWidth, screenHeight)
game.manager.load()
game.map.load()
game.towerPlacement.load()
game.creatures.load()
game.gameOverScreen.load()
mainMenu.load(switchToGame)
game.enemyAi.load()
game.tMenu.load()
game.powerUps.load()
music1:setLooping(true)
music2:setLooping(true)
music1:setVolume(0.4)
music2:setVolume(0.4)
music1:play()
end
function love.update(dt)
if currentState == "menu" then
mainMenu.update(dt)
elseif currentState =="pause" then
mainMenu.update(dt)
elseif currentState == "gameover" then
game.gameOverScreen.update(dt)
elseif currentState == "tutorial" then
game.tutorial.update(dt)
if not game.tutorial.updatePause then
game.map.update(dt)
game.manager.update(dt)
game.towerPlacement.update(dt)
game.creatures.update(dt)
game.tMenu.update(dt)
game.enemyAi.update(dt)
end
game.powerUps.update(dt)
elseif currentState == "game" then
game.map.update(dt)
game.manager.update(dt)
game.towerPlacement.update(dt)
game.creatures.update(dt)
game.tMenu.update(dt)
game.enemyAi.update(dt)
game.powerUps.update(dt)
end
end
function love.draw()
--love.graphics.scale(love.graphics.getWidth()/screenWidth + 0.2, love.graphics.getHeight()/screenHeight + 0.2)
--love.graphics.scale(screenWidth/love.graphics.getWidth(), screenHeight/love.graphics.getHeight())
love.graphics.setDefaultFilter("nearest", "nearest")
if currentState == "menu" then
mainMenu.draw()
elseif currentState == "pause" then
mainMenu.changePlayButtonText("Resume Game")
mainMenu.draw()
elseif currentState == "gameover" then
game.gameOverScreen.draw()
mainMenu.changePlayButtonText("Start new Game")
elseif currentState == "tutorial" then
game.map.draw()
game.towerPlacement.draw()
game.creatures.draw()
game.tutorial.draw()
game.tMenu.draw()
game.enemyAi.draw()
game.powerUps.draw()
game.manager.draw()
elseif currentState == "game" then
font = love.graphics.newFont(12)
love.graphics.setFont(font)
game.map.draw()
game.towerPlacement.draw()
game.creatures.draw()
game.tMenu.draw()
game.enemyAi.draw()
game.powerUps.draw()
game.manager.draw()
end
end
function love.mousepressed(x, y, button, istouch, presses)
if currentState == "menu" then
mainMenu.mousepressed(x, y, button)
elseif currentState == "pause" then
mainMenu.mousepressed(x, y, button, presses)
elseif currentState == "tutorial" then
game.tutorial.mousepressed(x, y, button)
--game.map.mousepressed(x, y, button)
game.powerUps.mousepressed(x, y, button)
game.tMenu.mousepressed(x, y, button, istouch, presses)
elseif currentState == "game" then
if game.map.editorMode then
game.map.mousepressed(x, y, button)
else
game.tMenu.mousepressed(x, y, button, istouch, presses)
end
game.powerUps.mousepressed(x, y, button)
end
end
function love.keypressed(key)
game.tutorial.keypressed(key)
game.tMenu.keypressed(key)
if currentState =="gameover" then
currentState= "menu"
resetGame()
elseif key == "escape" then
currentState = "pause"
end
if key == "c" then
game.map.editorMode = not game.map.editorMode
end
end
function resetGame()
print("reset game")
local font
font = love.graphics.newFont(12)
love.graphics.setFont(font)
game.towerPlacement.towers = {}
game.creatures.resetCreatureStore()
game.map.load()
game.towerPlacement.load()
game.creatures.load()
game.manager.load()
game.gameOverScreen.load()
game.enemyAi.load()
game.powerUps.load()
love.update(dt)
end