-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtug of war.lua
67 lines (48 loc) · 1.61 KB
/
tug of war.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
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local rope = display.newImage("images/rope.png", 0.01, 0.01)
rope.x = centerX
rope.y = centerY
local moveSpeed = 3
local pullSpeed = 7
local movetime = 0
local offsetY = 0
local function handleImageTap(event)
rope.y = rope.y + pullSpeed
end
local function moveImage(event)
movetime = movetime + 1
if movetime > 10 then
rope.y = rope.y - moveSpeed
movetime = 0
print(rope.y)
if rope.y > 280 then
print("獲勝!")
Runtime:removeEventListener("enterFrame", moveImage)
Runtime:removeEventListener("tap",handleImageTap)
local scoreText = display.newText("獲勝", display.contentCenterX, display.contentCenterY, native.systemFont, 110)
end
end
end
local function startGame()
Runtime:addEventListener("enterFrame", moveImage)
Runtime:addEventListener("tap", handleImageTap)
end
local startButton = display.newRect(centerX, centerY, 100, 50)
startButton:setFillColor(0.8, 0.8, 0.8)
local buttonText = display.newText("Start", centerX, centerY, native.systemFont, 20)
local function onStartButtonTap(event)
if event.phase == "ended" then
display.remove(startButton)
display.remove(buttonText)
startGame()
end
return true
end
startButton:addEventListener("touch", onStartButtonTap)