Advertisement
guitarplayer616

CC Bloons Tower Defense

Jun 29th, 2015
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. local w,h = term.getSize()
  2. local previous = {0,math.floor(h/2)}
  3. local entry = {1,math.floor(h/2)}
  4. local exit = {w,math.floor(h/2)}
  5.  
  6.  
  7. local buffer = {}
  8. for x = 1,w do
  9.     buffer[x] = {}
  10.     for y = 1,h do
  11.         buffer[x][y] = nil
  12.     end
  13. end
  14.  
  15.  
  16. for x= 1, w do
  17.     buffer[x][math.floor(h/2)] = {char=" ",track=true,backcol=colors.orange}
  18. end
  19.  
  20. function Balloon(layer, delay)
  21.     local balloon = {}
  22.     balloon.speed = layer
  23.     balloon.layer = layer
  24.     balloon.delay = delay
  25.     balloon.pos = entry
  26.     balloon.previous = previous
  27.     balloon.dir = "east"
  28.     if layer == 1 then
  29.         balloon.color = colors.red
  30.     elseif layer == 2 then
  31.         balloon.color = colors.blue
  32.     elseif layer == 3 then
  33.         balloon.color = colors.green
  34.     end
  35.     return balloon
  36. end
  37.  
  38.  
  39. bloons = {
  40. red = Balloon(1,0),
  41. red2 = Balloon(1,2),
  42. blue = Balloon(2,4),
  43. green = Balloon(3,7),
  44. }
  45.  
  46. ntime = 0
  47.  
  48. for x=1,w do
  49.     for y=1,h do
  50.         if buffer[x][y] then
  51.             term.setBackgroundColor(buffer[x][y].backcol)
  52.             term.setCursorPos(x,y)
  53.             term.write(buffer[x][y].char)
  54.         end
  55.     end
  56. end
  57.  
  58. while true do
  59.     for _,bloon in pairs(bloons) do
  60.         if ntime >= bloon.delay then
  61.             term.setCursorPos(bloon.pos[1],bloon.pos[2])
  62.             term.setBackgroundColor(bloon.color)
  63.             term.write(" ")
  64.             term.setBackgroundColor(colors.orange)
  65.             term.setCursorPos(bloon.previous[1],bloon.previous[2])
  66.             term.write(" ")
  67.             bloon.previous[1],bloon.previous[2] = bloon.pos[1],bloon.pos[2]
  68.             if bloon.dir == "east" then
  69.                 bloon.pos[1] = bloon.pos[1] + 1
  70.             end
  71.         end
  72.     end
  73.     sleep(1)
  74.     ntime = ntime + 1
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement