Advertisement
Guest User

spcam

a guest
Apr 23rd, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.17 KB | None | 0 0
  1. --Tank
  2. --[[ Info:
  3.   Welcome to World of Tanks. Your objective is to
  4.   eliminate all tanks from the playing field.
  5.  
  6.   Enemys:
  7.   Red - Moves
  8.   Green - Shoots
  9.   Orange - Shoots and moves
  10.  
  11.   Help:
  12.   Ammo Packs
  13.   Health Packs
  14.   Extra Support (Not Implemented Yet)
  15.  
  16.   Information about scoring:
  17.     Scoring is recorded in the user's player.stat
  18.     file. Here is how scoring goes:
  19.       Enemy Red Kill - 10 pt
  20.       Enemy Green Kill - 15 pt
  21.       Enemy Orange Kill - 20 pt
  22.       Headshots - 15 pt
  23.       Ship Level Up - 20 pt
  24.       Ship Extra Exp - 10 pt
  25.       Ammo Pack -  -5 pt
  26.       Health Packs -  -5 pt
  27.    
  28.    Information about experience:
  29.      Experience is gathered to ulock other tanks.
  30.      As of now there are certain tanks but in the
  31.      future customization may be an option. Some
  32.      tanks may have higher health ,some may have
  33.      more ammo, some may get more health from
  34.      health packs, some may get kill streaks,
  35.      some may enable more exp and much more:
  36.      
  37.        Enemy Kills: 1 exp
  38.        Headshots: 2 exp
  39.        
  40.        Maximum Exp (How much exp you need to level up) :
  41.        20 exp
  42.  
  43.   Information about the player.stat file:
  44.   The player.stat file holds the following info
  45.   in the file in the following order:
  46.     Name
  47.     Campaign Level
  48.     Highscore
  49.     Total Lifetime Shots
  50.     Total Lifetime Enemies Killed
  51.     Total Lifetime Deaths
  52.     Waves
  53. ]]--
  54.  
  55. w,h = term.getSize()
  56.  
  57. running = true
  58.  
  59. refresh = 0.10
  60. gtId = os.startTimer(refresh)
  61.  
  62. brefresh = 1.5
  63. gtId2 = os.startTimer(brefresh)
  64.  
  65. brand = math.random(0.10, 1.5)
  66. gtId3 = os.startTimer(brand)
  67.  
  68. hrefresh = 3
  69. gtId4 = os.startTimer(hrefresh)
  70.  
  71. levelprogress = 0
  72. tries = 1
  73.  
  74. score = 0
  75. maxexp = 20
  76.  
  77. killstreak = 0
  78.  
  79. --Opens the player stat file and player info file --
  80. h = fs.open("Tanks/player.stat", "r")
  81. p = fs.open("Tanks/player.info", "r")
  82. name = h.readLine()
  83. level = h.readLine()
  84. highscore1 = h.readLine()
  85. tlbullets = h.readLine()
  86. tlenemies = h.readLine()
  87. tldeaths = h.readLine()
  88. wavenum = h.readLine()
  89.  
  90. levelplayer = p.readLine()
  91. expplayer = p.readLine()
  92. xplayer = p.readLine()
  93. yplayer = p.readLine()
  94. hpplayer = p.readLine()
  95. maxhpplayer = p.readLine()
  96. ammoplayer = p.readLine()
  97. colorplayer = p.readLine()
  98.  
  99. lbullets = tlbullets
  100. lenemies = tlenemies
  101. ldeaths = tldeaths
  102. levelpro = tonumber(level)
  103. playerlevel = tonumber(levelplayer)
  104. playerexp = tonumber(expplayer)
  105. playerx = tonumber(xplayer)
  106. playery = tonumber(yplayer)
  107. playerhp = tonumber(hpplayer)
  108. playermaxhp = tonumber(maxhpplayer)
  109. playerammo = tonumber(ammoplayer)
  110. playercolor = tostring(colorplayer)
  111. highscore = tonumber(highscore1)
  112.  
  113. w,h = term.getSize()
  114.  
  115. tankInfo = {
  116.   x = 22,
  117.   y = h - 5,
  118.   hp = playerhp,
  119.   maxhp = playermaxhp,
  120.   ammo = playerammo,
  121.   exp = playerexp,
  122.   color = playercolor
  123. }
  124.  
  125. bullets = { }
  126. ent = { }
  127. ammopack = { }
  128. healthpack = { }
  129.  
  130. bulletColor = {
  131.   colors.white,
  132.   colors.gray,
  133.   colors.red,
  134.   colors.green,
  135.   colors.orange
  136. }
  137.  
  138. tankBullet = bulletColor[1]
  139. enemyBullet = bulletColor[4]
  140. ent3Bullet = bulletColor[5]
  141.  
  142. function createBullets(x, y, xvel, yvel, typeBullets, bdmg)
  143.   table.insert(bullets, {
  144.     x = x,
  145.     y = y,
  146.     xstep = xvel,
  147.     ystep = yvel,
  148.     type = typeBullets,
  149.     dmg = bdmg
  150.    })
  151. end
  152.  
  153. function createEnt(x, y, typeEnt, entNumber, xvel, yvel, entId)
  154.   table.insert(ent, {
  155.   x = x,
  156.   y = y,
  157.   color = typeEnt,
  158.   newEnt = entNumber,
  159.   xstep = xvel,
  160.   ystep = yvel,
  161.   ID = entId
  162.   })
  163. end
  164.  
  165. function createAmmo(x, y, amount)
  166.   table.insert(ammopack, {
  167.   x = x,
  168.   y = y,
  169.   amount = amount
  170.   })
  171. end
  172.  
  173. function createHPack(x, y, amount)
  174.   table.insert(healthpack, {
  175.   x = x,
  176.   y = y,
  177.   amount = amount
  178.   })
  179. end
  180.  
  181. function createPlayer(playerx, playery, playerhp, playermaxhp, playerammo, playerexp)
  182.   table.insert(tankInfo, {
  183.   x = playerx,
  184.   y = playery,
  185.   hp = playerhp,
  186.   maxhp = playermaxhp,
  187.   ammo = playerammo,
  188.   exp = playerexp
  189.   })
  190. end
  191.    
  192. function tank()
  193. term.setTextColor(tankInfo.color)
  194.   term.setCursorPos(tankInfo.x, tankInfo.y)
  195.   print(" | ")
  196.   term.setCursorPos(tankInfo.x, tankInfo.y + 1)
  197.   print("*-*")
  198.   term.setCursorPos(tankInfo.x, tankInfo.y + 2)
  199.   print("| |")
  200.   term.setCursorPos(tankInfo.x, tankInfo.y + 3)
  201.   print("*-*")
  202. end
  203.  
  204. function enemy()
  205. for _, v in pairs(ent) do
  206. term.setTextColor(v.color)
  207.   term.setCursorPos(v.x, v.y)
  208.   print(" | ")
  209.   term.setCursorPos(v.x, v.y - 1)
  210.   print("*-*")
  211.   term.setCursorPos(v.x, v.y - 2)
  212.   print("| |")
  213.   term.setCursorPos(v.x, v.y - 3)
  214.   print("*-*")
  215.  end
  216. end
  217.  
  218. function ammoPack()
  219. for _, v in pairs(ammopack) do
  220.   term.setTextColor(colors.yellow)
  221.   term.setCursorPos(v.x, v.y)
  222.   print("[]")
  223. end  
  224. end
  225.  
  226. function healthPack()
  227. for _, v in pairs(healthpack) do
  228.   term.setTextColor(colors.red)
  229.   term.setCursorPos(v.x, v.y)
  230.   print("[]")
  231. end
  232. end
  233.  
  234. function updateEnt()
  235.   if #ent > 0 then
  236.     for i = 1, #ent do
  237.       if ent[i] then
  238.         local ents = ent[i]
  239.         if ents.ID == 1 then
  240.           moveEnemy1(i, 5)
  241.         elseif ents.ID == 3 then
  242.           moveEnemy1(i, 10)
  243.         end
  244.       end
  245.     end
  246.   end
  247. end
  248.  
  249. function updateEnt2()
  250.   if #ent > 0 then
  251.     for i = 1, #ent do
  252.       if ent[i] then
  253.         local ents = ent[i]
  254.         if ents.ID == 2 then
  255.           enemyBullets(i)
  256.         end
  257.       end
  258.     end
  259.   end
  260. end
  261.  
  262. function updateEnt3()
  263.   if #ent > 0 then
  264.     for i = 1, #ent do
  265.       if ent[i] then
  266.         local ents = ent[i]
  267.         if ents.ID == 3 then
  268.           enemy3Bullets(i)
  269.         end
  270.       end
  271.     end
  272.   end
  273. end
  274.  
  275.  
  276. function checkForCollison()
  277.   if #ent > 0 then
  278.     for i = 1, #ent do
  279.       if ent[i] then
  280.         local ents = ent[i]
  281.         if not (ents.x > tankInfo.x or ents.x + 2 < tankInfo.x or ents.y - 3 > tankInfo.y + 3 or ents.y < tankInfo.y) then
  282.           running = false
  283.           endGame("Tip: You should not run head first into battle")
  284.         end
  285.       end
  286.     end
  287.   end
  288. end
  289.  
  290. function updateAmmo()
  291.   for _, v in pairs(ammopack) do
  292.     if not (v.x > tankInfo.x or v.x + 1 < tankInfo.x or v.y > tankInfo.y + 3 or v.y < tankInfo.y) then
  293.       tankInfo.ammo = tankInfo.ammo + v.amount
  294.       table.remove(ammopack, 1)
  295.       score = score - 5
  296.       break
  297.     end
  298.   end
  299. end
  300.  
  301. function updateHealth()
  302.   for _, v in pairs(healthpack) do
  303.     if not (v.x > tankInfo.x or v.x + 1 < tankInfo.x or v.y > tankInfo.y + 3 or v.y < tankInfo.y) then
  304.       tankInfo.hp = tankInfo.hp + v.amount
  305.       table.remove(healthpack, 1)
  306.       score = score - 5
  307.       break
  308.     end
  309.   end
  310. end
  311.  
  312. function endGame(deathmsg)
  313.     local select = 1
  314.   function optionsdraw()
  315.     term.clear()
  316.     term.setTextColor(colors.black)
  317.     term.setBackgroundColor(colors.white)
  318.     term.clear()
  319.     bg = paintutils.loadImage("Tanks/bgt")
  320.     paintutils.drawImage(bg, 1,1)
  321.     term.setBackgroundColor(colors.white)
  322.     term.setCursorPos(w/2 - 4, 11)
  323.     print("GAME OVER")
  324.     term.setCursorPos(4, 13)
  325.     print(deathmsg)
  326.     term.setCursorPos(w/2 - 8, 15)
  327.     print("Retry Last Level")
  328.     term.setCursorPos(w/2 - 4, 17)
  329.     print("Quit Game")
  330.       if select == 1 then
  331.         term.setCursorPos(w/2 - 9, 15)
  332.         print("[")
  333.         term.setCursorPos(w/2 + 8, 15)
  334.         print("]")
  335.       else
  336.         term.setCursorPos(w/2 - 5, 17)
  337.         print("[")
  338.         term.setCursorPos(w/2 + 5, 17)
  339.         print("]")
  340.       end
  341.   end
  342.   optionsdraw()
  343.     while true do
  344.       local event, p1 = os.pullEventRaw()
  345.         if event == "key" then
  346.           if p1 == keys.w or p1 == keys.s or p1 == keys.up or p1 == keys.down then
  347.             select = -select
  348.             optionsdraw()
  349.           elseif p1 == keys.enter or p1 == keys.space then
  350.             if select == 1 and tries <= 1 then
  351.               running = true
  352.               tankInfo.x = playerx
  353.               tankInfo.y = playery
  354.               tankInfo.hp = tankInfo.maxhp
  355.               tankInfo.ammo = playerammo
  356.               tankInfo.exp = 0
  357.               term.setBackgroundColor(colors.black)
  358.               term.setTextColor(colors.white)
  359.                 for i = 1, #healthpack do
  360.                   table.remove(healthpack, i)
  361.                 end
  362.                 gtId = os.startTimer(refresh)
  363.                 gtId2 = os.startTimer(brefresh)
  364.                 gtId3 = os.startTimer(brand)
  365.                 gtId4 = os.startTimer(hrefresh)
  366.               drawBg()
  367.               updateBullets()
  368.               tries = tries + 1
  369.               ldeaths = ldeaths + 1
  370.               break  
  371.             else
  372.             ldeaths = ldeaths + 1
  373.             filelevel = 0
  374.             filescore = 0
  375.             if levelpro > levelprogress then
  376.               filelevel = levelpro
  377.             elseif levelprogress > levelpro then
  378.               filelevel = levelprogress
  379.             end
  380.             if score > highscore then
  381.               filescore = score
  382.             elseif highscore > score then
  383.               filescore = highscore
  384.             end
  385.             w = fs.open("Tanks/player.stat", "w")
  386.             w.writeLine(name)
  387.             w.writeLine(filelevel)
  388.             w.writeLine(filescore)
  389.             w.writeLine(lbullets)
  390.             w.writeLine(lenemies)
  391.             w.writeLine(ldeaths)
  392.             w.writeLine(wavenum)
  393.             w.flush()
  394.             w.close()
  395.             pl = fs.open("Tanks/player.info", "w")
  396.             pl.writeLine(playerlevel)
  397.             pl.writeLine(playerexp)
  398.             pl.flush()
  399.             pl.close()
  400.               term.clear()
  401.               term.setTextColor(colors.white)
  402.               term.setBackgroundColor(colors.black)
  403.               term.clear()
  404.               term.setCursorPos(1,1)
  405.               print("Thank you for playing")
  406.               return
  407.             end
  408.           end
  409.         end
  410.     end
  411.   end
  412.  
  413.  createPlayer(22, h - 5, 15, 15, 10, playerexp)
  414.  
  415. function drawBg()
  416. term.clear()
  417.   for i = 1, w do
  418.   term.setTextColor(colors.white)
  419.     term.setCursorPos(w - (i), h - 1)
  420.     write("-")
  421.   end
  422.   for i = 1, h do
  423.     term.setTextColor(colors.white)
  424.       term.setCursorPos(5, h - (i))
  425.       write("|")
  426.   end
  427.   function hpbar()
  428.   for i = 1, (tankInfo.hp/tankInfo.maxhp)*5 do
  429.     term.setBackgroundColor(colors.red)
  430.     term.setCursorPos(2, 15 - (i))
  431.     write("  ")
  432.     term.setBackgroundColor(colors.black)
  433.   end
  434.   end
  435.   function expbar()
  436.   for i = 1, (tankInfo.exp/maxexp)*10 do
  437.     term.setBackgroundColor(colors.orange)
  438.     term.setCursorPos( (w-13) + (i), h - 1)
  439.     write(" ")
  440.     term.setBackgroundColor(colors.black)
  441.   end
  442.   end
  443.   term.setCursorPos(1, 9)
  444.   print("*--*")
  445.   for i = 1, 5 do
  446.     term.setTextColor(colors.white)
  447.     term.setCursorPos(1, 15 - (i))
  448.     write("|  |")
  449.     hpbar()
  450.   end
  451.   term.setCursorPos(1,15)
  452.   print("*--*")
  453.   --term.setCursorPos(w - 15, 1)
  454.   --print("Score: "..score)
  455.   term.setCursorPos(1,2)
  456.   print("Tank")
  457.   print("    ")
  458.   print("Ammo")
  459.   print(tankInfo.ammo)
  460.   print("    ")
  461.   print("HP ")
  462.   term.setCursorPos(2,8)
  463.   print(tankInfo.hp)
  464.   term.setCursorPos(1,15)
  465.   print("Score")
  466.   print(score)
  467. term.setCursorPos(1,h)
  468. print("Tank Info -     Name: "..name.."  Exp: Level "..playerlevel)
  469. term.setCursorPos( w - 20, h - 1)
  470. expbar()
  471. tank()
  472.  
  473.   for _, v in pairs(bullets) do
  474.     term.setCursorPos(v.x, v.y)
  475.     term.setTextColor(v.type)
  476.     term.write(".")
  477.     term.setTextColor(colors.black)
  478.   end
  479.   --Draws all the desired enemies on the screen
  480.     enemy()
  481.     ammoPack()
  482.     healthPack()
  483. end
  484.  
  485. function createNewLevel()
  486.   if levelprogress == 0 then
  487.     createEnt(10, 5, colors.red,1,1,0,1)
  488.     levelprogress = levelprogress + 1
  489.   elseif levelprogress == 1 then
  490.     createEnt(10, 5, colors.green,1,0,0,2)
  491.     levelprogress = 2
  492.   elseif levelprogress == 2 then
  493.     createEnt(10, 5, colors.orange,1,1,0,3)
  494.     levelprogress = 3
  495.   elseif levelprogress == 3 then
  496.     createEnt(10, 5, colors.red, 1,1,0,1)
  497.     createEnt(20, 10, colors.green,2,0,0,2)
  498.     levelprogress = 4
  499.   elseif levelprogress == 4 then
  500.     createEnt(10, 5, colors.red, 1,1,0,1)
  501.     createEnt(20, 10, colors.orange,2,1,0,3)
  502.     levelprogress = 5
  503.   elseif levelprogress == 5 then
  504.     createEnt(10, 5, colors.red, 1,1,0,1)
  505.     createEnt(20, 10, colors.green, 2,0,0,2)
  506.     createEnt(40, 10, colors.green, 3,0,0,2)
  507.     levelprogress = 6
  508.   elseif levelprogress == 6 then
  509.     createEnt(10, 5, colors.red, 1,1,0,1)
  510.     createEnt(20, 10, colors.green, 2,0,0,2)
  511.     createEnt(40, 10, colors.green, 3,0,0,2)
  512.     createEnt(30, 10, colors.green, 4,0,0,2)
  513.     levelprogress = 7
  514.   elseif levelprogress == 7 then
  515.     createEnt(10, 5, colors.red, 1,1,0,1)
  516.     createEnt(20, 5, colors.red, 2,1,0,1)
  517.     createEnt(30, 5, colors.red, 3,1,0,1)
  518.     createEnt(40, 5, colors.red, 4,1,0,1)
  519.     createEnt(25, 10, colors.red, 5,1,0,1)
  520.     createEnt(35, 10, colors.red, 6,1,0,1)
  521.     levelprogress = 8
  522.   elseif levelprogress == 8 then
  523.     createEnt(10, 5, colors.green, 1,0,0,2)
  524.     createEnt(20, 5, colors.green, 2,0,0,2)
  525.     createEnt(30, 5, colors.green, 3,0,0,2)
  526.     createEnt(40, 5, colors.green, 4,0,0,2)
  527.     levelprogress = 9
  528.   elseif levelprogress == 9 then
  529.     createEnt(10, 10, colors.orange, 1,1,0,3)
  530.     createEnt(20, 10, colors.orange, 2,1,0,3)
  531.     levelprogress = 10
  532.   elseif levelprogress == 10 then
  533.     createEnt(10, 5, colors.red, 1,1,0,1)
  534.     createEnt(20, 5, colors.red, 2,1,0,1)
  535.     createEnt(30, 5, colors.red, 3,1,0,1)
  536.     createEnt(25, 10, colors.green, 4,0,0,2)
  537.     createEnt(15, 10, colors.green, 5,0,0,2)
  538.     levelprogress = 11
  539.   elseif levelprogress == 11 then
  540.     createEnt(10, 5, colors.red, 1,1,0,1)
  541.     createEnt(20, 5, colors.red, 2,1,0,1)
  542.     createEnt(30, 5, colors.red, 3,1,0,1)
  543.     createEnt(20, 10, colors.orange, 4,1,0,3)
  544.     levelprogress = 12
  545.   elseif levelprogress == 12 then
  546.     createEnt(10, 5, colors.red, 1,1,0,1)
  547.     createEnt(20, 5, colors.red, 2,1,0,1)
  548.     createEnt(30, 5, colors.red, 3,1,0,1)
  549.     createEnt(40, 5, colors.red, 4,1,0,1)
  550.     createEnt(25, 10, colors.green, 5,0,0,2)
  551.     createEnt(35, 10, colors.green, 6,0,0,2)
  552.     levelprogress = 13
  553.   elseif levelprogress == 13 then
  554.     createEnt(10, 5, colors.red, 1,1,0,1)
  555.     createEnt(20, 5, colors.red, 2,1,0,1)
  556.     createEnt(30, 5, colors.red, 3,1,0,1)
  557.     createEnt(40, 5, colors.red, 4,1,0,1)
  558.     createEnt(25, 10, colors.orange, 4,1,0,3)
  559.     levelprogress = 14
  560.   elseif levelprogress == 14 then
  561.     createEnt(25, 5, colors.red, 1,1,0,1)
  562.     levelprogress = 15
  563.   elseif levelprogress == 15 then
  564.     createEnt(10, 10, colors.orange, 1,1,0,3)
  565.     createEnt(20, 10, colors.orange, 2,1,0,3)
  566.     createEnt(30, 10, colors.orange, 3,1,0,3)
  567.     levelprogress = 16
  568.   elseif levelprogress == 16 then
  569.     createEnt(20, 10, colors.green, 1,0,0,2)
  570.     levelprogress = 17
  571.   elseif levelprogress == 17 then
  572.     createEnt(10, 5, colors.red, 1,1,0,1)
  573.     createEnt(20, 5, colors.red, 2,1,0,1)
  574.     createEnt(30, 5, colors.red, 3,1,0,1)
  575.     createEnt(40, 5, colors.red, 4,1,0,1)
  576.     createEnt(25, 10, colors.orange, 5,1,0,3)
  577.     createEnt(35, 10, colors.orange, 6,1,0,3)
  578.     levelprogress = 18
  579.   elseif levelprogress == 18 then
  580.     createEnt(20, 10, colors.green, 1,0,0,2)
  581.     levelprogress = 19
  582.   elseif levelprogress == 19 then
  583.     createEnt(10, 10, colors.orange, 1,1,0,3)
  584.     createEnt(20, 10, colors.orange, 2,1,0,3)
  585.     createEnt(30, 10, colors.orange, 3,1,0,3)
  586.     createEnt(40, 10, colors.orange, 4,1,0,3)
  587.     levelprogress = 20
  588.   elseif levelprogress == 20 then
  589.     endGame("Congratulations! You completed the campaign! Now try to beat your score, level up, or play unlimited waves!")
  590.     running = false
  591.   end
  592. end
  593.  
  594. tank()
  595. drawBg()
  596.   enemy()
  597.  
  598. function input()
  599. local event, key = os.pullEvent()
  600.   if event == "key" then
  601.     if key == keys.q then
  602.     running = false
  603.     elseif key == keys.w then
  604.       tankInfo.y = tankInfo.y - 1
  605.     elseif key == keys.s then
  606.       tankInfo.y = tankInfo.y + 1
  607.     elseif key == keys.a then
  608.       tankInfo.x = tankInfo.x - 1
  609.     elseif key == keys.d then
  610.       tankInfo.x = tankInfo.x + 1
  611.     elseif key == keys.up then
  612.       tankInfo.y = tankInfo.y - 1
  613.     elseif key == keys.down then
  614.       tankInfo.y = tankInfo.y + 1
  615.     elseif key == keys.left then
  616.       tankInfo.x = tankInfo.x - 1
  617.     elseif key == keys.right then
  618.       tankInfo.x = tankInfo.x + 1
  619.     elseif key == keys.space then
  620.       if tankInfo.ammo > 0 then
  621.         createBullets(tankInfo.x + 1, tankInfo.y - 1, 0, -1, tankBullet,0)
  622.         tankInfo.ammo = tankInfo.ammo - 1
  623.         lbullets = lbullets + 1
  624.       end
  625.       drawBg()
  626.       tank()
  627.         enemy()
  628.         updateBullets()
  629.         checkForCollison()
  630.         updateAmmo()
  631.     end
  632.     term.setBackgroundColor(colors.black)
  633.     term.setCursorPos(tankInfo.x, tankInfo.y)
  634.     term.clearLine()
  635.     term.setCursorPos(tankInfo.x, tankInfo.y + 1)
  636.     term.clearLine()
  637.     term.setCursorPos(tankInfo.x, tankInfo.y + 2)
  638.     term.clear()
  639.     tank()
  640.     drawBg()
  641.     if tankInfo.x == w - 3 then
  642.       tankInfo.x = 22
  643.       tankInfo.y = h - 5
  644.     elseif tankInfo.x == 5 then
  645.       tankInfo.x = 22
  646.       tankInfo.y = h - 5
  647.     elseif tankInfo.y == h - 3 then
  648.       tankInfo.x = 22
  649.       tankInfo.y = h - 5
  650.     elseif tankInfo.y == 1 then
  651.       tankInfo.x = 22
  652.       tankInfo.y = h - 5
  653.     end
  654.   elseif event == "timer" then
  655.     if key == gtId then
  656.       updateBullets()
  657.       updateEnt()
  658.       updateAmmo()
  659.       updateHealth()
  660.       checkForCollison()
  661.       gtId = os.startTimer(refresh)
  662.       drawBg()
  663.       for _, v in pairs(bullets) do
  664.         for i, k in pairs(ent) do
  665.         if #ent > 0 then
  666.           if v.x == k.x + 1 and v.y <= k.y then
  667.             score = score + 15
  668.             tankInfo.exp = tankInfo.exp + 3
  669.             table.remove(ent, i)
  670.             lenemies = lenemies + 1
  671.             if k.ID == 1 then
  672.               score = score + 10
  673.             elseif k.ID == 2 then
  674.               score = score + 15
  675.             elseif k.ID == 3 then
  676.               score = score + 20
  677.             end
  678.             break
  679.           end
  680.           if v.x >= k.x and v.x <= k.x + 2 and v.y <= k.y then
  681.             table.remove(ent, i)
  682.             lenemies = lenemies + 1
  683.             tankInfo.exp = tankInfo.exp + 1
  684.             if k.ID == 1 then
  685.               score = score + 10
  686.             elseif k.ID == 2 then
  687.               score = score + 15
  688.             elseif k.ID == 3 then
  689.               score = score + 20
  690.             end
  691.             break
  692.           end
  693.         end
  694.         end
  695.       end
  696.       if tankInfo.exp >= maxexp then
  697.         tankInfo.exp = 0
  698.         playerlevel = playerlevel + 1
  699.       end
  700.       if tankInfo.hp <= 0 then
  701.         running = false
  702.         endGame("You kind of got shot")
  703.       end
  704.         if tankInfo.ammo <= 3 then
  705.           if #ammopack == 0 then
  706.           xrand = math.random(7,47)
  707.           yrand = math.random(3,h-5)
  708.           arand = math.random(0,20)
  709.           if arand > 0 then
  710.             createAmmo(xrand, yrand, arand)
  711.           elseif arand == 0 then
  712.             running = false
  713.             endGame("You took all the bullets from your camp")
  714.           end
  715.           end
  716.         end
  717.     elseif key == gtId2 then
  718.       updateEnt2()
  719.       gtId2 = os.startTimer(brefresh)
  720.       if #ent <= 0 then
  721.         createNewLevel()
  722.       end
  723.     elseif key == gtId3 then
  724.       updateEnt3()
  725.       brand = math.random(0.10, 2.5)
  726.       gtId3 = os.startTimer(brand)
  727.     elseif key == gtId4 then
  728.       updateHealth()
  729.       if tankInfo.hp <= 5 then
  730.         chances = math.random(0, 50)
  731.         if #healthpack == 0 then
  732.           if chances < 15 then
  733.           xrand = math.random(7, 47)
  734.           yrand = math.random(3, (h - 5))
  735.           createHPack(xrand, yrand, 5)
  736.           end
  737.         end
  738.       end
  739.       gtId4 = os.startTimer(hrefresh)
  740.     end
  741.   end
  742. end
  743.  
  744. function updateBullets()
  745.   for _, v in pairs(bullets) do
  746.     v.x = v.x + v.xstep
  747.     v.y = v.y + v.ystep
  748.     for i, k in pairs(ent) do
  749.     if #ent > 0 then
  750.       if v.y == tankInfo.y and (v.x >= tankInfo.x and v.x <= tankInfo.x + 2) then
  751.         if tankInfo.hp > 0 then
  752.           tankInfo.hp = tankInfo.hp - v.dmg
  753.           break
  754.         elseif tankInfo.hp == 0 then
  755.           running = false
  756.           endGame("Your tank was obliterated")
  757.         end
  758.       end
  759.     end
  760.   end
  761. end
  762.  
  763.   local blistl = #bullets
  764.   for i = 1, blistl do
  765.     local v = bullets[i]
  766.     if v and (v.y < 1 or v.y > h or v.y > h - 4) then
  767.       table.remove(bullets, i)
  768.       blistl = blistl - 1
  769.       i = i - 1
  770.       break
  771.     end
  772.   end
  773. end
  774.  
  775. function enemyBullets(nr)
  776. local ents = ent[nr]
  777.     createBullets(ents.x + 1, ents.y, 0, 1, enemyBullet, 5)
  778. end
  779.  
  780. function enemy3Bullets(nr)
  781.   local ents = ent[nr]
  782.     createBullets(ents.x + 1, ents.y, 0, 1, ent3Bullet, 5)
  783. end
  784.  
  785. function moveEnemy1(nr, xparam)
  786.  
  787. local ents = ent[nr]
  788.  
  789.   ents.x = ents.x + ents.xstep
  790.   ents.y = ents.y + ents.ystep
  791.   if ents.x == w - 2 then
  792.     ents.xstep = -1
  793.     ents.ystep = 0
  794.     enemy()
  795.   elseif ents.x == xparam then
  796.     ents.xstep = 1
  797.     ents.ystep = 0
  798.   elseif (ents.y >= tankInfo.y and ents.y <= tankInfo.y + 2 and ents.x >= tankInfo.x and ents.x <= tankInfo.x + 2)
  799.    and (ents.y - 2 >= tankInfo.y and ents.y - 2 <= tankInfo.y + 2 and ents.x + 2 >= tankInfo.x and ents.x + 2 <= tankInfo.x + 2) then
  800.     running = false
  801.     endGame("Your tank perished")
  802.   end
  803. end
  804.  
  805.   while running do
  806.     input()
  807.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement