-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameEndless.lua
196 lines (160 loc) · 6.48 KB
/
gameEndless.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
local composer = require("composer")
local scene = composer.newScene()
-- -----------------------------------------------------------------------------------
--
--Header
--
-- -----------------------------------------------------------------------------------
---- GAMEHEADER ----
--loading spritesheets
local sheetFile = require("sheet")
local gFunc = require("gameFunctions")
--Loading physics and setting the gravity to 0
local physics = require("physics")
physics.start()
physics.setGravity(0, 0)
--physics.setDrawMode( "hybrid" ) --Uncomment this line to show hitboxes
--hiding the status bar
display.setStatusBar(display.HiddenStatusBar)
--------------------
---- VARIABLES ----
gFunc.gameVarInit()
---------------------------
---- GAME FUNCTIONS ----
--gameloop function will only run after the animation
--will not run after player death
--todo, change checks from on colision to here
function gameLoop()
if(onAnim == false and dead == false) then
CreateArrows()
end
end
function endGame()
--setting the game over score and going to the highscores page
audio.stop(1)
backgroundMusic = audio.loadStream("Sounds/Death.ogg")
audio.play(backgroundMusic, {channel = 1, loops = -1})
timer.performWithDelay(1000, composer.setVariable("finalScore", score))
transition.to(playerObj, {time = 800, alpha = 0})
composer.gotoScene("highscores", {time = 800, effect = "crossFade"})
end
--------------------
-- -----------------------------------------------------------------------------------
--
-- Scene event functions
--
-- -----------------------------------------------------------------------------------
-- create()
function scene:create(event)
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
--pause physics for loading
physics.pause()
--setting groups
backGroup = display.newGroup()
sceneGroup:insert(backGroup)
itemGroup = display.newGroup()
sceneGroup:insert(itemGroup)
playerGroup = display.newGroup()
sceneGroup:insert(playerGroup)
abovePlayerGroup = display.newGroup()
sceneGroup:insert(abovePlayerGroup)
uiGroup = display.newGroup()
sceneGroup:insert(uiGroup)
--loading the background map and setting their layers
map = display.newImage(backGroup, "Sprites/mapInf.png", centerX, mapMarginY)
mapClosed = display.newImage(abovePlayerGroup, "Sprites/mapInfUp.png", centerX, mapMarginY)
mapOpened = display.newImage(abovePlayerGroup, "Sprites/mapInfUp.png", centerX, mapMarginY)
doors = display.newImage(backGroup, "Sprites/mapInfDoors.png", centerX, mapMarginY)
map.alpha = 1
mapClosed.alpha = 0
mapOpened.alpha = 1
doors.alpha = 1
----loading sheets
--player
local playerSheet = graphics.newImageSheet("Sprites/player sheet.png", optionsPlayer)
playerObj = display.newSprite(playerSheet, playerAnimation)
playerObj.x = display.contentCenterX
playerObj.y = playerMarginY
playerObj.alpha = 0
physics.addBody(playerObj, {isSensor = true, shape = playerHitbox})
playerObj.myName = "player"
playerGroup:insert(playerObj)
--shield
local sheetShield = graphics.newImageSheet("Sprites/shield.png", optionsShield)
shieldMMarginY = playerObj.y - playerObj.contentHeight / 2
--creating shield on the right place
shieldM = display.newImage(itemGroup, sheetShield, 1, centerX, shieldMMarginY)
shieldL = display.newImage(itemGroup, sheetShield, 2, centerX - 22, playerObj.y)
shieldR = display.newImage(itemGroup, sheetShield, 2, centerX + 25, playerObj.y)
--adding their bodies
physics.addBody(shieldM, {isSensor = true, shape = shieldMHitbox})
physics.addBody(shieldL, {isSensor = true, shape = shieldLHitbox})
physics.addBody(shieldR, {isSensor = true, shape = shieldRHitbox})
--setting colision names
shieldM.myName = "shield"
shieldL.myName = "shield"
shieldR.myName = "shield"
--making everything disappear to be loaded in the animation
shieldM.alpha = 0
shieldL.alpha = 0
shieldR.alpha = 0
--music set
currentMusic = "Sounds/City.ogg"
createUI()
end
-- show()
function scene:show(event)
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif (phase == "did") then
--starting the physics again
physics.start()
--starting the collisions
Runtime:addEventListener("collision", gFunc.onCollision)
--starting the animation
gFunc.InitialAnimation()
end
end
-- hide()
function scene:hide(event)
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
-- Code here runs when the scene is on screen (but is about to go off screen)
if(gameLoopTimer ~= nil) then
timer.cancel(gameLoopTimer)
end
elseif (phase == "did") then
-- Code here runs immediately after the scene goes entirely off screen
--removing the listeners
Runtime:removeEventListener("collision", gFunc.onCollision)
Runtime:removeEventListener("touch", gFunc.swipeListener)
rRect:removeEventListener("tap", gFunc.tapListener)
lRect:removeEventListener("tap", gFunc.tapListener)
mRect:removeEventListener("tap", gFunc.tapListener)
--pausing the physics and the music
physics.pause()
--todo, probably need to dispose of player
--removing the scene
composer.removeScene("gameEndless")
audio.dispose( shieldClang )
audio.dispose( deathSound )
end
end
-- destroy()
function scene:destroy(event)
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener("create", scene)
scene:addEventListener("show", scene)
scene:addEventListener("hide", scene)
scene:addEventListener("destroy", scene)
-- -----------------------------------------------------------------------------------
return scene