Added comments, (some) cleanup
After Width: | Height: | Size: 188 B |
After Width: | Height: | Size: 180 B |
After Width: | Height: | Size: 146 B |
After Width: | Height: | Size: 146 B |
After Width: | Height: | Size: 188 B |
After Width: | Height: | Size: 180 B |
After Width: | Height: | Size: 146 B |
After Width: | Height: | Size: 172 B |
10
main.lua
|
@ -5,7 +5,7 @@ function love.load()
|
|||
love.graphics.setDefaultFilter("nearest") -- good pixel
|
||||
window_width = 600
|
||||
window_height = 600
|
||||
Time = 0
|
||||
t = 0
|
||||
TimeDone = false
|
||||
BackgroundColor = {0,0,0}
|
||||
BackgroundTimer = 0
|
||||
|
@ -18,8 +18,8 @@ end
|
|||
|
||||
function love.update(dt)
|
||||
current_dt = dt
|
||||
You:Input()
|
||||
|
||||
You:Input()
|
||||
for _, obj in pairs(List.Simulate) do
|
||||
obj:Step()
|
||||
end
|
||||
|
@ -51,7 +51,7 @@ function love.update(dt)
|
|||
end
|
||||
|
||||
if TimeDone == false then
|
||||
Time = Time + dt
|
||||
t = t + dt
|
||||
EnemyTimer = EnemyTimer + dt
|
||||
BackgroundTimer = BackgroundTimer + dt
|
||||
end
|
||||
|
@ -101,9 +101,9 @@ function love.draw()
|
|||
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(Time, 10, 10)
|
||||
--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(current_dt, 10, window_height-10)
|
||||
love.graphics.print(love.timer.getFPS(), 10, window_height-20)
|
||||
end
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
AttackPattern = {}
|
||||
|
||||
AttackPattern.Wait = function(entity,t,a,b,c)
|
||||
entity.patternTime = 2
|
||||
entity.patternTime = 0.75
|
||||
entity.nextPattern = AttackPattern.PressureWebOfLies
|
||||
|
||||
end
|
||||
|
||||
AttackPattern.PressureWebOfLies = function(entity,t,a,b,c)
|
||||
if t % 2 == 0 then AttackPattern.FixatedWeb(entity,t,a,b,c) end
|
||||
|
||||
if t % 10 > 7 then AttackPattern.ShotAtPlayerTriple(entity,t,5) end
|
||||
if t % 50 < 5 then AttackPattern.DrowningBarrage(entity,t,a,b,c) end
|
||||
if t % 10 < 4 then AttackPattern.ShotAtPlayerTriple(entity,t,5) end
|
||||
entity.shotTimer = 0.05
|
||||
entity.patternTime = 10
|
||||
entity.patternTime = 4
|
||||
entity.nextPattern = AttackPattern.Wait
|
||||
end
|
||||
|
||||
|
@ -23,46 +23,57 @@ AttackPattern.MortalDrowningBarrage = function(entity,t,a,b,c)
|
|||
end
|
||||
|
||||
AttackPattern.FixatedWeb = function(entity,t,a,b,c)
|
||||
local BulletDataLeft = {
|
||||
|
||||
-- BULLETS DATA
|
||||
b = b or {
|
||||
damage = 3,
|
||||
hits = 1,
|
||||
moveSpeed = 7,
|
||||
moveSpeedIncrease = 0.1,
|
||||
moveSpeed = 4,
|
||||
moveSpeedIncrease = 0.001,
|
||||
moveHorizontalIncrease = 0.001,
|
||||
moveSpeedValues = { min = 2, max = 4},
|
||||
moveSpeedLimits = { min = 2, max = 4},
|
||||
animation = Animation.projectileGreen,
|
||||
hostile = true
|
||||
hostile = true,
|
||||
maximumTurnRate = 0.05
|
||||
}
|
||||
local BulletDataRight = {
|
||||
c = c or {
|
||||
damage = 3,
|
||||
hits = 1,
|
||||
moveSpeed = 7,
|
||||
moveSpeedIncrease = 0.1,
|
||||
moveSpeed = 4,
|
||||
moveSpeedIncrease = 0.001,
|
||||
moveHorizontalIncrease = -0.001,
|
||||
moveSpeedValues = { min = 2, max = 4},
|
||||
moveSpeedLimits = { min = 2, max = 4},
|
||||
animation = Animation.projectileGreen,
|
||||
hostile = true
|
||||
hostile = true,
|
||||
maximumTurnRate = 0.05
|
||||
}
|
||||
|
||||
|
||||
-- Initialization if not initialized
|
||||
local t = t or 0
|
||||
if a == nil then
|
||||
a = -10
|
||||
end
|
||||
gunBullet:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(a *-math.cos( 5 )) + math.rad(90) + math.rad(40) --[[GetAngle(
|
||||
target_x - entity.pos.x,
|
||||
target_y - entity.pos.y)]],
|
||||
BulletDataLeft
|
||||
)
|
||||
gunBullet:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(a *math.cos( 5 )) + math.rad(90) - math.rad(40) --[[GetAngle(
|
||||
target_x - entity.pos.x,
|
||||
target_y - entity.pos.y)]],
|
||||
BulletDataRight
|
||||
)
|
||||
|
||||
if t % 40 < 20 then
|
||||
b.moveHorizontalIncrease = -b.moveHorizontalIncrease
|
||||
c.moveHorizontalIncrease = -c.moveHorizontalIncrease
|
||||
end
|
||||
|
||||
-- Bullet Generation
|
||||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(a *-math.cos( 5 )) + math.rad(90) + math.rad(40),
|
||||
b
|
||||
)
|
||||
|
||||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(a *math.cos( 5 )) + math.rad(90) - math.rad(40),
|
||||
c
|
||||
)
|
||||
entity.patternTime = 4
|
||||
entity.shotTimer = 0.3
|
||||
entity.nextPattern = AttackPattern.FixatedWeb
|
||||
|
@ -81,9 +92,9 @@ AttackPattern.TwinRays = function(entity,t,a,b,c)
|
|||
local BulletDataRed = {
|
||||
damage = 3,
|
||||
hits = 1,
|
||||
moveSpeed = 3.5,
|
||||
moveSpeed = 2,
|
||||
moveSpeedIncrease = -0.05,
|
||||
moveSpeedValues = { min = 2, max = 4},
|
||||
moveSpeedLimits = { min = 2, max = 4},
|
||||
animation = Animation.projectileRed,
|
||||
hostile = true
|
||||
}
|
||||
|
@ -92,14 +103,14 @@ AttackPattern.TwinRays = function(entity,t,a,b,c)
|
|||
hits = 1,
|
||||
moveSpeed = 3.5,
|
||||
moveSpeedIncrease = -0.05,
|
||||
moveSpeedValues = { min = 2, max = 4},
|
||||
moveSpeedLimits = { min = 2, max = 4},
|
||||
animation = Animation.projectileBlue,
|
||||
hostile = true
|
||||
}
|
||||
local target_x = You.pos.x
|
||||
local target_y = You.pos.y
|
||||
for i=-1, 1 do
|
||||
gunBullet:New(
|
||||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(a *math.cos(t/5 )) + math.rad(90) + math.rad(45)* i --[[GetAngle(
|
||||
|
@ -107,7 +118,7 @@ AttackPattern.TwinRays = function(entity,t,a,b,c)
|
|||
target_y - entity.pos.y)]],
|
||||
BulletDataRed
|
||||
)
|
||||
gunBullet:New(
|
||||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(a *-math.cos(t/5 )) + math.rad(90) + math.rad(45)* i --[[GetAngle(
|
||||
|
@ -147,14 +158,15 @@ AttackPattern.DrowningBarrage = function(entity,t,a,b,c)
|
|||
shotCooldown = 0.05,
|
||||
damage = 3,
|
||||
hits = 1,
|
||||
moveSpeed = 3.5,
|
||||
moveSpeed = 2.5,
|
||||
animation = Animation.projectileRed,
|
||||
hostile = true
|
||||
hostile = true,
|
||||
maximumTurnRate = 0.5
|
||||
}
|
||||
local target_x = You.pos.x
|
||||
local target_y = You.pos.y
|
||||
entity.shotTimer = BulletData.shotCooldown
|
||||
gunBullet:New(
|
||||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(b *math.cos(t)) + GetAngle(
|
||||
|
@ -180,7 +192,7 @@ AttackPattern.ShotAtPlayerDouble = function(entity)
|
|||
entity.shotTimer = BulletData.shotCooldown
|
||||
for i=-1, 1 do
|
||||
if i ~= 0 then
|
||||
gunBullet:New(
|
||||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(-10)*i + GetAngle(
|
||||
|
@ -199,13 +211,14 @@ AttackPattern.ShotAtPlayerTriple = function(entity,t,a)
|
|||
hits = 1,
|
||||
moveSpeed = a,
|
||||
animation = Animation.projectileBlue,
|
||||
hostile = true
|
||||
hostile = true,
|
||||
maximumTurnRate = 0.2
|
||||
}
|
||||
local target_x = You.pos.x
|
||||
local target_y = You.pos.y
|
||||
entity.shotTimer = BulletData.shotCooldown
|
||||
for i=-1, 1 do
|
||||
gunBullet:New(
|
||||
Projectile:New(
|
||||
entity.pos.x,
|
||||
entity.pos.y,
|
||||
math.rad(-15)*i + GetAngle(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
gunBullet = Entity:New(x,y)
|
||||
Projectile = Entity:New(x,y)
|
||||
|
||||
function gunBullet:New(x,y,angle,data)
|
||||
function Projectile:New(x,y,angle,data)
|
||||
local o = Entity:New(x,y,angle)
|
||||
|
||||
o.target = {}
|
||||
|
@ -10,12 +10,15 @@ function gunBullet:New(x,y,angle,data)
|
|||
|
||||
o.hits = data.hits
|
||||
o.damage = data.damage
|
||||
-- i guess damage is useless to the player but maybe there's stuff that has hp? like obstacles
|
||||
o.animation = AnimationContainer:New(data.animation)
|
||||
|
||||
o.moveSpeed = data.moveSpeed
|
||||
o.moveSpeedValues = data.moveSpeedValues or { min = 0, max = 100}
|
||||
o.moveSpeedLimits = data.moveSpeedLimits or { min = 0, max = 100}
|
||||
o.moveSpeedIncrease = data.moveSpeedIncrease or 0
|
||||
o.moveHorizontalIncrease = data.moveHorizontalIncrease or 0
|
||||
o.moveVerticalIncrease = data.moveVerticalIncrease or 0
|
||||
o.maximumTurnRate = data.maximumTurnRate or 0
|
||||
o.moveHorizontal = 0
|
||||
o.moveVertical = 0
|
||||
-- lists
|
||||
|
@ -35,25 +38,33 @@ function gunBullet:New(x,y,angle,data)
|
|||
return o
|
||||
end
|
||||
|
||||
function gunBullet:Step()
|
||||
function Projectile:Step()
|
||||
|
||||
self.moveSpeed = self.moveSpeed + self.moveSpeedIncrease
|
||||
self.moveSpeed = math.max(self.moveSpeedValues.min,self.moveSpeed)
|
||||
self.moveSpeed = math.min(self.moveSpeedValues.max,self.moveSpeed)
|
||||
self.moveSpeed = math.max(self.moveSpeedLimits.min,self.moveSpeed)
|
||||
self.moveSpeed = math.min(self.moveSpeedLimits.max,self.moveSpeed)
|
||||
|
||||
self.moveHorizontal = self.moveHorizontal + self.moveHorizontalIncrease
|
||||
self.moveVertical = self.moveVertical + self.moveVerticalIncrease
|
||||
|
||||
local move_x = (self.moveSpeed) * math.cos(self.angle) + self.moveHorizontal
|
||||
local move_y = (self.moveSpeed) * math.sin(self.angle) + self.moveVertical
|
||||
self.pos.x = self.pos.x + move_x
|
||||
self.pos.y = self.pos.y + move_y
|
||||
|
||||
self:AngleTowards(
|
||||
You.pos.x,
|
||||
You.pos.y
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
self:AngleTowards(
|
||||
self.pos.x + move_x,
|
||||
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)
|
||||
|
@ -61,7 +72,7 @@ function gunBullet:Step()
|
|||
end
|
||||
end
|
||||
|
||||
function gunBullet:Draw()
|
||||
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(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
Player = Entity:New(x,y)
|
||||
|
||||
-- Player Gun Types
|
||||
Player.GunType = {
|
||||
{
|
||||
name = "Plasma Machine Gun",
|
||||
|
@ -30,11 +31,13 @@ Player.GunType = {
|
|||
}
|
||||
}
|
||||
|
||||
-- Player Builder
|
||||
function Player:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
o.moveSpeed = 3
|
||||
o.hitbox = 10
|
||||
o.moveSpeedFocused = 2
|
||||
o.hitbox = 5
|
||||
o.sprite = love.graphics.newImage("assets/heart.png")
|
||||
o.draw_scale = 3
|
||||
|
||||
|
@ -54,48 +57,54 @@ function Player:New(x,y)
|
|||
return o
|
||||
end
|
||||
|
||||
-- Function to get the player input
|
||||
function Player:Input()
|
||||
if self.sprite ~= nil then
|
||||
-- gun control
|
||||
if love.keyboard.isDown("q") then self.gunSwitchTimer = self.gunSwitchTimer - current_dt
|
||||
elseif love.keyboard.isDown("e") then self.gunSwitchTimer = self.gunSwitchTimer + current_dt
|
||||
else self.gunSwitchTimer = 0
|
||||
end
|
||||
|
||||
if math.abs(self.gunSwitchTimer) > self.gunSwitchTime then
|
||||
self.current_gun = self.current_gun + math.sign(self.gunSwitchTimer)
|
||||
self.gunSwitchTimer = 0
|
||||
end
|
||||
|
||||
if self.current_gun < 1 then self.current_gun = #self.GunType end
|
||||
if self.current_gun > #self.GunType then self.current_gun = 1 end
|
||||
|
||||
-- basic movement
|
||||
if love.keyboard.isDown("a") then self.target.x = self.pos.x - 1
|
||||
elseif love.keyboard.isDown("d") then self.target.x = self.pos.x + 1
|
||||
else self.target.x = self.pos.x end
|
||||
|
||||
if love.keyboard.isDown("w") then self.target.y = self.pos.y - 1
|
||||
elseif love.keyboard.isDown("s") then self.target.y = self.pos.y + 1
|
||||
else self.target.y = self.pos.y end
|
||||
|
||||
self:MoveTowards(self.target.x, self.target.y, self.moveSpeed)
|
||||
|
||||
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)
|
||||
|
||||
-- shoot
|
||||
local x, y = love.mouse.getPosition()
|
||||
|
||||
if self.shotTimer > 0 then self.shotTimer = self.shotTimer - current_dt end
|
||||
if self.shotTimer < 0 then self.shotTimer = 0 end
|
||||
|
||||
if love.mouse.isDown(1) and self.shotTimer == 0 then
|
||||
gunBullet:New(self.pos.x,self.pos.y,GetAngle(x - self.pos.x, y - self.pos.y), self.GunType[self.current_gun])
|
||||
self.shotTimer = self.GunType[self.current_gun].shotCooldown
|
||||
end
|
||||
-- Gun Switch
|
||||
if love.keyboard.isDown("q") then
|
||||
self.gunSwitchTimer = self.gunSwitchTimer - current_dt
|
||||
elseif love.keyboard.isDown("e") then
|
||||
self.gunSwitchTimer = self.gunSwitchTimer + current_dt
|
||||
else
|
||||
TimeDone = true
|
||||
self.gunSwitchTimer = 0
|
||||
end
|
||||
|
||||
if math.abs(self.gunSwitchTimer) > self.gunSwitchTime then
|
||||
self.current_gun = self.current_gun + math.sign(self.gunSwitchTimer)
|
||||
self.gunSwitchTimer = 0
|
||||
end
|
||||
|
||||
if self.current_gun < 1 then self.current_gun = #self.GunType end
|
||||
if self.current_gun > #self.GunType then self.current_gun = 1 end
|
||||
|
||||
-- Player Intent to Movement
|
||||
if love.keyboard.isDown("a") then self.target.x = self.pos.x - 1
|
||||
elseif love.keyboard.isDown("d") then self.target.x = self.pos.x + 1
|
||||
else self.target.x = self.pos.x end
|
||||
|
||||
if love.keyboard.isDown("w") then self.target.y = self.pos.y - 1
|
||||
elseif love.keyboard.isDown("s") then self.target.y = self.pos.y + 1
|
||||
else self.target.y = self.pos.y end
|
||||
|
||||
-- Variable moveSpeed when focusing
|
||||
if love.keyboard.isDown("lshift") then
|
||||
self:MoveTowards(self.target.x, self.target.y, self.moveSpeedFocused)
|
||||
else
|
||||
self:MoveTowards(self.target.x, self.target.y, self.moveSpeed)
|
||||
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)
|
||||
|
||||
-- Get Ready to shoot if triggered
|
||||
if self.shotTimer > 0 then self.shotTimer = self.shotTimer - current_dt end
|
||||
if self.shotTimer < 0 then self.shotTimer = 0 end
|
||||
|
||||
-- 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])
|
||||
self.shotTimer = self.GunType[self.current_gun].shotCooldown
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -104,13 +113,16 @@ function Player:Step()
|
|||
end
|
||||
|
||||
function Player:Draw()
|
||||
--love.graphics.circle("line", self.pos.x, self.pos.y, self.hitbox)
|
||||
love.graphics.setColor(1,1,1)
|
||||
|
||||
-- Draw Mouse
|
||||
local x, y = love.mouse.getPosition()
|
||||
love.graphics.circle("line", x, y, self.hitbox/2)
|
||||
|
||||
--love.graphics.line(self.pos.x, self.pos.y, x, y)
|
||||
-- Draw Gun Name
|
||||
love.graphics.print("Current Gun: "..self.GunType[self.current_gun].name, 10, 35)
|
||||
|
||||
-- Draw Self
|
||||
if self.sprite ~= nil then
|
||||
love.graphics.draw(
|
||||
self.sprite,
|
||||
|
@ -120,4 +132,12 @@ function Player:Draw()
|
|||
self.draw_scale
|
||||
)
|
||||
end
|
||||
|
||||
-- Draw Hitbox
|
||||
love.graphics.setColor(1,0,0)
|
||||
if love.keyboard.isDown("lshift") then
|
||||
love.graphics.circle("fill", self.pos.x, self.pos.y, self.hitbox)
|
||||
end
|
||||
|
||||
love.graphics.setColor(1,1,1)
|
||||
end
|
||||
|
|
|
@ -8,5 +8,5 @@ List.Enemy = {}
|
|||
List.EnemyBullet = {}
|
||||
List.FriendlyBullet = {}
|
||||
|
||||
|
||||
-- Animations
|
||||
List.AnimationContainers = {}
|
||||
|
|