Advertisement
guitarplayer616

starBounce

Jun 12th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. local star = {5,5}
  2. term.redirect(peripheral.wrap("right"))
  3. local w,h = term.getSize()
  4. local dir = "++"
  5.  
  6. dir = dir:sub(1,1)..dir:sub(2,2)
  7.  
  8. function Main()
  9.   redraw(star[1],star[2])
  10.   local posX,posY = term.getCursorPos()
  11.   if posX == 1 then
  12.     dir = "+"..dir:sub(2,2)
  13.   elseif posX == w then
  14.     dir = "-"..dir:sub(2,2)
  15.   end
  16.   if posY == 1 then
  17.     dir = dir:sub(1,1).."+"
  18.   elseif posY == h then
  19.     dir = dir:sub(1,1).."-"
  20.   end
  21.   local modX = dir:sub(1,1)
  22.   local modY = dir:sub(2,2)
  23.   if modX == "+" then
  24.     star[1] = star[1] + 1
  25.   else
  26.     star[1] = star[1] - 1
  27.   end
  28.   if modY == "+" then
  29.     star[2] = star[2] + 1
  30.   else
  31.     star[2] = star[2] - 1
  32.   end
  33. end
  34.  
  35.  
  36. function redraw(x,y)
  37.   draw("*",x,y)
  38.   sleep(.5)
  39.   draw(" ",x,y)
  40. end
  41.  
  42. function draw(words,x,y)
  43.   term.setCursorPos(x,y)
  44.   write(words)
  45. end
  46.  
  47. while true do
  48.   Main()
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement