-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.lua
More file actions
221 lines (124 loc) · 3.67 KB
/
game.lua
File metadata and controls
221 lines (124 loc) · 3.67 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
216
217
218
219
220
221
require("key_handle")
require("renderer.renderer")
require("states.game_states")
sample_state=require("states.state_sample")
g = require("globals")
local game ={}
---------------------------
--preinit functions?
---------------------------
local base={}
------------------------------------------------------------
--Base data fields
------------------------------------------------------------
constants = nil
------------------------
-- dynamic data
--game state
game_state = GameStates.MAIN_MENUE
previous_game_state = game_state
--others
key_timer = 0--timer between movement
mouse_coords={0,0}
exit_timer =0
selector_timer = 0
target_timer = 0
show_main_menue =true
main_menue_item = 1
selected_state_idx = 1
-----------------------------------------------------------
-- special data fields for debugging / testing only
-----------------------------------------------------------
function update_menue()
for key,v in pairs(key_list) do
print("Key pressed",key)
local action=handle_main_menue(key)--get key callbacks
if action["menue_idx_change"] ~= nil then
if key_timer+0.2 < love.timer.getTime() then
main_menue_item = main_menue_item+ action["menue_idx_change"][2]
if main_menue_item <1 then main_menue_item = 1 end
if main_menue_item>4 then main_menue_item = 4 end
print(main_menue_item)
key_timer = love.timer.getTime()
end
end
-- main menu action handling
if action["selected_item"]~= nil then
show_main_menue = false
--menue item switcher
if main_menue_item == 1 then--new game
game_state=GameStates.PLAYING
game.new()
elseif main_menue_item == 2 then--load game
elseif main_menue_item == 3 then
else
love.event.quit()
end
end
if action["exit"]~= nil then
love.event.quit()
end
end
end
--loading a game
function game.load()
end
--new game
function game.new()
sample_state:startup()
end
function game.play(dt)
for key,v in pairs(key_list)do
attack = false
movement = {x=0,y=0}
--print("got some id",plid)
--print(key,v)
local action=handle_keys(key)--get key callbacks
if action["move"] and game_state==GameStates.PLAYING then
movement.x=movement.x+action["move"][1]
movement.y=movement.y+action["move"][2]
end
if action["exit"] then
if exit_timer +0.3 < love.timer.getTime() then
love.event.quit()
end
end
if action["attack"] then
attack = true
end
end
sample_state:update()
-- Enemy behaviour basic / Enemy turn
end
--main loop
function game.update(dt)
--handle game stuff
if show_main_menue == false then
game.play(dt)
return
end
--handle menue
update_menue()
end
function game.draw()
if show_main_menue ==true then
render_menue()
return
end
sample_state:draw()
end
--default key list to check
function game.keyHandle(key,s,r,pressed_)
if pressed_ == true then
key_list[key] = true
last_key=key
else
key_list[key] = nil
end
end
function game.MouseHandle(x,y,btn)
end
function game.MouseMoved(mx,my)
mouse_coords={mx,my}
end
return game