-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.lua
59 lines (46 loc) · 1.24 KB
/
main.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
-- Example program for using paddy library
function love.load()
-- Load the paddy module
require("paddy")
-- Create an object we can move
player = {}
player.x = love.graphics.getWidth()/2
player.y = love.graphics.getHeight()/2
player.speed = 500
player.w = 50
player.h = 70
end
function love.update(dt)
-- Check the dpad for touch events
paddy.update(dt)
if paddy.isDown("up") then
player.y = player.y - player.speed *dt
elseif paddy.isDown("down") then
player.y = player.y + player.speed *dt
elseif paddy.isDown("left") then
player.x = player.x - player.speed *dt
elseif paddy.isDown("right") then
player.x = player.x + player.speed *dt
end
if paddy.isDown("x") then
player.w = player.w - player.speed *dt
elseif paddy.isDown("y") then
player.w = player.w + player.speed *dt
elseif paddy.isDown("a") then
player.h = player.h - player.speed *dt
elseif paddy.isDown("b") then
player.h = player.h + player.speed *dt
end
end
function love.draw()
-- Draw the player
love.graphics.setColor(255,0,0,255)
love.graphics.rectangle("fill", player.x,player.y,player.w,player.h)
-- Draw the touchpad controls
paddy.draw()
end
function love.keypressed(key)
if key == "escape" then
love.event.quit()
end
end