-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview09Lemon.lua
More file actions
226 lines (183 loc) ยท 6.71 KB
/
Copy pathview09Lemon.lua
File metadata and controls
226 lines (183 loc) ยท 6.71 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
222
223
224
225
226
-----------------------------------------------------------------------------------------
--
-- view09Lemon.lua
--
-----------------------------------------------------------------------------------------
local composer = require( "composer" )
local scene = composer.newScene()
function scene:create( event )
local sceneGroup = self.view
-- ๋ฐฐ๊ฒฝ ๊ฐ์ฒด
local background = display.newImageRect("์ด๋ฏธ์ง/๋ฏธ๋๊ฒ์/๋ฏธ๋๊ฒ์_๋
ธ๋๋ง์/๋ฏธ๋๊ฒ์_๋ ๋ชฌ๊ฒ์ ๋ฐฐ๊ฒฝ(๋
ธ๋๋ง์).png",display.contentWidth, display.contentHeight)
background.x,background.y = display.contentWidth/2,display.contentHeight/2
sceneGroup:insert(background)
-- physics ์์ฑ ์์
local phyics = require "physics"
phyics.start()
-- ์๊ฐ, ์ ์ ๊ฐ์ฒด
local time = display.newImageRect("์ด๋ฏธ์ง/๋ฏธ๋๊ฒ์/๋ฏธ๋๊ฒ์_์๊ฐํ์ด๋จธ.png", display.contentWidth/7.91, display.contentHeight/3.78)
time.anchorX, time.anchorY =0,0
time.x,time.y = display.contentWidth/1.180, display.contentHeight/21.53
sceneGroup:insert(time)
local score = display.newImageRect("์ด๋ฏธ์ง/๋ฏธ๋๊ฒ์/๋ฏธ๋๊ฒ์_์ฝ์ธ์ฐฝ.png", display.contentWidth/9.3, display.contentHeight/4.26)
score.anchorX, score.anchorY =0,0
score.x,score.y = display.contentWidth/33.166, display.contentHeight/13.2482826
sceneGroup:insert(score)
local score_num = 0
local score1 = 15
local score_num = 15
local showScore = display.newText(score1,display.contentWidth/12,display.contentHeight/5.555,"font/์ํ๋ฆฌ๋์ค๋ Medium.ttf")
showScore:setFillColor(1,0,0)
showScore.size = 73
sceneGroup:insert(showScore)
local limit = 20
local showLimit = display.newText(limit,display.contentWidth/1.1,display.contentHeight/5.555,"font/์ํ๋ฆฌ๋์ค๋ Medium.ttf")
showLimit:setFillColor(1,0,0)
showLimit.size =80
sceneGroup:insert(showLimit)
-- ๋ฐ๋ฅ ๊ฐ์ฒด, phyics body ์ถ๊ฐ
local floor = display.newImage("์ด๋ฏธ์ง/๋ฏธ๋๊ฒ์/๋ฏธ๋๊ฒ์_๋
ธ๋๋ง์/๋ฏธ๋๊ฒ์_๋ ๋ชฌ๊ฒ์ ๋ฐ๋ฅ(๋
ธ๋๋ง์).png")
floor.name = "floor"
floor.x=display.contentWidth/2
floor.y=display.contentHeight/1.105
phyics.addBody(floor,"static")
sceneGroup:insert(floor)
local lemon = {}
local lemons = display.newGroup()
local n
local m = 0
local k
local s
-- ๋๋ค lemon ์์ฑ
local function newlemon()
m = m+1
n = math.random(display.contentWidth*0.1,display.contentWidth*0.9)
k = math.random(1,5)
s = math.random(1,2)
-- ๋ ๋ชฌ๊ณผ ๋ฒ๋ ๋ ๋ค์ผ๋ก ํ๋ ๋ด๋ ค์ด
if s ==1 then
lemon[1] = display.newImageRect("์ด๋ฏธ์ง/๋ฏธ๋๊ฒ์/๋ฏธ๋๊ฒ์_๋
ธ๋๋ง์/๋ฏธ๋๊ฒ์_๋ ๋ชฌ๊ฒ์ ๋ ๋ชฌ(๋
ธ๋๋ง์).png", display.contentWidth/22.0233999, display.contentHeight/16.0810006)
lemon[1].name = "lemon"
end
if s ==2 then
lemon[2] = display.newImageRect("์ด๋ฏธ์ง/๋ฏธ๋๊ฒ์/๋ฏธ๋๊ฒ์_๋
ธ๋๋ง์/๋ฏธ๋๊ฒ์_๋ ๋ชฌ๊ฒ์ ๋ฉ๋ชจ์ง๋ ์ด(๋
ธ๋๋ง์).png", display.contentWidth/13.9251523, display.contentHeight/11.568)
lemon[2].name = "bug"
end
-- ๋ ๋ชฌ/๋ฒ๋ ์ฒ์ ์์น + body ์ถ๊ฐ
lemon[s].x, lemon[s].y = n,-25
phyics.addBody(lemon[s],{density=1.0, friction=0,bounce=0, radius=25})
lemon[s].gravityScale = 0.5 *k
sceneGroup:insert(lemon[s])
score:toFront()
time:toFront()
showScore:toFront()
showLimit:toFront()
end
-- pen ๊ฐ์ฒด ์ถ๊ฐ ๋ฐ ๋ง์ฐ์ค์ ๋ฐ๋ผ x์ถ ๋ณํ
local pen = display.newImageRect("์ด๋ฏธ์ง/๋ฏธ๋๊ฒ์/๋ฏธ๋๊ฒ์_๋
ธ๋๋ง์/๋ฏธ๋๊ฒ์_๋ ๋ชฌ๊ฒ์ ๋ฐ๊ตฌ๋(๋
ธ๋๋ง์).png",display.contentWidth/11.0471807,display.contentHeight/3.37922403)
pen.name = "pen"
pen.anchorY = 0
pen.x,pen.y = display.contentWidth/2.199, display.contentHeight/1.46260208
phyics.addBody(pen,"static")
sceneGroup:insert(pen)
function move1(event)
if event.x < display.contentWidth*0.1 then
pen.x = display.contentWidth*0.1
elseif event.x > display.contentWidth*0.9 then
pen.x = display.contentWidth*0.9
else
pen.x = event.x
end
end
function remove1(object)
object:remove()
end
-- ๋ ๋ชฌ๊ณผ ๋ฒ๋ ๊ฐ ๋ถ๋ชํ์ ๋ ์ ์ ์์น ๋ฐ ์ ์ ํ๋ฝ
function oncoll(self,event)
if event.phase == "began" then
if event.other.name == "lemon" or event.other.name == "bug" then
if event.target.name == "floor" then
timer.performWithDelay( 1000,event.other:removeSelf())
event.other=nil
m = m-1
end
if event.target.name == "pen" and event.other.y < display.contentHeight/1.444719 then
if event.other.name == "bug" then
if score_num > 0 then
score_num = score_num - 1
end
if score_num%5==0 then
score1 = score_num
showScore.text = score1
end
end
event.other:removeSelf()
event.other=nil
m = m-1
end
end
end
end
-- ํ์์ดํ
local function timeAttack( event )
limit = limit - 1
showLimit.text = limit
if limit == 0 then
Runtime:removeEventListener("mouse",move1)
timer.cancelAll()
composer.setVariable("score2", score1)
composer.removeScene("view09Lemon")
composer.gotoScene("view10Lemon")
end
end
timer.performWithDelay( 1000, timeAttack, 0 )
Runtime:addEventListener("mouse",move1)
-- 0.7์ด๋ง๋ค ๋ ๋ชฌ ์์ฑ.
timer.performWithDelay( 700, newlemon,-1)
timer.performWithDelay( 700, newlemon,-1)
pen.collision = oncoll
pen:addEventListener( "collision" )
floor.collision = oncoll
floor:addEventListener( "collision" )
pen:toFront()
showLimit:toFront()
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is still off screen and is about to move on screen
elseif phase == "did" then
-- Called when the scene is now on screen
--
-- INSERT code here to make the scene come alive
-- e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
-- Called when the scene is on screen and is about to move off screen
--
-- INSERT code here to pause the scene
-- e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == "did" then
composer.removeScene("view09Lemon")
end
end
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's "view" (sceneGroup)
--
-- INSERT code here to cleanup the scene
-- e.g. remove display objects, remove touch listeners, save state, etc.
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-----------------------------------------------------------------------------------------
return scene