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 = 2
- function Game:reset()
- for i=0, nbFoes do
- table.insert(foes, { x = i*20, y = 256, hp = 100})
- end
- end
- function Game:init()
- Game:reset()
- end
- function Game:turrets()
- for i=1, nbTurrets do
- if love.mouse.isDown("l") then
- table.insert(turrets, {x = love.mouse.getX()})
- end
- end
- end
- function Game:update(dt)
- if #turrets < nbTurrets then
- Game:turrets()
- elseif not won then
- for i, foe in ipairs(foes) do
- for j, turret in ipairs(turrets) do
- if foe.x > turret.x-50 and foe.x < turret.x+50 and i % #turret == j then foe.hp =foe.hp-1
- if foe.hp <=0 then
- foe=nil
- end
- end
- end
- end
- foe.x = foe.x+1
- elseif won then
- Gui.group.push{grow = "down", pos = {50,5}}
- Gui.Label{ text = "Bravo"}
- Gui.group.pop{}
- end
- if table.getn(foes)==0 then
- won=true
- end
- 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
- love.graphics.setColor(0,0,0,255)
- love.graphics.circle("fill", foe.x-(i*20), 300, 5, 100) --show foe i if it has hp
- love.graphics.print(foe.hp, foe.x-(i*20), 400) --shows hp
- end
- end
- Gui.core.draw() --Draw Gui
- end
- return Game
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement