Team XSaturn - Tutorials - simple player movement
This tutorial is going to tell you how to make a program that moves the player in lua.
ok, first define our colors:
red = Color.new(255,0,0)
next, we need to have an array for the player:
player = {x = 0, y = 0, img = Image.createEmpty(32,32)}
player.img:clear(red)
next we have our function:
function controls()
if pad:up() then
player.y = player.y - 2
end
if pad:down() then
player.y = player.y + 2
end
if pad:left() then
player.y = player.x - 2
end
if pad:right() then
player.x = player.x + 2
end
end
and finally, our main loop:
while true do
screen:clear()
pad = Controls.read()
controls()
screen.waitVblankStart()
screen.flip()
end
and that's all there is to it!