local initialSpeed = 20
local brakes = 0.5
local speed = {initialSpeed, initialSpeed}
local stopping = {0,0}
local touched = 0
local area = { "area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1",
"area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1",
"area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1",
"area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1", "area1",
"area1", "area1", "area1", "area1", "area1",
"area2", "area2", "area2", "area2", "area2", "area2", "area2", "area2", "area2", "area2",
"area2", "area2", "area2", "area2", "area2", "area2", "area2", "area2", "area2", "area2",
"area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3",
"area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3",
"area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3",
"area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3", "area3",
"area4", "area4", "area4", "area4", "area4", "area4", "area4", "area4", "area4", "area4",
"area4", "area4", "area4", "area4", "area4", "area4", "area4", "area4", "area4", "area4",
"area4", "area4", "area4", "area4", "area4",
"area5", "area5", "area5", "area5", "area5", "area5", "area5", "area5", "area5", "area5",
"area5", "area5", "area5", "area5", "area5", "area5", "area5", "area5", "area5", "area5",
"area5", "area5", "area5", "area5", "area5", "area5", "area5", "area5", "area5", "area5",
"area5", "area5", "area5", "area5", "area5",
"area6", "area6", "area6", "area6", "area6", "area6", "area6", "area6", "area6", "area6",
"area7", "area7", "area7", "area7", "area7", "area7", "area7", "area7", "area7", "area7",
"area7", "area7", "area7", "area7", "area7", "area7", "area7", "area7", "area7", "area7",
"area7", "area7", "area7", "area7", "area7", "area7", "area7", "area7", "area7", "area7",
"area8", "area8", "area8", "area8", "area8",
"area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9",
"area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9",
"area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9",
"area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9",
"area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9", "area9",
"area10", "area10", "area10", "area10", "area10", "area10", "area10", "area10", "area10", "area10",
"area10", "area10", "area10", "area10", "area10", "area10", "area10", "area10", "area10", "area10",
"area10", "area10", "area10", "area10", "area10"
}
local function RemoveAll ()
Runtime:removeEventListener( "enterFrame", gameLoop )
Runtime:removeEventListener( "enterFrame", applyBrakes )
Runtime:removeEventListener("enterFrame", gameResult)
print("completed")
end
---------------------------------------------------------------------------------------------
----------------------------------------Game Result------------------------------------------
---------------------------------------------------------------------------------------------
local function checkArea(n)
for n = math.random(1, 100), #area, 100 do
areaCheck = area[n]
end
check = areaCheck
end
local function gameResult()
local score
if arrow.rotation \> 0 and arrow.rotation \<= 36 then
score = "area1"
elseif arrow.rotation \> 36 and arrow.rotation \<= 72 then
score = "area2"
elseif arrow.rotation \> 72 and arrow.rotation \<= 108 then
score = "area3"
elseif arrow.rotation \> 108 and arrow.rotation \<= 144 then
score = "area4"
elseif arrow.rotation \> 144 and arrow.rotation \<= 180 then
score = "area5"
elseif arrow.rotation \> 180 and arrow.rotation \<= 216 then
score = "area6"
elseif arrow.rotation \> 216 and arrow.rotation \<= 252 then
score = "area7"
elseif arrow.rotation \> 252 and arrow.rotation \<= 288 then
score = "area8"
elseif arrow.rotation \> 288 and arrow.rotation \<= 324 then
score = "area9"
else --if arrow.rotation \> 324 and arrow.rotation \<= 360 then
score = "area10"
end
globalScore = score
end
---------------------------------------------------------------------------------------------
---------------------------------------Game Looping------------------------------------------
---------------------------------------------------------------------------------------------
local function applyBrakes(event)
for i = 1, 2 do
if stopping[i] == 1 then
speed[i] = speed[i] - brakes
Runtime:removeEventListener("enterFrame", checkArea)
Runtime:addEventListener("enterFrame", gameResult)
gameResult()
print ("area = "..check)
print("globalscore = "..globalScore)
if (globalScore == check) == false then
if speed[i] \<= 0 then
speed[i] = speed[i] + 0.05
end
print("do nothing")
else
speed[i] = 0
end
end
end
end
local function applyMotion(i)
if arrow.rotation \>= 360 then
arrow.rotation = arrow.rotation - (360) + speed[i]
topboard.rotation = arrow.rotation
else
arrow.rotation = math.floor (arrow.rotation + speed[i])
topboard.rotation = arrow.rotation
end
end
local function gameLoop()
for i = 1, 2 do
applyMotion(i)
break
end
end
---------------------------------------------------------------------------------------------
-----------------------------------------Button----------------------------------------------
---------------------------------------------------------------------------------------------
local buttonStart = ui.newButton {
default = "Images/button.png",
over = "Images/button.png",
id = "Start",
text = "start",
font = native.systemFontBold,
textColor = {0,0,0, 255},
size = 20,
align = "center"
}
buttonStart.x = W
buttonStart.y = H + 150
local buttonStop = ui.newButton {
default = "Images/button.png",
over = "Images/button.png",
id = "Stop",
text = "Stop",
font = native.systemFontBold,
textColor = {0,0,0, 255},
size = 20,
align = "center"
}
buttonStop.x = W
buttonStop.y = H + 150
buttonStop.isVisible = false
local buttonSpin = ui.newButton {
default = "Images/button.png",
over = "Images/button.png",
id = "Spin",
text = "Spin",
font = native.systemFontBold,
textColor = {0,0,0, 255},
size = 20,
align = "center"
}
buttonSpin.x = W
buttonSpin.y = H + 150
buttonSpin.isVisible = false
---------------------------------------------------------------------------------------------
--------------------------------------Button Funtion-----------------------------------------
---------------------------------------------------------------------------------------------
-- local function spinGame (event)
-- Runtime:addEventListener( "enterFrame", gameLoop )
-- Runtime:addEventListener( "enterFrame", checkArea )
-- buttonStop.isVisible = true
-- buttonSpin.isVisible = false
-- if event.phase == "began" then
-- touched = touched + 1
-- if stopping[2] == 1 then
-- speed = { initialSpeed, initialSpeed}
-- stopping = {0, 0} -- 0 = false, 1 = stopping, 2 = stopped
-- touched = 0
-- return
-- end
-- if (touched \>= 2) then
-- return
-- end
-- end
-- end
local function stopGame (event)
Runtime:addEventListener( "enterFrame", applyBrakes )
buttonStop.isVisible = false
buttonSpin.isVisible = true
for i = 1, 2, 1 do
if stopping[i] == 0 then
stopping[i] = 1
stopping[i+1] = 1
break
end
end
end
local function startGame (event)
buttonStart.isVisible = false
buttonStop.isVisible = true
Runtime:addEventListener( "enterFrame", gameLoop )
Runtime:removeEventListener( "enterFrame", gameResult)
Runtime:addEventListener( "enterFrame", checkArea )
end
this is my code…
but this got some error when the arrow rotation and area check are not match, the arrow will keep spinning…i dunno how to solve it…
i wanna make it like
after user clicked stop button
if score = check
then the arrow.rotation will stop slowly to the area…
but if the arrow.rotation speed is 0 but it is still not in the area, i wanna make it rotate on one time to the area…can someone help me…
[import]uid: 33180 topic_id: 8165 reply_id: 29300[/import]