haha guess who forgot to push
Before Width: | Height: | Size: 188 B |
Before Width: | Height: | Size: 180 B |
Before Width: | Height: | Size: 146 B |
Before Width: | Height: | Size: 146 B |
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 189 B |
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 184 B |
After Width: | Height: | Size: 182 B |
After Width: | Height: | Size: 188 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 180 B |
107
main.lua
|
@ -3,107 +3,30 @@ function love.load()
|
|||
love.graphics.setColor(1,1,1)
|
||||
love.keyboard.setKeyRepeat(true)
|
||||
love.graphics.setDefaultFilter("nearest") -- good pixel
|
||||
window_width = 600
|
||||
window_height = 600
|
||||
t = 0
|
||||
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)
|
||||
|
||||
windowWidth = 600
|
||||
windowHeight = 600
|
||||
currentMenu = 1
|
||||
MenuInit(currentMenu)
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
current_dt = dt
|
||||
|
||||
You:Input()
|
||||
for _, obj in pairs(List.Simulate) do
|
||||
obj:Step()
|
||||
if doStageStep == true then
|
||||
stageStep()
|
||||
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
|
||||
if currentMenu ~= nil
|
||||
and currentMenu > 0 then
|
||||
MenuStep(currentMenu)
|
||||
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
|
||||
t = t + dt
|
||||
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()
|
||||
if doStageDraw == true then
|
||||
stageDraw()
|
||||
end
|
||||
for _, enemy in pairs(List.Enemy) do
|
||||
if enemy.show_health == true then enemy:DrawHealth() end
|
||||
if currentMenu ~= nil
|
||||
and currentMenu > 0 then
|
||||
MenuDisplay(currentMenu)
|
||||
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
|
||||
--love.graphics.print(t, 10, 10)
|
||||
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)
|
||||
love.graphics.print(love.timer.getFPS(), 10, window_height-20)
|
||||
love.graphics.print(love.timer.getFPS(), 10, windowHeight-20)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
require "scripts/math"
|
||||
require "scripts/lists"
|
||||
require "scripts/score"
|
||||
require "scripts/animations"
|
||||
require "scripts/attack_patterns"
|
||||
require "scripts/entity"
|
||||
require "scripts/stage"
|
||||
require "scripts/menus"
|
||||
|
|
|
@ -29,6 +29,11 @@ Animation = {
|
|||
path = "assets/projectileBlueRocket",
|
||||
frames = 1,
|
||||
speed = 1
|
||||
},
|
||||
projectileCard = {
|
||||
path = "assets/projectileCard",
|
||||
frames = 8,
|
||||
speed = 1/24
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ AttackPattern.FixatedWeb = function(entity,t,a,b,c)
|
|||
hits = 1,
|
||||
moveSpeed = 4,
|
||||
moveSpeedIncrease = 0.001,
|
||||
moveHorizontalIncrease = 0.001,
|
||||
moveHorizontalIncrease = 0.00125,
|
||||
moveSpeedLimits = { min = 2, max = 4},
|
||||
animation = Animation.projectileGreen,
|
||||
animation = Animation.projectileCard,
|
||||
hostile = true,
|
||||
maximumTurnRate = 0.05
|
||||
}
|
||||
|
@ -41,9 +41,9 @@ AttackPattern.FixatedWeb = function(entity,t,a,b,c)
|
|||
hits = 1,
|
||||
moveSpeed = 4,
|
||||
moveSpeedIncrease = 0.001,
|
||||
moveHorizontalIncrease = -0.001,
|
||||
moveHorizontalIncrease = -0.00125,
|
||||
moveSpeedLimits = { min = 2, max = 4},
|
||||
animation = Animation.projectileGreen,
|
||||
animation = Animation.projectileCard,
|
||||
hostile = true,
|
||||
maximumTurnRate = 0.05
|
||||
}
|
||||
|
@ -67,7 +67,6 @@ AttackPattern.FixatedWeb = function(entity,t,a,b,c)
|
|||
math.rad(a *-math.cos( 5 )) + math.rad(90) + math.rad(40),
|
||||
b
|
||||
)
|
||||
|
||||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
|
@ -169,7 +168,7 @@ AttackPattern.DrowningBarrage = function(entity,t,a,b,c)
|
|||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(b *math.cos(t)) + GetAngle(
|
||||
math.rad(b *math.cos(t)) + GetAngleFromVector(
|
||||
target_x - entity.pos.x,
|
||||
target_y - entity.pos.y),
|
||||
BulletData
|
||||
|
@ -195,7 +194,7 @@ AttackPattern.ShotAtPlayerDouble = function(entity)
|
|||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(-10)*i + GetAngle(
|
||||
math.rad(-10)*i + GetAngleFromVector(
|
||||
target_x - entity.pos.x,
|
||||
target_y - entity.pos.y),
|
||||
BulletData
|
||||
|
@ -221,7 +220,7 @@ AttackPattern.ShotAtPlayerTriple = function(entity,t,a)
|
|||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(-15)*i + GetAngle(
|
||||
math.rad(-15)*i + GetAngleFromVector(
|
||||
target_x - entity.pos.x,
|
||||
target_y - entity.pos.y),
|
||||
BulletData
|
||||
|
|
|
@ -22,16 +22,18 @@ function Projectile:New(x,y,angle,data)
|
|||
o.moveHorizontal = 0
|
||||
o.moveVertical = 0
|
||||
-- lists
|
||||
o:AddList(List.Simulate)
|
||||
o:AddList("Simulate")
|
||||
|
||||
local friendly = data.friendly or false
|
||||
local hostile = data.hostile or false
|
||||
|
||||
if friendly == true then
|
||||
o:AddList(List.FriendlyBullet)
|
||||
o:AddList("FriendlyBullet")
|
||||
end
|
||||
if hostile == true then
|
||||
o:AddList(List.EnemyBullet)
|
||||
o:AddList("HostileBullet")
|
||||
o.grazeTimer = 0
|
||||
o.Grazed = false
|
||||
end
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
@ -55,6 +57,7 @@ function Projectile:Step()
|
|||
You.pos.y
|
||||
)
|
||||
|
||||
-- bends towards the player? owo
|
||||
self.pos.x = self.pos.x + move_x + self.maximumTurnRate * math.cos(self.angle)
|
||||
self.pos.y = self.pos.y + move_y + self.maximumTurnRate * math.sin(self.angle)
|
||||
|
||||
|
@ -63,18 +66,18 @@ function Projectile:Step()
|
|||
self.pos.y + move_y
|
||||
)
|
||||
|
||||
-- bends towards the player? owo
|
||||
|
||||
if self.pos.x < 0 or self.pos.x > window_width
|
||||
or self.pos.y < 0 or self.pos.y > window_height then
|
||||
self:RemoveList(List.Simulate)
|
||||
self:RemoveList(List.CollidesEnemies)
|
||||
-- if out of s screen, kill.
|
||||
if self.pos.x < 0 or self.pos.x > windowWidth
|
||||
or self.pos.y < 0 or self.pos.y > windowHeight then
|
||||
self:RemoveList("Simulate")
|
||||
self:RemoveList("EnemyBullet")
|
||||
self:RemoveList("FriendlyBullet")
|
||||
end
|
||||
end
|
||||
|
||||
function Projectile:Draw()
|
||||
self.animation:Animate()
|
||||
love.graphics.line(self.pos.x, self.pos.y, self.pos.x + 10*self.vel.x, self.pos.y + 10*self.vel.y)
|
||||
self.animation:Draw(
|
||||
self.pos.x,
|
||||
self.pos.y,
|
||||
|
@ -82,6 +85,7 @@ function Projectile:Draw()
|
|||
self.draw_scale,
|
||||
self.draw_scale
|
||||
)
|
||||
love.graphics.line(self.pos.x, self.pos.y, self.pos.x + 50*self.vel.x, self.pos.y + 50*self.vel.y)
|
||||
--[[love.graphics.draw(
|
||||
self.sprite,
|
||||
self.pos.x,
|
||||
|
|
|
@ -15,8 +15,8 @@ function Fang:New(x,y)
|
|||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
o:AddList(List.Simulate)
|
||||
o:AddList(List.Enemy)
|
||||
o:AddList("Simulate")
|
||||
o:AddList("Enemy")
|
||||
return o
|
||||
end
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ function Shooter:New(x,y)
|
|||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
o:AddList(List.Simulate)
|
||||
o:AddList(List.Enemy)
|
||||
o:AddList("Simulate")
|
||||
o:AddList("Enemy")
|
||||
o:ChangePattern(AttackPattern.DrowningBarrage)
|
||||
|
||||
return o
|
||||
|
|
|
@ -50,7 +50,7 @@ function Player:New(x,y)
|
|||
o.max_health = 100
|
||||
o.health = 100
|
||||
-- lists
|
||||
o:AddList(List.Simulate)
|
||||
o:AddList("Simulate")
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
@ -93,8 +93,8 @@ function Player:Input()
|
|||
end
|
||||
|
||||
-- Actually moving the player
|
||||
self.pos.x = math.min(math.max(self.pos.x + self.vel.x,self.hitbox),window_width - self.hitbox)
|
||||
self.pos.y = math.min(math.max(self.pos.y + self.vel.y,self.hitbox),window_height - self.hitbox)
|
||||
self.pos.x = math.min(math.max(self.pos.x + self.vel.x,self.hitbox),windowWidth - self.hitbox)
|
||||
self.pos.y = math.min(math.max(self.pos.y + self.vel.y,self.hitbox),windowHeight - self.hitbox)
|
||||
|
||||
-- Get Ready to shoot if triggered
|
||||
if self.shotTimer > 0 then self.shotTimer = self.shotTimer - current_dt end
|
||||
|
@ -103,7 +103,7 @@ function Player:Input()
|
|||
-- Shoot if ready and triggered
|
||||
if love.mouse.isDown(1) and self.shotTimer == 0 then
|
||||
local x, y = love.mouse.getPosition()
|
||||
Projectile:New(self.pos.x,self.pos.y,GetAngle(x - self.pos.x, y - self.pos.y), self.GunType[self.current_gun])
|
||||
Projectile:New(self.pos.x,self.pos.y,GetAngleFromVector(x - self.pos.x, y - self.pos.y), self.GunType[self.current_gun])
|
||||
self.shotTimer = self.GunType[self.current_gun].shotCooldown
|
||||
end
|
||||
end
|
||||
|
@ -120,7 +120,7 @@ function Player:Draw()
|
|||
love.graphics.circle("line", x, y, self.hitbox/2)
|
||||
|
||||
-- Draw Gun Name
|
||||
love.graphics.print("Current Gun: "..self.GunType[self.current_gun].name, 10, 35)
|
||||
--love.graphics.print("Current Gun: "..self.GunType[self.current_gun].name, 10, 35)
|
||||
|
||||
-- Draw Self
|
||||
if self.sprite ~= nil then
|
||||
|
|
|
@ -45,89 +45,52 @@ function Entity:DrawHealth()
|
|||
|
||||
end
|
||||
|
||||
function Entity:AddList(list)
|
||||
table.insert(list,self)
|
||||
function Entity:AddList( target)
|
||||
if List[target] == nil then List[target] = {} end
|
||||
table.insert(List[target],self)
|
||||
self.id[target] = #List[target]
|
||||
end
|
||||
|
||||
if list == List.Simulate then
|
||||
self.id.Simulate = #list
|
||||
elseif list == List.Enemy then
|
||||
self.id.Enemy = #list
|
||||
elseif list == List.EnemyBullet then
|
||||
self.id.EnemyBullet = #list
|
||||
elseif list == List.FriendlyBullet then
|
||||
self.id.FriendlyBullet = #list
|
||||
function Entity:RemoveList(target)
|
||||
if self.id[target] ~= nil then
|
||||
for _, e in pairs(List[target]) do
|
||||
if e.id[target] > self.id[target] then
|
||||
e.id[target] = e.id[target] - 1
|
||||
end
|
||||
end
|
||||
table.remove(List[target],self.id[target])
|
||||
end
|
||||
end
|
||||
|
||||
function Entity:CollisionWith(obj)
|
||||
if math.sqrt((obj.pos.x-self.pos.x)^2 + (obj.pos.y-self.pos.y)^2) < obj.hitbox + self.hitbox then
|
||||
function Entity:DistanceWith(obj, distance)
|
||||
if math.sqrt((obj.pos.x-self.pos.x)^2 + (obj.pos.y-self.pos.y)^2) < distance then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function Entity:RemoveList(list)
|
||||
if list == List.Simulate then
|
||||
for _, e in pairs(list) do
|
||||
if e.id.Simulate > self.id.Simulate then
|
||||
e.id.Simulate = e.id.Simulate - 1
|
||||
end
|
||||
end
|
||||
table.remove(list,self.id.Simulate)
|
||||
elseif list == List.Enemy then
|
||||
for _, e in pairs(list) do
|
||||
if e.id.Enemy > self.id.Enemy then
|
||||
e.id.Enemy = e.id.Enemy - 1
|
||||
end
|
||||
end
|
||||
table.remove(list,self.id.Enemy)
|
||||
elseif list == List.EnemyBullet then
|
||||
for _, e in pairs(list) do
|
||||
if e.id.EnemyBullet > self.id.EnemyBullet then
|
||||
e.id.EnemyBullet = e.id.EnemyBullet - 1
|
||||
end
|
||||
end
|
||||
table.remove(list,self.id.EnemyBullet)
|
||||
elseif list == List.FriendlyBullet then
|
||||
for _, e in pairs(list) do
|
||||
if e.id.FriendlyBullet > self.id.FriendlyBullet then
|
||||
e.id.FriendlyBullet = e.id.FriendlyBullet - 1
|
||||
end
|
||||
end
|
||||
table.remove(list,self.id.FriendlyBullet)
|
||||
function Entity:Kill()
|
||||
for target, _ in pairs(self.id) do
|
||||
self:RemoveList(target)
|
||||
end
|
||||
|
||||
self = nil
|
||||
end
|
||||
|
||||
function Entity:AngleTowards(x,y)
|
||||
target_x = x - self.pos.x
|
||||
target_y = y - self.pos.y
|
||||
|
||||
self.angle = GetAngle(target_x,target_y)
|
||||
self.angle = GetAngleFromVector(target_x,target_y)
|
||||
end
|
||||
|
||||
function Entity:Kill()
|
||||
if self.id.Simulate ~= nil then
|
||||
self:RemoveList(List.Simulate)
|
||||
end
|
||||
if self.id.Enemy ~= nil then
|
||||
self:RemoveList(List.Enemy)
|
||||
end
|
||||
if self.id.EnemyBullet ~= nil then
|
||||
self:RemoveList(List.EnemyBullet)
|
||||
end
|
||||
if self.id.FriendlyBullet ~= nil then
|
||||
self:RemoveList(List.FriendlyBullet)
|
||||
end
|
||||
|
||||
self = nil
|
||||
end
|
||||
|
||||
function Entity:MoveTowards(x,y,speed)
|
||||
target_x = x - self.pos.x
|
||||
target_y = y - self.pos.y
|
||||
|
||||
local angle = GetAngle(target_x,target_y)
|
||||
local angle = GetAngleFromVector(target_x,target_y)
|
||||
|
||||
if speed ~= 0 then
|
||||
if target_x ~= 0 then
|
||||
|
|
|
@ -1,12 +1,60 @@
|
|||
List = {}
|
||||
|
||||
-- list to simulate things (draw, step, move)
|
||||
-- Gameplay lists
|
||||
List.Simulate = {}
|
||||
|
||||
-- collide lists
|
||||
List.Enemy = {}
|
||||
List.EnemyBullet = {}
|
||||
List.FriendlyBullet = {}
|
||||
|
||||
-- Animations
|
||||
List.AnimationContainers = {}
|
||||
|
||||
-- UI Elements
|
||||
List.UIElement = {}
|
||||
|
||||
|
||||
--[[
|
||||
function AddToList(self, target) -- object where to store id, string name.
|
||||
table.insert(List[target],self)
|
||||
self.id[target] = #list
|
||||
end
|
||||
|
||||
function RemoveFromList(self, list)
|
||||
end
|
||||
|
||||
for _, value in pairs(self.id) do
|
||||
RemoveFromList(self,value)
|
||||
|
||||
|
||||
--[[function Entity:RemoveList(list)
|
||||
if list == List.Simulate then
|
||||
for _, e in pairs(list) do
|
||||
if e.id.Simulate > self.id.Simulate then
|
||||
e.id.Simulate = e.id.Simulate - 1
|
||||
end
|
||||
end
|
||||
table.remove(list,self.id.Simulate)
|
||||
elseif list == List.Enemy then
|
||||
for _, e in pairs(list) do
|
||||
if e.id.Enemy > self.id.Enemy then
|
||||
e.id.Enemy = e.id.Enemy - 1
|
||||
end
|
||||
end
|
||||
table.remove(list,self.id.Enemy)
|
||||
elseif list == List.EnemyBullet then
|
||||
for _, e in pairs(list) do
|
||||
if e.id.EnemyBullet > self.id.EnemyBullet then
|
||||
e.id.EnemyBullet = e.id.EnemyBullet - 1
|
||||
end
|
||||
end
|
||||
table.remove(list,self.id.EnemyBullet)
|
||||
elseif list == List.FriendlyBullet then
|
||||
for _, e in pairs(list) do
|
||||
if e.id.FriendlyBullet > self.id.FriendlyBullet then
|
||||
e.id.FriendlyBullet = e.id.FriendlyBullet - 1
|
||||
end
|
||||
end
|
||||
table.remove(list,self.id.FriendlyBullet)
|
||||
end
|
||||
end
|
||||
]]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function GetAngle(x,y)
|
||||
function GetAngleFromVector(x,y)
|
||||
local reduce = 0
|
||||
if x < 0 then
|
||||
reduce = math.rad(180)
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
require "scripts/ui/button"
|
||||
|
||||
function MenuStep(menu)
|
||||
-- first get mouse
|
||||
local mouse_x, mouse_y = love.mouse.getPosition()
|
||||
for _, element in pairs(List.UIElement) do
|
||||
if element.type == "Button" then
|
||||
element:checkMouse(mouse_x, mouse_y)
|
||||
end
|
||||
end
|
||||
if menu == 1 then
|
||||
if M_game_start:getVariable() == true then
|
||||
MenuExit(menu,0)
|
||||
stageStart()
|
||||
elseif M_exit:getVariable() == true then
|
||||
love.event.quit()
|
||||
end
|
||||
else
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function MenuExit(from,to)
|
||||
for _, element in pairs(List.UIElement) do
|
||||
element = nil
|
||||
end
|
||||
List.UIElement = {}
|
||||
if from == 1 then
|
||||
M_game_start = nil
|
||||
M_exit = nil
|
||||
end
|
||||
currentMenu = to or 0
|
||||
end
|
||||
|
||||
function MenuDisplay(menu)
|
||||
for _, element in pairs(List.UIElement) do
|
||||
element:Draw()
|
||||
end
|
||||
if menu == 1 then
|
||||
love.graphics.print(tostring(M_exit[1]), windowWidth-100, windowHeight-10)
|
||||
else
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function MenuInit(menu)
|
||||
-- main menu
|
||||
if menu == 1 then
|
||||
-- elements
|
||||
M_game_start = interfaceButton:New(
|
||||
windowWidth/2,
|
||||
2/10*windowHeight,
|
||||
windowWidth/6,
|
||||
windowWidth/12,
|
||||
{false,true},
|
||||
1,
|
||||
{
|
||||
text = "Press here to start",
|
||||
color = {0,0,0.5},
|
||||
color2 = {1,1,1},
|
||||
alpha = 1,
|
||||
scale = 1,
|
||||
scale_x = 1,
|
||||
scale_y = 1
|
||||
})
|
||||
M_exit = interfaceButton:New(
|
||||
windowWidth/2,
|
||||
500,
|
||||
windowWidth/6,
|
||||
windowWidth/12,
|
||||
{false,true},
|
||||
1,
|
||||
{
|
||||
color = {1,0,0.5},
|
||||
color2 = {1,1,1},
|
||||
alpha = 1,
|
||||
scale = 1,
|
||||
scale_x = 1,
|
||||
scale_y = 1
|
||||
})
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
function AddScore()
|
||||
if Score-ScoreShown > 150 then
|
||||
ScoreShown = ScoreShown + 150 --math.floor(1/5 * (Score - ScoreShown))
|
||||
else
|
||||
ScoreShown = math.floor(Score)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,118 @@
|
|||
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
|
|
@ -0,0 +1,106 @@
|
|||
interfaceButton = {type = "Button"}
|
||||
|
||||
-- centered buttons
|
||||
function interfaceButton:New(x,y,w,h,table_values,value,style)
|
||||
|
||||
o = {}
|
||||
o.pos = {
|
||||
x = x,
|
||||
y = y
|
||||
}
|
||||
o.size = {
|
||||
w = w,
|
||||
h = h
|
||||
|
||||
}
|
||||
|
||||
o.values = table_values or {false,true}
|
||||
o.value = value or 1
|
||||
o.target_variable = o.values[o.value]
|
||||
|
||||
o.clicked = false
|
||||
|
||||
o.style = {
|
||||
text = style.text or nil,
|
||||
color = style.color or {1,1,1},
|
||||
color2 = style.color2 or {0,0,0},
|
||||
--color3 = style.color3 or style.color2 or {0,0,0},
|
||||
alpha = style.alpha or 1,
|
||||
scale = style.scale or 1,
|
||||
scale_x = style.scale_x or 1,
|
||||
scale_y = style.scale_y or 1,
|
||||
scale_proportion = 1
|
||||
}
|
||||
|
||||
o.style.unselected = {
|
||||
scale_proportion = o.style.scale_proportion
|
||||
}
|
||||
|
||||
o.style.selected = {
|
||||
scale_proportion = 1.5
|
||||
}
|
||||
|
||||
|
||||
AddElement(o)
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
function interfaceButton:getVariable()
|
||||
return self.target_variable
|
||||
end
|
||||
function AddElement(self)
|
||||
table.insert(List.UIElement,self)
|
||||
|
||||
self.id = #List.UIElement
|
||||
end
|
||||
|
||||
function interfaceButton:checkMouse(mouse_x, mouse_y)
|
||||
if self.clicked == false
|
||||
and mouse_x < self.pos.x + self.size.w/2
|
||||
and mouse_x > self.pos.x - self.size.w/2
|
||||
and mouse_y < self.pos.y + self.size.h/2
|
||||
and mouse_y > self.pos.y - self.size.h/2 then
|
||||
o.style.scale_proportion = o.style.selected.scale_proportion
|
||||
if love.mouse.isDown(1) then
|
||||
self.clicked = true
|
||||
self.value = self.value + 1
|
||||
if self.value > #self.values then
|
||||
self.value = 1
|
||||
end
|
||||
self.target_variable = self.values[self.value]
|
||||
end
|
||||
else
|
||||
o.style.scale_proportion = o.style.unselected.scale_proportion
|
||||
self.clicked = false
|
||||
end
|
||||
end
|
||||
|
||||
function interfaceButton:Draw()
|
||||
local c1, c2, c3, a = love.graphics.getColor()
|
||||
|
||||
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)
|
||||
love.graphics.rectangle(
|
||||
"fill",
|
||||
self.pos.x-(self.size.w/2)*self.style.scale_x*self.style.scale_proportion,
|
||||
self.pos.y-(self.size.h/2)*self.style.scale_y*self.style.scale_proportion,
|
||||
self.size.w *self.style.scale_x*self.style.scale_proportion,
|
||||
self.size.h *self.style.scale_y*self.style.scale_proportion)
|
||||
love.graphics.setColor(self.style.color2[1],self.style.color2[2],self.style.color2[3],self.style.alpha)
|
||||
love.graphics.rectangle(
|
||||
"line",
|
||||
self.pos.x-(self.size.w/2)*self.style.scale_x*self.style.scale_proportion,
|
||||
self.pos.y-(self.size.h/2)*self.style.scale_y*self.style.scale_proportion,
|
||||
self.size.w *self.style.scale_x*self.style.scale_proportion,
|
||||
self.size.h *self.style.scale_y*self.style.scale_proportion)
|
||||
|
||||
if self.style.text ~= nil then
|
||||
love.graphics.print(self.style.text,self.pos.x,self.pos.y)
|
||||
else
|
||||
love.graphics.print(tostring(self.target_variable),self.pos.x,self.pos.y)
|
||||
end
|
||||
love.graphics.setColor(c1,c2,c3,a)
|
||||
end
|