-
Notifications
You must be signed in to change notification settings - Fork 0
/
turn.lua
234 lines (208 loc) · 6.04 KB
/
turn.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
local char = require "char"
local football = require "football"
local rules = require "rules"
local results = require "results"
local window = require "window"
local turn = {}
local replay_active = false
local replay_info = {}
local turn_time = 0
local step_time = .4
local timer = turn_time
local resolve = false
local step = 0
local max_step = 0
local down_delay = false
local max_turns = 0
local turns_left = 0
local hud_canvas = love.graphics.newCanvas(318, 51)
turn.load = function(settings, game_replay_active, game_replay_info)
if network_state == "client" then
network.client_callback("load_or_save", function()
turn.load_or_save()
end)
network.client_callback("resolve", function(data)
turn.resolve(data)
end)
network.client_callback("new_step", function(data)
turn.new_step(data)
end)
network.client_callback("complete", function(data)
turn.complete(data)
end)
network.client_callback("results", function()
turn.start_results()
end)
network.client_callback('timer', function(data)
timer = data
end)
end
turn_time = settings.turn_time
max_turns = settings.max_turns
replay_info = game_replay_info
if game_replay_active then
replay_active = true
turn_time = 0
else
replay_active = false
end
step = 0
max_step = 0
down_delay = false
timer = turn_time
resolve = false
turns_left = max_turns
end
turn.update = function(dt)
timer = timer - dt
if timer < 0 then
if network_state == "server" then
if resolve then
if step >= max_step then
turn.complete(max_step)
network.server_send("complete", max_step)
else
local new_step = step+1
turn.new_step(new_step)
network.server_send("new_step", new_step)
end
else
turn.load_or_save()
network.server_send("load_or_save")
local step_num = math.max(char.step_num(), football.step_num())
turn.resolve(step_num)
network.server_send("resolve", step_num)
end
else
timer = 0
end
end
end
turn.new_step = function(new_step)
step = new_step
timer = step_time
if step > 1 then
turn.finish(step-1)
end
if not down_delay then
if turn.prepare(step) then -- returns true if collision has occured, which may alter the amount of steps needed
max_step = math.max(char.step_num(), football.step_num())
end
end
end
turn.prepare = function(step)
football.prepare(step, step_time)
return char.prepare(step, step_time, max_step)
end
turn.finish = function(step)
football.finish(step)
if not down_delay and char.finish(step, step_time, max_step) then
turn.delay_down()
network.server_send("timer", timer)
end
end
turn.complete = function(step)
football.finish(step)
if not down_delay and char.finish(step, step_time, max_step) then
turn.delay_down()
network.server_send("timer", timer)
else
down_delay = false
resolve = false
timer = turn_time
if char.end_resolve(step, step_time) and replay_active then
timer = step_time/2
end
football.end_resolve()
turn.increment()
end
end
turn.increment = function()
if turns_left > 0 then
turns_left = turns_left - 1
end
end
turn.check_end = function()
if turns_left <= 0 then
turn.start_results()
end
end
turn.start_results = function()
state = "results"
if server then
network.server_send("results")
server:update()
end
results.load(char.get_players(), rules.get_info(), replay_active, replay_info)
end
turn.delay_down = function()
down_delay = true
timer = step_time * 3
turn.check_end()
end
turn.load_or_save = function()
local current = max_turns-turns_left+1
if replay_active then
if replay_info.turns[current] then
char.load_turn(replay_info.turns[current])
else
turn.start_results()
end
else
replay_info.turns[current] = char.save_turn()
end
end
turn.resolve = function(step_num)
max_step = step_num
resolve = true
turn.start_resolve()
if max_step > 0 then -- if something is moving
turn.new_step(1)
else -- if nothing is moving, go right back to input phase
turn.complete(0)
end
end
turn.start_resolve = function()
football.start_resolve()
char.start_resolve(step_time)
end
turn.draw_hud = function(x, y)
love.graphics.setCanvas(hud_canvas)
love.graphics.clear()
love.graphics.draw(art.img.scoreboard)
love.graphics.draw(art.img.possession, art.quad.possession[rules.get_offense()], 92, 27)
art.set_effects(1, 1, 1, "scoreboard_overlay", "color", palette[rules.get_color(1)])
love.graphics.draw(art.img.scoreboard_overlay, art.quad.scoreboard_overlay[1])
art.set_effects(1, 1, 1, "scoreboard_overlay", "color", palette[rules.get_color(2)])
love.graphics.draw(art.img.scoreboard_overlay, art.quad.scoreboard_overlay[2], 159, 0)
art.set_effects(1, 1, 1, "possession_overlay", "color", palette[rules.get_color(rules.get_offense())])
love.graphics.draw(art.img.possession_overlay, art.quad.possession[rules.get_offense()], 92, 27)
art.clear_effects()
love.graphics.setColor(colors.white)
love.graphics.printf(rules.get_score(1), 5, 6, 18, "left")
love.graphics.printf(rules.get_name(1), 24, 6, 96, "right")
love.graphics.printf(rules.get_score(2), 295, 6, 18, "right")
love.graphics.printf(rules.get_name(2), 199, 6, 96, "left")
if turns_left > 0 then
love.graphics.printf(turns_left, 132, 6, 34, "left")
else
love.graphics.printf("O.T.", 132, 6, 34, "left")
end
if not replay_active then
if resolve then
love.graphics.printf("0", 168, 6, 18, "right")
else
love.graphics.printf(math.floor(timer)+1, 168, 6, 18, "right")
end
end
love.graphics.printf(rules.get_play_string(), 102, 33, 118, "center")
love.graphics.setColor(1, 1, 1)
love.graphics.setCanvas(window.canvas)
local w, h = window.get_dimensions()
love.graphics.draw(hud_canvas, math.floor(w/2-art.img.scoreboard:getWidth()/2), 8)
end
turn.get_resolve_time = function()
local move_dist = char.get_move_dist()
return step_time*(move_dist.qb+move_dist.offense)/2
end
return turn