-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.lua
184 lines (130 loc) · 5.22 KB
/
menu.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
local composer = require("composer")
local scene = composer.newScene()
local widget = require("widget")
local physics = require("physics")
physics.start()
physics.setGravity( 0, 0 )
display.setStatusBar( display.HiddenStatusBar )
W = display.contentWidth -- Largura da tela
H = display.contentHeight -- Altura da tela
local backGroup = display.newGroup()
local mainGroup = display.newGroup()
local uiGroup = display.newGroup()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
local bolhasTable = {}
local backgroundmusic = audio.loadSound('audio/Winds Of Stories.mp3')
audio.play(backgroundmusic, { loops=1 })
local background = display.newImageRect( backGroup, 'img/background/back.png', 1250, 700)
background.x = display.contentCenterX
background.y = display.contentCenterY
local background2 = display.newImageRect( backGroup, 'img/background/back2.png', 1000, 250)
background2.x = display.contentCenterX
background2.y = display.contentCenterY + 100
local agua_viva = display.newImageRect( backGroup, 'img/background/agua-viva.png', 50, 50)
agua_viva.x = display.contentCenterX - 190
agua_viva.y = display.contentCenterY + 80
local function moveBackground2()
local limiteBackX = math.random(background2.x - 3, background2.x + 3)
local limiteBackY = math.random(background2.y - 1, background2.y + 1)
transition.moveTo(background2, { x=limiteBackX, y=limiteBackY, time=200 } )
end
local moveBack2Timer = timer.performWithDelay(500, moveBackground2, 2000)
local function moveAguaViva()
local limiteAguaViva = math.random(agua_viva.y - 5, agua_viva.y + 5)
if(limiteAguaViva > H) then
limiteAguaViva = H - 5
elseif(limiteAguaViva < 0) then
limiteAguaViva = 5
end
transition.moveTo( agua_viva, { x=agua_viva.x, y=limiteAguaViva, time=300 } )
end
local moveAguaVivaTimer = timer.performWithDelay(500, moveAguaViva, 2000)
local function createBolha()
tamanhoBolha = math.random(10, 51)
local newBolha = display.newImageRect( mainGroup, 'img/background/bolha.png', tamanhoBolha, tamanhoBolha, 85 )
table.insert( bolhasTable, newBolha )
physics.addBody( newBolha, "dynamic", { radius=40, bounce=0.8 } )
newBolha.myName = "bolha"
local whereFrom = 2
if ( whereFrom == 2 ) then
newBolha.x = math.random( display.contentWidth )
newBolha.y = H + 5
newBolha:setLinearVelocity( math.random( -40,40 ), math.random( 40,40 ) )
end
transition.moveTo( newBolha, { x=newBolha.x, y=-100, time=1500 } )
end
local function gameLoop()
createBolha()
-- Remove bubbles which have drifted off screen
for i = #bolhasTable, 1, -1 do
local thisBolha = bolhasTable[i]
if ( thisBolha.x < -10 or
thisBolha.x > display.contentWidth + 10 or
thisBolha.y < -50 or
thisBolha.y > display.contentHeight + 10 )
then
display.remove( thisBolha )
table.remove( bolhasTable, i )
end
end
end
gameLoopTimer = timer.performWithDelay( 500, gameLoop, 0 )
local function gotoPhaseOne()
audio.pause(backgroundmusic)
composer.gotoScene( "scene1", { time=800, effect="crossFade" } )
end
local logo = display.newImageRect( mainGroup, 'img/logo.png', 200, 200)
logo.x = display.contentCenterX
logo.y = display.contentCenterY - 60
local function onPress( event )
print("B5 pressed")
timer.performWithDelay(3000, function() event.target:removeSelf(); end)
end
local button_play = widget.newButton
{
left = 139,
top = 180,
width = 200,
height = 60,
defaultFile = 'img/botoes/play.png',
overFile = 'img/botoes/play.png',
onPress = onPress
}
button_play:addEventListener( "tap", gotoPhaseOne )
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
-- Code here runs when the scene is entirely on screen
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)
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
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