-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.lua
267 lines (260 loc) · 8.5 KB
/
input.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
input = {}
function interaction(name,object,actor)
function warp()
global.switchPlanet(global.currentPlanet,object.warpTo,actor)
end
local interactions = {warp=warp}
if interactions[name] then
interactions[name]()
end
end
function input:processInput(key)
local keys = global.keyBindings[global.gameScene]
local actor = global.multiverse[global.currentUniverse].bodies[global.currentPlanet].actors[global.currentActor]
-- controls for normal game
function GAMESCENE()
local modes = {
MOVE = 1,
INTERACT = 2,
BUILD = 3,
DESTROY = 4
}
inputCurrentMode = inputCurrentMode or modes.MOVE
inputDirection = inputDirection or vector(0,0,0)
function processInput()
function moveEntity()
actor:move(inputDirection)
end
function interactWithObject()
local planet = global.multiverse[global.currentUniverse].bodies[global.currentPlanet]
local placedObjectPos = actor.position+inputDirection
local listPosition = planet.collisionMap[placedObjectPos:__tostring()]
if listPosition ~= nil then
for i,v in pairs(listPosition) do
for flag,tu in pairs(v.flags) do
if interactionList[flag] then
interaction(flag,v,actor)
end
end
end
end
inputCurrentMode = modes.MOVE
end
function destroyEntity()
local planet = global.multiverse[global.currentUniverse].bodies[global.currentPlanet]
local placedObjectPos = actor.position+inputDirection
local listPosition = planet.collisionMap[placedObjectPos:__tostring()]
if listPosition ~= nil then
if listPosition[#listPosition].breaksInto then
print(listPosition[#listPosition].breaksInto)
local tile = classFactory.getObject(listPosition[#listPosition].breaksInto)
tile.position = placedObjectPos
tile.chunk = listPosition[#listPosition].chunk
table.insert(tile.chunk,tile)
-- ^ needed for chunk clearings
listPosition[#listPosition].removed = true
table.insert(planet.objects,tile)
tile.chunk.altered = true
end
end
inputCurrentMode = modes.MOVE
end
function placeEntity()
local planet = global.multiverse[global.currentUniverse].bodies[global.currentPlanet]
local placedObjectPos = actor.position+inputDirection
local objectName = classFactory.finishedObjectsIndexTable[(global.buildSlot%classFactory.databaseLength)+1]
placeObjectEntity(objectName,placedObjectPos,planet)
inputCurrentMode = modes.MOVE
end
local actions={[modes.MOVE]=moveEntity,[modes.INTERACT]=interactWithObject,[modes.BUILD]=placeEntity,[modes.DESTROY]=destroyEntity}
actions[inputCurrentMode]()
end
function moveleft()
inputDirection = vector(-1,0,0)
processInput()
end
function moveleftup()
inputDirection = vector(-1,-1,0)
processInput()
end
function moveleftdown()
inputDirection = vector(-1,1,0)
processInput()
end
function moveright()
inputDirection = vector(1,0,0)
processInput()
end
function moverightup()
inputDirection = vector(1,-1,0)
processInput()
end
function moverightdown()
inputDirection = vector(1,1,0)
processInput()
end
function moveup()
inputDirection = vector(0,-1,0)
processInput()
end
function movedown()
inputDirection = vector(0,1,0)
processInput()
end
function climbup()
inputDirection = vector(0,0,1)
processInput()
end
function climbdown()
inputDirection = vector(0,0,-1)
processInput()
end
function stepforward()
global.switchUniverse(global.currentUniverse,global.currentUniverse+1,global.multiverse[global.currentUniverse].bodies[global.currentPlanet].actors[global.currentActor])
end
function stepback()
global.switchUniverse(global.currentUniverse,global.currentUniverse-1,global.multiverse[global.currentUniverse].bodies[global.currentPlanet].actors[global.currentActor])
end
function placeObject()
inputCurrentMode = modes.BUILD
end
function destroyObject()
inputCurrentMode = modes.DESTROY
end
function interact()
inputCurrentMode = modes.INTERACT
end
function debug()
for i,v in pairs(global.multiverse[global.currentUniverse].bodies[global.currentPlanet].objects) do
print(i)
end
end
function buildSlotLeft()
global.buildSlot = global.buildSlot + 1
global.buildSlotName = classFactory.finishedObjectsIndexTable[(global.buildSlot%classFactory.databaseLength)+1]
end
function buildSlotRight()
global.buildSlot = global.buildSlot - 1
global.buildSlotName = classFactory.finishedObjectsIndexTable[(global.buildSlot%classFactory.databaseLength)+1]
end
function quit()
love.event.quit()
end
function openSpaceMenu()
global.gameScene = "SPACEMENU"
Scene.Load(global.scenes["SPACEMENU"])
end
function openWorldMenu()
global.gameScene = "WORLDMENU"
Scene.Load(global.scenes["WORLDMENU"])
end
local controls = {["moveleft"]=moveleft,["moveright"]=moveright,["moveup"]=moveup,["movedown"]=movedown,
["stepforward"]=stepforward,["stepback"]=stepback,climbup=climbup,climbdown=climbdown,debug=debug,
build=placeObject,moverightup=moverightup,moverightdown=moverightdown,moveleftup=moveleftup,moveleftdown=moveleftdown,buildSlotLeft=buildSlotLeft,buildSlotRight=buildSlotRight,destroy = destroyObject,
["escape"]=quit,interact=interact,
["spacemenu"]=openSpaceMenu,worldmenu=openWorldMenu}
if keys[key] ~= nil then
controls[keys[key]]()
end
end
function SPACEMENU()
function quitMenu()
global.gameScene = "GAMESCENE"
Scene.Load(global.scenes["GAMESCENE"])
end
function up()
space.offset = space.offset + vector(0,10)
--space.viewingPlanet = functions.clamp(1,space.viewingPlanet-1,global.planetAmount)
--updateSpaceMenu()
end
function down()
space.offset = space.offset + vector(0,-10)
--space.viewingPlanet = functions.clamp(1,space.viewingPlanet+1,global.planetAmount)
--updateSpaceMenu()
end
function left()
space.offset = space.offset + vector(10,0)
end
function right()
space.offset = space.offset + vector(-10,0)
end
function minus()
space.zoom = space.zoom - 0.1
end
function plus()
space.zoom = space.zoom + 0.1
end
function stepforward()
space.viewingUniverse = space.viewingUniverse + 1
space.bodies = functions.generatePlanets(space.viewingUniverse)
updateSpaceMenu()
end
function stepback()
space.viewingUniverse = space.viewingUniverse - 1
space.bodies = functions.generatePlanets(space.viewingUniverse)
updateSpaceMenu()
end
function timeforward()
space.viewingTime = space.viewingTime + 3600
updateSpaceMenu()
end
function timeback()
space.viewingTime = functions.clamp(0,space.viewingTime - 3600,math.huge)
updateSpaceMenu()
end
local controls = {exitmenu=quitMenu,left=left,right=right,up=up,down=down,minus=minus,plus=plus,stepforward=stepforward,stepback=stepback,
timeforward=timeforward,timeback=timeback}
if keys[key] ~= nil then
controls[keys[key]]()
end
end
function WORLDMENU()
function quitMenu()
global.gameScene = "GAMESCENE"
Scene.Load(global.scenes["GAMESCENE"])
end
function up()
end
function down()
end
function left()
end
function right()
end
function minus()
end
function plus()
end
function stepforward()
space.viewingUniverse = space.viewingUniverse + 1
space.bodies = functions.generatePlanets(space.viewingUniverse)
updateSpaceMenu()
end
function stepback()
space.viewingUniverse = space.viewingUniverse - 1
space.bodies = functions.generatePlanets(space.viewingUniverse)
updateSpaceMenu()
end
function timeforward()
space.viewingTime = space.viewingTime + 3600
updateSpaceMenu()
end
function timeback()
space.viewingTime = functions.clamp(0,space.viewingTime - 3600,math.huge)
updateSpaceMenu()
end
local controls = {exitmenu=quitMenu,left=left,right=right,up=up,down=down,minus=minus,plus=plus,stepforward=stepforward,stepback=stepback,
timeforward=timeforward,timeback=timeback}
if keys[key] ~= nil then
controls[keys[key]]()
end
end
local scenes = {
["GAMESCENE"] = GAMESCENE,
["SPACEMENU"] = SPACEMENU,
["WORLDMENU"] = WORLDMENU
}
if scenes[global.gameScene] ~= nil then
scenes[global.gameScene]()
end
end