Advertisement
Fallstar

Untitled

Oct 19th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.66 KB | None | 0 0
  1. --Gamestates/Game.lua
  2. --by Fallstar
  3.  
  4. local Game = {}
  5. local Gui = require "Quickie"
  6.  
  7. function Game:enter()
  8.     Previous = "Gamestates/Menu"
  9. end
  10.  
  11. local foes = {}
  12. local nbFoes = 5 --Number of foes
  13. local won = false
  14. local turrets = {}
  15. local nbTurrets = 2
  16.  
  17.  
  18.  
  19. function Game:reset()
  20.     for i=0, nbFoes do
  21.         table.insert(foes, { x = i*20, y = 256, hp = 100})
  22.     end
  23. end
  24.  
  25.  
  26. function Game:init()
  27.     Game:reset()
  28. end
  29.  
  30. function Game:turrets()
  31.     for i=1, nbTurrets do
  32.         if love.mouse.isDown("l") then
  33.             table.insert(turrets, {x = love.mouse.getX()})
  34.         end
  35.     end
  36. end
  37.  
  38.  
  39. function Game:update(dt)
  40.    
  41.     if #turrets < nbTurrets then
  42.         Game:turrets()
  43.     elseif not won then
  44.         for i, foe in ipairs(foes) do
  45.             for j, turret in ipairs(turrets) do
  46.                 if foe.x > turret.x-50 and foe.x < turret.x+50 and i % #turret == j then                                    foe.hp =foe.hp-1
  47.                     if foe.hp <=0 then
  48.                         foe=nil
  49.                     end
  50.                     end
  51.             end        
  52.         end
  53.         foe.x = foe.x+1
  54.     elseif won then
  55.         Gui.group.push{grow = "down", pos = {50,5}}
  56.         Gui.Label{ text = "Bravo"}
  57.         Gui.group.pop{}
  58.     end
  59.    
  60.    
  61.     if table.getn(foes)==0 then
  62.         won=true
  63.     end
  64. end
  65.  
  66.  
  67.  
  68. function Game:draw()
  69.     love.graphics.setBackgroundColor(100, 050, 200)
  70.     for i, turret in ipairs(turrets) do
  71.         if turret then
  72.         love.graphics.setColor(255, 0, 0, 100)
  73.         love.graphics.rectangle("fill", turret.x-50, 0, 100, 600)
  74.         end
  75.     end
  76.     if not won then
  77.         for i, foe in ipairs(foes) do
  78.             love.graphics.setColor(0,0,0,255)
  79.             love.graphics.circle("fill", foe.x-(i*20), 300, 5, 100) --show foe i if it has hp  
  80.             love.graphics.print(foe.hp, foe.x-(i*20), 400) --shows hp
  81.         end
  82.     end
  83.     Gui.core.draw() --Draw Gui
  84. end
  85.  
  86. return Game
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement