Advertisement
Symmetryc

The Irritating Game

Jun 4th, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. -- The Irritating Game, By Symmetryc
  2.  
  3. -- Change the variables to your liking.
  4. local screen = {}
  5. local c = {}
  6. c.back = colors.yellow
  7. c.b = colors.lightBlue
  8. local b = {}
  9. b[1] = {x=math.random(3, 49),y=5,vx=1,vy=-1,h=1,h2=9}
  10. b[2] = {x=math.random(3, 49),y=15,vx=-1, vy=-1,h=11,h2=18}
  11. b[3] = {x=25,y=10,w=5}
  12. b[4] = {x=25,y=19,w=5}
  13. local speed = 0.6
  14. local intspeed = 0.9
  15. local fps = 0.6
  16. local key = {"j","k","d","f"}
  17. local count = 0
  18.  
  19. local reset = function()
  20.     for i=0, 51 do
  21.         screen[i] = {}
  22.         for i2=1, 19 do
  23.             screen[i][i2] = false
  24.         end
  25.     end
  26. end
  27. local draw = function()
  28.     reset()
  29.     for i=1, 2 do
  30.         screen[b[i].x][b[i].y] = i
  31.     end
  32.     for i=3, 4 do
  33.         for i2=b[i].x-((b[i].w-1)/2), b[i].x+((b[i].w-1)/2) do
  34.             screen[i2][b[i].y] = i
  35.         end
  36.     end
  37.     for i=1, 51 do
  38.         for i2=1, 19 do
  39.             term.setCursorPos(i, i2)
  40.             term.setBackgroundColor(screen[i][i2] and c.b or c.back)
  41.             write(" ")
  42.         end
  43.     end
  44. end
  45. local time = os.clock()
  46. local main = function()
  47.     local id = os.startTimer(speed)
  48.     os.startTimer(fps)
  49.     while true do
  50.         draw()
  51.         term.setCursorPos(1, 1)
  52.         term.setBackgroundColor(c.back)
  53.         term.setTextColor(colors.red)
  54.         write(os.clock()-time)
  55.         local e = {os.pullEvent()}
  56.         if e[1]=="char" then
  57.             local n = (e[2]==key[1] or e[2]==key[2]) and 3 or 4
  58.             local d = ((e[2]==key[1] or e[2]==key[3]) and -1) or ((e[2]==key[2] or e[2]==key[4]) and 1) or 0
  59.             b[n].x = ((b[n].x+d)>=3 and (b[n].x+d)<=49) and b[n].x+d or b[n].x
  60.         elseif e[1]=="timer" and e[2]==id then
  61.             count = count+1
  62.             if count>5 then
  63.                 speed = speed*intspeed
  64.                 count = 0
  65.             end
  66.             for i=1, 2 do
  67.                 if (b[i].x+b[i].vx)>51 or (b[i].x+b[i].vx)<1 then
  68.                     b[i].vx = -b[i].vx
  69.                 end
  70.                 if (b[i].y+b[i].vy)>b[i].h2 and ((b[i+2].x-(b[i+2].w-1)/2)>b[i].x or (b[i+2].x+(b[i+2].w-1)/2)<b[i].x) then
  71.                     term.setBackgroundColor(colors.black)
  72.                     term.clear()
  73.                     term.setCursorPos(1, 1)
  74.                     error("Your score was: "..(os.clock()-time), 0)
  75.                 elseif (b[i].y+b[i].vy)<b[i].h or (b[i].y+b[i].vy)>b[i].h2 then
  76.                     b[i].vy = -b[i].vy
  77.                 end
  78.                 b[i].x = b[i].vx+b[i].x
  79.                 b[i].y = b[i].vy+b[i].y
  80.             end
  81.             id = os.startTimer(speed)
  82.         end
  83.     end
  84. end
  85. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement