Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Gamestates/Game.lua
- --by Fallstar
- local Game = {}
- local Gui = require "Quickie"
- function Game:enter()
- Previous = "Gamestates/Menu"
- end
- local foes = {}
- local nbFoes = 5 --Number of foes
- local won = false
- local turrets = {}
- local nbTurrets = 4
- local deadFoes = 0
- function Game:reset()
- for i=1, nbFoes do
- table.insert(foes, { x = -i*20, y = 256, hp = 100})
- end
- end
- function Game:init()
- Game:reset()
- end
- function Game:mousepressed(x, y, button)
- if #turrets < nbTurrets then
- table.insert(turrets, { x = x } )
- end
- end
- function Game:update(dt)
- if not won and #turrets==nbTurrets then
- for i, foe in ipairs(foes) do
- for j, turret in ipairs(turrets) do
- if foe and foe.x > turret.x-50 and foe.x < turret.x+51 and i % #turrets == j-1 then
- foe.hp =foe.hp-1
- if foe.hp <=0 then
- foes[i]=false
- end
- end
- end
- if foe then
- foe.x = foe.x+1
- end
- end
- elseif won then
- Gui.group.push{grow = "down", pos = {50,5}}
- Gui.Label{ text = "Bravo"}
- Gui.group.pop{}
- end
- if Game:tableSize(foes)==0 then
- won=true
- end
- end
- function Game:tableSize(tab)
- local cpt=0
- for i, val in ipairs(tab) do
- if val then
- cpt=cpt+1
- end
- end
- return cpt
- end
- function Game:draw()
- love.graphics.setBackgroundColor(100, 050, 200)
- for i, turret in ipairs(turrets) do
- if turret then
- love.graphics.setColor(255, 0, 0, 100)
- love.graphics.rectangle("fill", turret.x-50, 0, 100, 600)
- end
- end
- if not won then
- for i, foe in ipairs(foes) do
- if foe then
- love.graphics.setColor(0,0,0,255)
- love.graphics.circle("fill", foe.x, 300, 5, 100) --show foe i if it has hp
- love.graphics.print(foe.hp, foe.x, 400) --shows hp
- end
- love.graphics.print(Game:tableSize(foes), 300, 500)
- end
- end
- Gui.core.draw() --Draw Gui
- end
- return Game
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement