Advertisement
GauHelldragon

guyMover v0.1

May 8th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.89 KB | None | 0 0
  1. local x,y = 5,5
  2. local oldx,oldy = 5,5
  3. scancode
  4. local left_key, right_key, up_key, down_key = 203, 205, 200, 208
  5. local quit_key = 45
  6.  
  7. maxx, maxy = term.getSize()
  8.  
  9. function drawGuy()
  10.    term.setCursorPos(x,y)
  11.    term.write("@")
  12. end
  13. function eraseGuy()
  14.    term.setCursorPos(oldx,oldy)
  15.    term.write(" ")
  16. end
  17. function moveGuy(code)
  18.   if ( code == left_key ) then x = x - 1 end
  19.   if ( code == right_key ) then x = x + 1 end
  20.   if ( code == up_key ) then y = y - 1 end
  21.   if ( code == down_key ) then y = y + 1 end
  22.   x = max(1,x)
  23.   x = min(maxx,x)
  24.   y = max(1,y)
  25.   y = min(maxy,y)
  26.  
  27. end
  28.  
  29.  
  30.  
  31. term.clear()
  32. drawGuy()
  33.  
  34. while scancode ~= quit_key do
  35.  
  36.   event, scancode = os.pullEvent("key")
  37.  
  38.   if ( scancode == left_key or scancode == right_key or scancode == up_key or scancode == down_key ) then
  39.     oldx = x
  40.     oldy = y
  41.     moveGuy(scancode)
  42.     eraseOldGuy()
  43.     drawGuy()
  44.   end
  45.  
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement