Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. --globals
  2. px,py=64,64
  3.  
  4. --check if button was pressed previously
  5. function btn_prev(i)
  6.   return (btn(i) and 2^i==band(2^i,btn_))
  7. end
  8.  
  9. function _update()
  10.   --check if player is still moving in the same direction as last frame
  11.   if not btn(direction) then
  12.     direction=-1
  13.   end
  14.  
  15.   --check if there is a new button pressed
  16.   for i=0,3 do
  17.     if btn(i) and (not btn_prev(i) or direction==-1) then
  18.       direction=i
  19.     end
  20.   end
  21.  
  22.   --move player
  23.   if btnp(direction) then
  24.     if direction<=1 then
  25.       px+=(direction-0.5)*16
  26.     else
  27.       py+=(direction-2.5)*16
  28.     end
  29.   end
  30.  
  31.   --store current buttons
  32.   btn_ = btn()
  33. end
  34.  
  35. function _draw()
  36.     cls()
  37.     print("direction "..direction)
  38.     print("x "..px..", y "..py)
  39.     pset(px,py)
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement