-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.lua
More file actions
71 lines (52 loc) · 1.07 KB
/
Copy pathcontroller.lua
File metadata and controls
71 lines (52 loc) · 1.07 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
import "CoreLibs/graphics"
import "CoreLibs/sprites"
gfx = playdate.graphics
gfx.setColor(gfx.kColorWhite)
gfx.fillRect(0, 0, 400, 240)
gfx.setBackgroundColor(gfx.kColorWhite)
ball = gfx.sprite:new()
ball:setImage(gfx.image.new('ball'))
ball:moveTo(100,100)
ball:addSprite()
elapsedTime = 0
dx, dy = 0, 0
function playdate.leftButtonDown()
dx -= 1
print("Left Down")
end
function playdate.rightButtonDown()
dx += 1
print("Right Down")
end
function playdate.upButtonDown()
dy -= 1
print("Up Down")
end
function playdate.downButtonDown()
dy += 1
print("Down Down")
end
function playdate.leftButtonUp()
dx += 1
print("Left Up")
end
function playdate.rightButtonUp()
dx -= 1
print("Right Up")
end
function playdate.upButtonUp()
dy += 1
print("Up Up")
end
function playdate.downButtonUp()
dy -= 1
print("Down Up")
end
function playdate.update()
dt = 1/20
elapsedTime = elapsedTime + dt
moveDistance = 100 * dt
ball:moveTo(ball.x + dx * moveDistance, ball.y += dy * moveDistance)
-- print(ball.x .. "," .. ball.y)
gfx.sprite.update()
end