Guest User

Untitled

a guest
Oct 24th, 2015
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. local char = ">"
  2. local playerX = 1
  3. local playerY = 1
  4.  
  5. function drawCharacter()
  6.   term.clear()
  7.   term.setCursorPos(playerX, playerY)
  8.   write(char)
  9. end
  10.  
  11. function newSolidObject(obx, oby, obj)
  12.  
  13.     term.setCursorPos(obx, oby)
  14.     write(obj)
  15.         if playerX == obx and char == ">" then
  16.             playerX = playerX - 1
  17.         elseif playerX == obx and char == "<" then
  18.             playerX = playerX + 1
  19.         elseif playerY == oby and char == "^" then
  20.             playerY = playerY + 1
  21.         elseif playerY == oby and char == "v" then
  22.             playerY = playerY -1
  23.     drawCharacter()
  24. end
  25. end
  26.  
  27. function drawMap()
  28. term.clear()
  29.     newSolidObject(4, 4, "x")
  30. drawCharacter()
  31.  
  32. end
  33.  
  34. while true do
  35.   drawCharacter()
  36.   drawMap()
  37.   local e,key = os.pullEvent( "key" )
  38.   if key == 17 or key == 200 then
  39.                 playerY = playerY -1
  40.                 char = "^"
  41.   elseif key == 31 or key == 208 then
  42.                 playerY = playerY +1
  43.                 char = "v"
  44.   elseif key == 203 or key == 30 then
  45.                 playerX = playerX -1
  46.                 char = "<"
  47.    elseif key == 205 or key == 32 then
  48.                 playerX = playerX +1
  49.                 char = ">"
  50.    elseif key == 15 then
  51.                 break
  52.    end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment