From a333bcc9b77e644d556fb3a9080ea0019d9ae177 Mon Sep 17 00:00:00 2001 From: UndeadMaelys Date: Fri, 31 Dec 2021 12:21:48 +0100 Subject: [PATCH] Added comments, (some) cleanup --- assets/ projectileCard5.png | Bin 0 -> 188 bytes assets/ projectileCard6.png | Bin 0 -> 180 bytes assets/ projectileCard7.png | Bin 0 -> 146 bytes assets/ projectileCard8.png | Bin 0 -> 146 bytes assets/projectileCard1.png | Bin 0 -> 188 bytes assets/projectileCard2.png | Bin 0 -> 180 bytes assets/projectileCard3.png | Bin 0 -> 146 bytes assets/projectileCard4.png | Bin 0 -> 172 bytes main.lua | 10 ++-- scripts/attack_patterns.lua | 95 ++++++++++++++++++-------------- scripts/entities/bullet.lua | 29 +++++++--- scripts/entities/player.lua | 106 +++++++++++++++++++++--------------- scripts/lists.lua | 2 +- 13 files changed, 143 insertions(+), 99 deletions(-) create mode 100755 assets/ projectileCard5.png create mode 100755 assets/ projectileCard6.png create mode 100755 assets/ projectileCard7.png create mode 100755 assets/ projectileCard8.png create mode 100755 assets/projectileCard1.png create mode 100755 assets/projectileCard2.png create mode 100755 assets/projectileCard3.png create mode 100755 assets/projectileCard4.png diff --git a/assets/ projectileCard5.png b/assets/ projectileCard5.png new file mode 100755 index 0000000000000000000000000000000000000000..24e5a9e539ec2b3f731ca197fd8bc1d56d28567b GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|$~;{hLnNjq zrz9jK%+NgiA%5muM%FujPac@?ucdJ!tJ;Gz%&BkMv<#Xq=LI*V^)!OM^`PF1atv|r>mdKI;Vst0NNr-0{{R3 literal 0 HcmV?d00001 diff --git a/assets/ projectileCard6.png b/assets/ projectileCard6.png new file mode 100755 index 0000000000000000000000000000000000000000..4c8aee2e4dbcf76f4042b43d71f7af3a02b95e61 GIT binary patch literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|@;qG}LnNjq zCpa)0r%L==+zw`V+n;AS^{an^LB{Ts5Zbe4L literal 0 HcmV?d00001 diff --git a/assets/ projectileCard7.png b/assets/ projectileCard7.png new file mode 100755 index 0000000000000000000000000000000000000000..dd9b0f89472e9b814e01eaeca7fb8daf27357aba GIT binary patch literal 146 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|d^}woLnNjq zCnzvTq@ObQlb(=}5Rm3Rb;obvRSEq@hyO1w?BxN0>1)p$tSP(4GSM(0<;L&U#>UPG qq8eNx&z~q;?B1xMaC#yOBZJ%oA@d6g&7wea89ZJ6T-G@yGywpPd@bt$ literal 0 HcmV?d00001 diff --git a/assets/ projectileCard8.png b/assets/ projectileCard8.png new file mode 100755 index 0000000000000000000000000000000000000000..dd9b0f89472e9b814e01eaeca7fb8daf27357aba GIT binary patch literal 146 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|d^}woLnNjq zCnzvTq@ObQlb(=}5Rm3Rb;obvRSEq@hyO1w?BxN0>1)p$tSP(4GSM(0<;L&U#>UPG qq8eNx&z~q;?B1xMaC#yOBZJ%oA@d6g&7wea89ZJ6T-G@yGywpPd@bt$ literal 0 HcmV?d00001 diff --git a/assets/projectileCard1.png b/assets/projectileCard1.png new file mode 100755 index 0000000000000000000000000000000000000000..24e5a9e539ec2b3f731ca197fd8bc1d56d28567b GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|$~;{hLnNjq zrz9jK%+NgiA%5muM%FujPac@?ucdJ!tJ;Gz%&BkMv<#Xq=LI*V^)!OM^`PF1atv|r>mdKI;Vst0NNr-0{{R3 literal 0 HcmV?d00001 diff --git a/assets/projectileCard2.png b/assets/projectileCard2.png new file mode 100755 index 0000000000000000000000000000000000000000..4c8aee2e4dbcf76f4042b43d71f7af3a02b95e61 GIT binary patch literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|@;qG}LnNjq zCpa)0r%L==+zw`V+n;AS^{an^LB{Ts5Zbe4L literal 0 HcmV?d00001 diff --git a/assets/projectileCard3.png b/assets/projectileCard3.png new file mode 100755 index 0000000000000000000000000000000000000000..dd9b0f89472e9b814e01eaeca7fb8daf27357aba GIT binary patch literal 146 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|d^}woLnNjq zCnzvTq@ObQlb(=}5Rm3Rb;obvRSEq@hyO1w?BxN0>1)p$tSP(4GSM(0<;L&U#>UPG qq8eNx&z~q;?B1xMaC#yOBZJ%oA@d6g&7wea89ZJ6T-G@yGywpPd@bt$ literal 0 HcmV?d00001 diff --git a/assets/projectileCard4.png b/assets/projectileCard4.png new file mode 100755 index 0000000000000000000000000000000000000000..f5df980a6aa1df580ef0d001b3e7e8eb3eb698e0 GIT binary patch literal 172 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|(mY)pLnNjq zCpa(}r%L=YUcji9a#DO{FHiN9Kv6>_??Vk=7ge!M-z{LNR&w(6wRDL&@Bg&VK62u~ zfdd=dXFmLYafe%*{`IwzyQWz?he#P1ovG?hxh|L5_WuOK>}JKTIKzbLN1lc 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( diff --git a/scripts/entities/bullet.lua b/scripts/entities/bullet.lua index 8884190..f7bf81f 100644 --- a/scripts/entities/bullet.lua +++ b/scripts/entities/bullet.lua @@ -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( diff --git a/scripts/entities/player.lua b/scripts/entities/player.lua index f2709b8..900fbd9 100644 --- a/scripts/entities/player.lua +++ b/scripts/entities/player.lua @@ -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 diff --git a/scripts/lists.lua b/scripts/lists.lua index 4be5e5e..77c1fd0 100644 --- a/scripts/lists.lua +++ b/scripts/lists.lua @@ -8,5 +8,5 @@ List.Enemy = {} List.EnemyBullet = {} List.FriendlyBullet = {} - +-- Animations List.AnimationContainers = {}