Same thing but this time with tables.
local Wnd={x = 320,y = 240,w = 0,caption = "Ship Movement"}
local paint={R=rnd()*256,G=rnd()*256,B=rnd()*256}
local keys={ESC=27}
openwindow(Wnd.x,Wnd.y,Wnd.w,Wnd.caption)
backcolor(paint.R,paint.G,paint.B)
setframetimer(60)
--' set the color key for the image that will be loaded, in this case 0,0,0 or black
colorkey(0,0,0)
--' function to load the image and path
player = {image = loadimage("ship.bmp"),x = Wnd.x/2-64/2,y = Wnd.y-64,speed = 3,visible = true}
--' main loop, this will repeat until a certain key or instruction is pressed or passed
repeat
--' clear the screen
cls()
--' declare a var to get the key that the user is pressing
key=getkey()
--' now we are trying to test what key was presses
if key == 276 then
--' if it was key left then the player goes back 3 pix.
player.x = player.x -player.speed
end
if key == 275 then
--' if it was right then goes forward 3 pix
player.x = player.x + player.speed
end
if key == 273 then
--'if it was up
player.y = player.y - player.speed
end
if key == 274 then
--' if it was down
player.y = player.y + player.speed
end
--' if the ship is alive then we print it in the screen
if player.visible then
putimage(player.x,player.y,player.image)
end
--' function to put everything in the screen
sync()
--' wait until the esc key is pressed and if it was pressed then
until key == keys.ESC
--' close the window and go away.... :)
closewindow()