ZLP1/main.lua

110 lines
2.7 KiB
Lua
Raw Normal View History

2021-12-31 01:46:21 +00:00
function love.load()
require "scripts"
love.graphics.setColor(1,1,1)
love.keyboard.setKeyRepeat(true)
love.graphics.setDefaultFilter("nearest") -- good pixel
window_width = 600
window_height = 600
2021-12-31 11:21:48 +00:00
t = 0
2021-12-31 01:46:21 +00:00
TimeDone = false
BackgroundColor = {0,0,0}
BackgroundTimer = 0
BackgroundPeriod = 0.1
EnemyTimer = 0
EnemyPeriod = 0.8
You = Player:New(1/2*window_width,4/5*window_height)
end
function love.update(dt)
current_dt = dt
2021-12-31 11:21:48 +00:00
You:Input()
2021-12-31 01:46:21 +00:00
for _, obj in pairs(List.Simulate) do
obj:Step()
end
for _, bullet in pairs(List.FriendlyBullet) do
for _, enemy in pairs(List.Enemy) do
if bullet:CollisionWith(enemy) then
if bullet.hits > 0 then
enemy:Damage(bullet.damage)
bullet.hits = bullet.hits - 1
if bullet.hits <= 0 then
bullet:Kill()
end
end
end
end
end
for _, bullet in pairs(List.EnemyBullet) do
if bullet:CollisionWith(You) then
if bullet.hits > 0 then
You:Damage(bullet.damage)
bullet.hits = bullet.hits - 1
if bullet.hits <= 0 then
bullet:Kill()
end
end
end
end
if TimeDone == false then
2021-12-31 11:21:48 +00:00
t = t + dt
2021-12-31 01:46:21 +00:00
EnemyTimer = EnemyTimer + dt
BackgroundTimer = BackgroundTimer + dt
end
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*window_width,1/5*window_height)
else
local rand_x = math.random(-10,10)
local rand_y = math.random(-10,10)
local x = Fang:New(window_width/2+rand_x,window_height/2+rand_y)
end
end
end
end
function love.keypressed(key)
end
function love.draw()
love.graphics.setColor(BackgroundColor)
love.graphics.rectangle("fill",0,0,window_width,window_height)
love.graphics.setColor(1,1,1)
You:Draw()
for _, obj in pairs(List.Simulate) do
obj:Draw()
end
for _, enemy in pairs(List.Enemy) do
if enemy.show_health == true then enemy:DrawHealth() end
end
local width = You.max_health*3
local height = 20
love.graphics.setColor(1,1,1)
love.graphics.rectangle("fill",20,10,width, height)
love.graphics.setColor(0,1,0)
love.graphics.rectangle("fill",20+1,10+1,You.health/You.max_health*(width)-2, height-2)
love.graphics.setColor(1,1,1)
love.graphics.line(0,1/5*window_height,window_height,1/5*window_height)
love.graphics.rectangle("line",0,0,window_width,window_height)
-- overlay
2021-12-31 11:21:48 +00:00
--love.graphics.print(t, 10, 10)
2021-12-31 01:46:21 +00:00
love.graphics.print(BackgroundTimer, window_width-100, 10)
love.graphics.print(BackgroundPeriod, window_width-100, 20)
love.graphics.print(#List.Simulate, window_width-100, window_height-10)
2021-12-31 11:21:48 +00:00
love.graphics.print(love.timer.getFPS(), 10, window_height-20)
2021-12-31 01:46:21 +00:00
end