ZLP1/scripts/stage.lua

119 lines
2.9 KiB
Lua

function stageStart()
doStageStep = true
doStageDraw = true
EnemyTimer = 0
EnemyPeriod = 0.8
Score = 0
ScoreShown = 0
t = 0
You = Player:New(1/2*windowWidth,4/5*windowHeight)
end
function stageStep()
-- [PLAYER STEP]
You:Input()
-- [WORLD STEP]
-- first, simulate basic interaction
for _, obj in pairs(List.Simulate) do
obj:Step()
end
-- develop extra interactions:
-- 1. friendly bullets
for _, bullet in pairs(List.FriendlyBullet) do
for _, enemy in pairs(List.Enemy) do
if bullet:DistanceWith(enemy, enemy.hitbox + bullet.hitbox) then
if bullet.hits > 0 then
enemy:Damage(bullet.damage)
Score = Score +bullet.damage
bullet.hits = bullet.hits - 1
if bullet.hits <= 0 then
bullet:Kill()
end
end
end
end
end
-- 2. ememy bullets
for _, bullet in pairs(List.EnemyBullet) do
if bullet:DistanceWith(You, You.hitbox + bullet.hitbox) then
if bullet.hits > 0 then
--You:Damage(bullet.damage)
bullet.hits = bullet.hits - 1
if bullet.hits <= 0 then
bullet:Kill()
end
end
else
if bullet:DistanceWith(You, 200) then
bullet.grazeTimer = bullet.grazeTimer + 1
if bullet.grazeTimer > 30
and bullet.Grazed ~= true then
--Score = Score +3
bullet.Grazed = true
end
else
bullet.grazeTimer = 0
end
end
end
for _, bullet in pairs(List.EnemyBullet) do
if love.keyboard.isDown("lshift") then
bullet:Kill()
end
end
-- [POST WORLD STEP]
-- update shown score
AddScore()
-- if game is not paused
t = t + current_dt
EnemyTimer = EnemyTimer + current_dt
if EnemyTimer >= 0 then --EnemyPeriod then
--EnemyTimer = EnemyTimer - EnemyPeriod
EnemyTimer = -1000000000000
for i=1, 1 do
local rand = 1 --math.random(10)
if rand == 1 then
local rand_x = math.random(-100,100)
local rand_y = math.random(-100,100)
local x = Shooter:New(1/2*windowWidth,1/5*windowHeight)
else
local rand_x = math.random(-10,10)
local rand_y = math.random(-10,10)
local x = Fang:New(windowWidth/2+rand_x,windowHeight/2+rand_y)
end
end
end
end
function stageDraw()
--[GAME WORLD]
-- draw background (unimplemented)
-- draw objects
for _, obj in pairs(List.Simulate) do
obj:Draw()
end
--[HEADS UP DISPLAY (HUD)]
-- show enemies healthbars
for _, enemy in pairs(List.Enemy) do
if enemy.show_health == true then enemy:DrawHealth() end
end
-- show recollection zone
love.graphics.line(0,1/5*windowHeight,windowHeight,1/5*windowHeight)
-- show game area
love.graphics.rectangle("line",0,0,windowWidth,windowHeight)
-- show score
love.graphics.print(ScoreShown, 10, 60)
--[DEBUGGING]
love.graphics.print(#List.Simulate, windowWidth-100, windowHeight-10)
end