Added comments, (some) cleanup

This commit is contained in:
UndeadMaelys 2021-12-31 12:21:48 +01:00
parent b9c23b7cf2
commit a333bcc9b7
13 changed files with 143 additions and 99 deletions

BIN
assets/ projectileCard5.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

BIN
assets/ projectileCard6.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

BIN
assets/ projectileCard7.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

BIN
assets/ projectileCard8.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

BIN
assets/projectileCard1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

BIN
assets/projectileCard2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

BIN
assets/projectileCard3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

BIN
assets/projectileCard4.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

View File

@ -5,7 +5,7 @@ function love.load()
love.graphics.setDefaultFilter("nearest") -- good pixel love.graphics.setDefaultFilter("nearest") -- good pixel
window_width = 600 window_width = 600
window_height = 600 window_height = 600
Time = 0 t = 0
TimeDone = false TimeDone = false
BackgroundColor = {0,0,0} BackgroundColor = {0,0,0}
BackgroundTimer = 0 BackgroundTimer = 0
@ -18,8 +18,8 @@ end
function love.update(dt) function love.update(dt)
current_dt = dt current_dt = dt
You:Input()
You:Input()
for _, obj in pairs(List.Simulate) do for _, obj in pairs(List.Simulate) do
obj:Step() obj:Step()
end end
@ -51,7 +51,7 @@ function love.update(dt)
end end
if TimeDone == false then if TimeDone == false then
Time = Time + dt t = t + dt
EnemyTimer = EnemyTimer + dt EnemyTimer = EnemyTimer + dt
BackgroundTimer = BackgroundTimer + dt BackgroundTimer = BackgroundTimer + dt
end end
@ -101,9 +101,9 @@ function love.draw()
love.graphics.line(0,1/5*window_height,window_height,1/5*window_height) love.graphics.line(0,1/5*window_height,window_height,1/5*window_height)
love.graphics.rectangle("line",0,0,window_width,window_height) love.graphics.rectangle("line",0,0,window_width,window_height)
-- overlay -- overlay
--love.graphics.print(Time, 10, 10) --love.graphics.print(t, 10, 10)
love.graphics.print(BackgroundTimer, window_width-100, 10) love.graphics.print(BackgroundTimer, window_width-100, 10)
love.graphics.print(BackgroundPeriod, window_width-100, 20) love.graphics.print(BackgroundPeriod, window_width-100, 20)
love.graphics.print(#List.Simulate, window_width-100, window_height-10) 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 end

View File

@ -1,17 +1,17 @@
AttackPattern = {} AttackPattern = {}
AttackPattern.Wait = function(entity,t,a,b,c) AttackPattern.Wait = function(entity,t,a,b,c)
entity.patternTime = 2 entity.patternTime = 0.75
entity.nextPattern = AttackPattern.PressureWebOfLies entity.nextPattern = AttackPattern.PressureWebOfLies
end end
AttackPattern.PressureWebOfLies = function(entity,t,a,b,c) AttackPattern.PressureWebOfLies = function(entity,t,a,b,c)
if t % 2 == 0 then AttackPattern.FixatedWeb(entity,t,a,b,c) end if t % 2 == 0 then AttackPattern.FixatedWeb(entity,t,a,b,c) end
if t % 50 < 5 then AttackPattern.DrowningBarrage(entity,t,a,b,c) end
if t % 10 > 7 then AttackPattern.ShotAtPlayerTriple(entity,t,5) end if t % 10 < 4 then AttackPattern.ShotAtPlayerTriple(entity,t,5) end
entity.shotTimer = 0.05 entity.shotTimer = 0.05
entity.patternTime = 10 entity.patternTime = 4
entity.nextPattern = AttackPattern.Wait entity.nextPattern = AttackPattern.Wait
end end
@ -23,46 +23,57 @@ AttackPattern.MortalDrowningBarrage = function(entity,t,a,b,c)
end end
AttackPattern.FixatedWeb = function(entity,t,a,b,c) AttackPattern.FixatedWeb = function(entity,t,a,b,c)
local BulletDataLeft = {
-- BULLETS DATA
b = b or {
damage = 3, damage = 3,
hits = 1, hits = 1,
moveSpeed = 7, moveSpeed = 4,
moveSpeedIncrease = 0.1, moveSpeedIncrease = 0.001,
moveHorizontalIncrease = 0.001, moveHorizontalIncrease = 0.001,
moveSpeedValues = { min = 2, max = 4}, moveSpeedLimits = { min = 2, max = 4},
animation = Animation.projectileGreen, animation = Animation.projectileGreen,
hostile = true hostile = true,
maximumTurnRate = 0.05
} }
local BulletDataRight = { c = c or {
damage = 3, damage = 3,
hits = 1, hits = 1,
moveSpeed = 7, moveSpeed = 4,
moveSpeedIncrease = 0.1, moveSpeedIncrease = 0.001,
moveHorizontalIncrease = -0.001, moveHorizontalIncrease = -0.001,
moveSpeedValues = { min = 2, max = 4}, moveSpeedLimits = { min = 2, max = 4},
animation = Animation.projectileGreen, animation = Animation.projectileGreen,
hostile = true hostile = true,
maximumTurnRate = 0.05
} }
-- Initialization if not initialized
local t = t or 0 local t = t or 0
if a == nil then if a == nil then
a = -10 a = -10
end end
gunBullet:New(
entity.pos.x, if t % 40 < 20 then
entity.pos.y, b.moveHorizontalIncrease = -b.moveHorizontalIncrease
math.rad(a *-math.cos( 5 )) + math.rad(90) + math.rad(40) --[[GetAngle( c.moveHorizontalIncrease = -c.moveHorizontalIncrease
target_x - entity.pos.x, end
target_y - entity.pos.y)]],
BulletDataLeft -- Bullet Generation
) Projectile:New(
gunBullet:New( entity.pos.x,
entity.pos.x, entity.pos.y,
entity.pos.y, math.rad(a *-math.cos( 5 )) + math.rad(90) + math.rad(40),
math.rad(a *math.cos( 5 )) + math.rad(90) - math.rad(40) --[[GetAngle( b
target_x - entity.pos.x, )
target_y - entity.pos.y)]],
BulletDataRight 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.patternTime = 4
entity.shotTimer = 0.3 entity.shotTimer = 0.3
entity.nextPattern = AttackPattern.FixatedWeb entity.nextPattern = AttackPattern.FixatedWeb
@ -81,9 +92,9 @@ AttackPattern.TwinRays = function(entity,t,a,b,c)
local BulletDataRed = { local BulletDataRed = {
damage = 3, damage = 3,
hits = 1, hits = 1,
moveSpeed = 3.5, moveSpeed = 2,
moveSpeedIncrease = -0.05, moveSpeedIncrease = -0.05,
moveSpeedValues = { min = 2, max = 4}, moveSpeedLimits = { min = 2, max = 4},
animation = Animation.projectileRed, animation = Animation.projectileRed,
hostile = true hostile = true
} }
@ -92,14 +103,14 @@ AttackPattern.TwinRays = function(entity,t,a,b,c)
hits = 1, hits = 1,
moveSpeed = 3.5, moveSpeed = 3.5,
moveSpeedIncrease = -0.05, moveSpeedIncrease = -0.05,
moveSpeedValues = { min = 2, max = 4}, moveSpeedLimits = { min = 2, max = 4},
animation = Animation.projectileBlue, animation = Animation.projectileBlue,
hostile = true hostile = true
} }
local target_x = You.pos.x local target_x = You.pos.x
local target_y = You.pos.y local target_y = You.pos.y
for i=-1, 1 do for i=-1, 1 do
gunBullet:New( Projectile:New(
entity.pos.x, entity.pos.x,
entity.pos.y, entity.pos.y,
math.rad(a *math.cos(t/5 )) + math.rad(90) + math.rad(45)* i --[[GetAngle( 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)]], target_y - entity.pos.y)]],
BulletDataRed BulletDataRed
) )
gunBullet:New( Projectile:New(
entity.pos.x, entity.pos.x,
entity.pos.y, entity.pos.y,
math.rad(a *-math.cos(t/5 )) + math.rad(90) + math.rad(45)* i --[[GetAngle( 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, shotCooldown = 0.05,
damage = 3, damage = 3,
hits = 1, hits = 1,
moveSpeed = 3.5, moveSpeed = 2.5,
animation = Animation.projectileRed, animation = Animation.projectileRed,
hostile = true hostile = true,
maximumTurnRate = 0.5
} }
local target_x = You.pos.x local target_x = You.pos.x
local target_y = You.pos.y local target_y = You.pos.y
entity.shotTimer = BulletData.shotCooldown entity.shotTimer = BulletData.shotCooldown
gunBullet:New( Projectile:New(
entity.pos.x, entity.pos.x,
entity.pos.y, entity.pos.y,
math.rad(b *math.cos(t)) + GetAngle( math.rad(b *math.cos(t)) + GetAngle(
@ -180,7 +192,7 @@ AttackPattern.ShotAtPlayerDouble = function(entity)
entity.shotTimer = BulletData.shotCooldown entity.shotTimer = BulletData.shotCooldown
for i=-1, 1 do for i=-1, 1 do
if i ~= 0 then if i ~= 0 then
gunBullet:New( Projectile:New(
entity.pos.x, entity.pos.x,
entity.pos.y, entity.pos.y,
math.rad(-10)*i + GetAngle( math.rad(-10)*i + GetAngle(
@ -199,13 +211,14 @@ AttackPattern.ShotAtPlayerTriple = function(entity,t,a)
hits = 1, hits = 1,
moveSpeed = a, moveSpeed = a,
animation = Animation.projectileBlue, animation = Animation.projectileBlue,
hostile = true hostile = true,
maximumTurnRate = 0.2
} }
local target_x = You.pos.x local target_x = You.pos.x
local target_y = You.pos.y local target_y = You.pos.y
entity.shotTimer = BulletData.shotCooldown entity.shotTimer = BulletData.shotCooldown
for i=-1, 1 do for i=-1, 1 do
gunBullet:New( Projectile:New(
entity.pos.x, entity.pos.x,
entity.pos.y, entity.pos.y,
math.rad(-15)*i + GetAngle( math.rad(-15)*i + GetAngle(

View File

@ -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) local o = Entity:New(x,y,angle)
o.target = {} o.target = {}
@ -10,12 +10,15 @@ function gunBullet:New(x,y,angle,data)
o.hits = data.hits o.hits = data.hits
o.damage = data.damage 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.animation = AnimationContainer:New(data.animation)
o.moveSpeed = data.moveSpeed 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.moveSpeedIncrease = data.moveSpeedIncrease or 0
o.moveHorizontalIncrease = data.moveHorizontalIncrease or 0 o.moveHorizontalIncrease = data.moveHorizontalIncrease or 0
o.moveVerticalIncrease = data.moveVerticalIncrease or 0 o.moveVerticalIncrease = data.moveVerticalIncrease or 0
o.maximumTurnRate = data.maximumTurnRate or 0
o.moveHorizontal = 0 o.moveHorizontal = 0
o.moveVertical = 0 o.moveVertical = 0
-- lists -- lists
@ -35,25 +38,33 @@ function gunBullet:New(x,y,angle,data)
return o return o
end end
function gunBullet:Step() function Projectile:Step()
self.moveSpeed = self.moveSpeed + self.moveSpeedIncrease self.moveSpeed = self.moveSpeed + self.moveSpeedIncrease
self.moveSpeed = math.max(self.moveSpeedValues.min,self.moveSpeed) self.moveSpeed = math.max(self.moveSpeedLimits.min,self.moveSpeed)
self.moveSpeed = math.min(self.moveSpeedValues.max,self.moveSpeed) self.moveSpeed = math.min(self.moveSpeedLimits.max,self.moveSpeed)
self.moveHorizontal = self.moveHorizontal + self.moveHorizontalIncrease self.moveHorizontal = self.moveHorizontal + self.moveHorizontalIncrease
self.moveVertical = self.moveVertical + self.moveVerticalIncrease self.moveVertical = self.moveVertical + self.moveVerticalIncrease
local move_x = (self.moveSpeed) * math.cos(self.angle) + self.moveHorizontal local move_x = (self.moveSpeed) * math.cos(self.angle) + self.moveHorizontal
local move_y = (self.moveSpeed) * math.sin(self.angle) + self.moveVertical 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:AngleTowards(
self.pos.x + move_x, self.pos.x + move_x,
self.pos.y + move_y self.pos.y + move_y
) )
-- bends towards the player? owo
if self.pos.x < 0 or self.pos.x > window_width if self.pos.x < 0 or self.pos.x > window_width
or self.pos.y < 0 or self.pos.y > window_height then or self.pos.y < 0 or self.pos.y > window_height then
self:RemoveList(List.Simulate) self:RemoveList(List.Simulate)
@ -61,7 +72,7 @@ function gunBullet:Step()
end end
end end
function gunBullet:Draw() function Projectile:Draw()
self.animation:Animate() 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) 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.animation:Draw(

View File

@ -1,5 +1,6 @@
Player = Entity:New(x,y) Player = Entity:New(x,y)
-- Player Gun Types
Player.GunType = { Player.GunType = {
{ {
name = "Plasma Machine Gun", name = "Plasma Machine Gun",
@ -30,11 +31,13 @@ Player.GunType = {
} }
} }
-- Player Builder
function Player:New(x,y) function Player:New(x,y)
local o = Entity:New(x,y) local o = Entity:New(x,y)
o.moveSpeed = 3 o.moveSpeed = 3
o.hitbox = 10 o.moveSpeedFocused = 2
o.hitbox = 5
o.sprite = love.graphics.newImage("assets/heart.png") o.sprite = love.graphics.newImage("assets/heart.png")
o.draw_scale = 3 o.draw_scale = 3
@ -54,48 +57,54 @@ function Player:New(x,y)
return o return o
end end
-- Function to get the player input
function Player:Input() function Player:Input()
if self.sprite ~= nil then -- Gun Switch
-- gun control if love.keyboard.isDown("q") then
if love.keyboard.isDown("q") then self.gunSwitchTimer = self.gunSwitchTimer - current_dt self.gunSwitchTimer = self.gunSwitchTimer - current_dt
elseif love.keyboard.isDown("e") then self.gunSwitchTimer = self.gunSwitchTimer + current_dt elseif love.keyboard.isDown("e") then
else self.gunSwitchTimer = 0 self.gunSwitchTimer = self.gunSwitchTimer + current_dt
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
else 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
end end
@ -104,13 +113,16 @@ function Player:Step()
end end
function Player:Draw() 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() local x, y = love.mouse.getPosition()
love.graphics.circle("line", x, y, self.hitbox/2) 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) love.graphics.print("Current Gun: "..self.GunType[self.current_gun].name, 10, 35)
-- Draw Self
if self.sprite ~= nil then if self.sprite ~= nil then
love.graphics.draw( love.graphics.draw(
self.sprite, self.sprite,
@ -120,4 +132,12 @@ function Player:Draw()
self.draw_scale self.draw_scale
) )
end 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 end

View File

@ -8,5 +8,5 @@ List.Enemy = {}
List.EnemyBullet = {} List.EnemyBullet = {}
List.FriendlyBullet = {} List.FriendlyBullet = {}
-- Animations
List.AnimationContainers = {} List.AnimationContainers = {}