-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
274 lines (234 loc) · 6.55 KB
/
main.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
require 'screens.screensManager'
require 'lib.functions'
function love.load()
width = 1080
height = 720
amountPlayers = 4
names = {
'Rick',
'Damien',
'Bob',
'Stefan'
}
types = {
'ijs',
'moeras',
'woestijn',
'bos'
}
-- generate player
-- playerList = player:generate(names, types, {}, 0)
love.window.setMode(width, height)
love.window.setFullscreen(settings:getConfigByKey("fullscreen"), "desktop")
love.graphics.setBackgroundColor(45, 127, 180)
screens.load()
end
function love:keypressed(key)
if (screens:on("game")) then
game:keypressed(key, screens)
elseif (screens:on("help")) then
help:keypressed(key, screens)
elseif (screens:on("credits")) then
credits:keypressed(key, screens)
elseif (screens:on("selection")) then
selection:keypressed(key, screens)
elseif (screens:on("settings")) then
settingsScreen:keypressed(key, screens)
end
-- exit game
-- if key == 'escape' then
-- love.event.quit()
-- end
end
function love.mousereleased(x, y, button)
if (screens:on("game")) then
for i,object in pairs(objects.items) do
if object.dragging.active then
object.dragging.active = false
if not objects.collision(object.x + object.size/2, object.y + object.size/2, i) then
object.x = object.prefx
object.y = object.prefy
end
end
end
end
end
function love.mousepressed(x, y, button)
if (screens:on("game")) then
if x > board.endTurn.x
and x < board.endTurn.x + board.endTurn.width
and y > board.endTurn.y
and y < board.endTurn.y + board.endTurn.height then
players:update(players:getActivePlayer())
for _,tiles in pairs(board.tiles) do
board.reset(tiles)
unitspawn.disable()
if tiles.unit then
tiles.unit.attacked = false
end
end
if players:getActivePlayerId() == 2 then
_base = board.getBaseById(currentPlayer.id)
-- ai(players:getActivePlayer(), _base)
end
return
end
for _,t in pairs(board.tiles) do
if t.unloadboatspawning then
for i,unit in pairs(t.unit.passengers) do
if x > t.x + (80 * (i-1))
and x < t.x + (80 * (i-1)) + 80
and y > t.y + tile.size
and y < t.y + tile.size + 80 then
board.spawn(t, unit, i, t.owner)
currentPlayer.currentEnergy = currentPlayer.currentEnergy - 1
-- return
end
end
end
-- select tile
if x > t.x
and x < t.x + t.size
and y > t.y
and y < t.y + t.size then
if t.unit.type == 'boot'
and #t.unit.passengers ~= 0 then
end
-- check if tile is occupied
-- check if owner of tile is active player
if t.occupied
and t.owner == players:getActivePlayerId()
and players:getActivePlayerEnergy() ~= 0 then
board.attackToggle(x, y, t)
end
-- check if tile is occupied
-- check if owner of tile is active player
if t.occupied
and t.unit.type == 'worker'
and t.owner == players:getActivePlayerId()
and players:getActivePlayerEnergy() ~= 0 then
board.buildToggle(x, y, t)
end
-- check if tile is occupied
-- check if owner of tile is active player
if t.buildable
and not t.harbor
and players:getActivePlayerEnergy() > 1
and currentPlayer.freq >= prices['bos']['harbor'] then
board.build(x, y, t)
return
end
-- check if tile is attackable
if t.attackable and players:attack() then
board.attack(x, y, t)
end
-- check if tile is unloadable
if t.unloadable then
board.unloadBoatSpawn(t)
end
-- check if tile is occupied
-- check if owner of tile is active player
if t.occupied
and t.owner == players:getActivePlayerId()
and players:getActivePlayerEnergy() ~= 0 then
board.walkToggle(x, y, t)
end
-- check if tile is occupied
-- check if owner of tile is active player
if t.occupied
and t.owner == players:getActivePlayerId()
and players:getActivePlayerEnergy() ~= 0
and t.unit.type == 'boot'
and not t.base
and #t.unit.passengers ~= 0 then
board.unloadToggle(x, y, t)
end
-- check if tile is walkable
-- check if tile contains boat
-- check if boat is not full
-- check if boat is urs
if t.loadable
and t.owner == players:getActivePlayerId()
and t.unit.type == 'boot'
and not t.base
and #t.unit.passengers < 3 then
board.loadBoat(x, y, t)
end
-- check if tile is walkable
-- check if tile is not occupied
-- check if its no base tile
if t.walkable
and not t.occupied
and not t.base
and not t.harbor
and players:walk() then
-- walk function
board.walk(x, y, t, lastTile, players:getActivePlayerId())
end
-- check click on base or harbor
-- check if no units on tile
-- check if owner of tile is active player
-- check if owner has energy
if (t.base or t.harbor)
and not t.occupied
and t.owner == players:getActivePlayerId()
and players:getActivePlayerEnergy() ~= 0 then
unitspawn.show(t)
end
end
end
for i,unit in pairs(units) do
if unitspawn.active then
if x > unit.x
and x < unit.x + unit.width
and y > unit.y
and y < unit.y + unit.height then
for _,t in pairs(board.tiles) do
-- check if tile is spawning
-- check if tile is not occupied
-- check if enough money and buy's item
if t.type == 0 then
tiletype = 'moeras'
elseif t.type == 1 then
tiletype = 'bos'
elseif t.type == 2 then
tiletype = 'goldmine'
elseif t.type == 3 then
tiletype = 'ijs'
elseif t.type == 4 then
tiletype = 'water'
else
tiletype = 'woestijn'
end
if t.spawning == true
and not t.occupied
and players:buyItem(prices[tiletype][unit.name]) then
-- spawn unit on tile
unitspawn.spawn(t, objects.items[unit.n + 1])
-- toggle all walkables on board
board.walkFromBaseToggle(t, unit)
-- set basewalk
-- board.baseWalk(t, unit)
unitspawn.active = false
else
unitspawn.active = false
end
end
end
end
end
-- Moving objects (soldiers)
for _,object in pairs(objects.items) do
objects.move(x, y, object)
end
end
end
function love:update(dt)
dt = math.min(1/60, love.timer.getDelta())
--print(love.timer.getDelta())
--screens:update(dt)
UPDATE_SCREENS(dt)
end
function love.draw()
DRAW_SCREENS()
end