Advertisement
CaptainSpaceCat

Gravity

Jun 12th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. local star = {5,5}
  2. --term.redirect(peripheral.wrap("right"))
  3. local w,h = term.getSize()
  4. local xDir = "+"
  5. local yDir = "+"
  6. local grav = 0
  7. local gravActive = true
  8.  
  9. function redraw(x,y)
  10.   draw("*",x,y)
  11.   sleep(.05)
  12.   draw(" ",x,y)
  13. end
  14.  
  15. function showinfo()
  16.   term.setCursorPos(1, 1)
  17.   term.clearLine()
  18.   draw(tostring(grav), w - #tostring(grav) + 1, 1)
  19. end
  20.  
  21. function draw(words,x,y)
  22.   term.setCursorPos(x,y)
  23.   write(words)
  24. end
  25.  
  26. while true do
  27.   redraw(star[1],star[2])
  28.   local prevPos = {posX, posY}
  29.   local posX, posY = term.getCursorPos()
  30.   if prevPos[2] == posY then
  31.     gravActive = false
  32.   end
  33.   showinfo()
  34.   if posX == 1 then
  35.     xDir = "+"
  36.   end
  37.   if posY >= h then
  38.     grav = (math.abs(grav) - .6)
  39.   end
  40.   if posX == w then
  41.     xDir = "-"
  42.   end
  43.   if posY <= 1 then
  44.     grav = -(math.abs(grav) - .6)
  45.   end
  46.   if xDir == "+" then
  47.     star[1] = star[1] + 1
  48.   else
  49.     star[1] = star[1] - 1
  50.   end
  51.   if gravActive then
  52.   star[2] = star[2] - grav
  53.   grav = grav - .5
  54.   end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement