From 9b6e9cf339a7b1f6a988413ce4888b4e84b8aa07 Mon Sep 17 00:00:00 2001 From: UndeadMaelys Date: Tue, 18 Jan 2022 00:53:03 +0100 Subject: [PATCH] haha guess who forgot to push --- assets/ projectileCard5.png | Bin 188 -> 0 bytes assets/ projectileCard6.png | Bin 180 -> 0 bytes assets/ projectileCard7.png | Bin 146 -> 0 bytes assets/ projectileCard8.png | Bin 146 -> 0 bytes assets/projectileCard2.png | Bin 180 -> 189 bytes assets/projectileCard4.png | Bin 172 -> 184 bytes assets/projectileCard5.png | Bin 0 -> 182 bytes assets/projectileCard6.png | Bin 0 -> 188 bytes assets/projectileCard7.png | Bin 0 -> 150 bytes assets/projectileCard8.png | Bin 0 -> 180 bytes main.lua | 107 ++++---------------------- scripts.lua | 3 + scripts/animations.lua | 5 ++ scripts/attack_patterns.lua | 15 ++-- scripts/entities/bullet.lua | 22 +++--- scripts/entities/enemy/fang.lua | 4 +- scripts/entities/enemy/shooter.lua | 4 +- scripts/entities/player.lua | 10 +-- scripts/entity.lua | 81 ++++++-------------- scripts/lists.lua | 54 ++++++++++++- scripts/math.lua | 2 +- scripts/menus.lua | 82 ++++++++++++++++++++ scripts/score.lua | 7 ++ scripts/stage.lua | 118 +++++++++++++++++++++++++++++ scripts/ui/button.lua | 106 ++++++++++++++++++++++++++ 25 files changed, 439 insertions(+), 181 deletions(-) delete mode 100755 assets/ projectileCard5.png delete mode 100755 assets/ projectileCard6.png delete mode 100755 assets/ projectileCard7.png delete mode 100755 assets/ projectileCard8.png 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 100644 scripts/menus.lua create mode 100644 scripts/score.lua create mode 100644 scripts/stage.lua create mode 100644 scripts/ui/button.lua diff --git a/assets/ projectileCard5.png b/assets/ projectileCard5.png deleted file mode 100755 index 24e5a9e539ec2b3f731ca197fd8bc1d56d28567b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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 diff --git a/assets/ projectileCard6.png b/assets/ projectileCard6.png deleted file mode 100755 index 4c8aee2e4dbcf76f4042b43d71f7af3a02b95e61..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|@;qG}LnNjq zCpa)0r%L==+zw`V+n;AS^{an^LB{Ts5Zbe4L diff --git a/assets/ projectileCard7.png b/assets/ projectileCard7.png deleted file mode 100755 index dd9b0f89472e9b814e01eaeca7fb8daf27357aba..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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$ diff --git a/assets/ projectileCard8.png b/assets/ projectileCard8.png deleted file mode 100755 index dd9b0f89472e9b814e01eaeca7fb8daf27357aba..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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$ diff --git a/assets/projectileCard2.png b/assets/projectileCard2.png index 4c8aee2e4dbcf76f4042b43d71f7af3a02b95e61..64501754397f81fc7a9f3b6a7201d7090d46317d 100755 GIT binary patch delta 148 zcmV;F0BirW0lfi`F@JYSL_t&-m1AH)12bh9{_jy{_z&YVAxrL2X84~b%)oH>Cxp#_ zE{P0aCNaSzkH$4Jgzoi&Ye+i>F^O@e48#8ysf}=nFW0RZx|TaL>{Vf8aJkFC$fV59 zz#uWZ9-F@J7JL_t&-m1AH)12bh9{-cY*!5(FX|Nr$F{$o|NN15S2GC)zZ zN15S&V`Jn0kUhQ#6|W#BG0v1>`2Qlc5w7^lb!&#M<<1OyRTvpu?lLekr9WX{l$c!) tSHPor6fTM3`o_k_|9h12_yU{j0h5qGkF@JJNL_t&-m1AIlf<4L%|7XfD{AWM|Ofbp2KN%Qaq&70_QASn7 zh%5;M){E*HT<$V3GB7YOFriCcwm!q)eCI#hBu1DON8=h9zFfCv=vwX!QE9-)FzYRn xU3-)n{v(5#G7SIG-2+kdiUGSM44_K_06Aeob-9&25dZ)H00>D%PDHLkV1lS>IiCOk delta 130 zcmV-|0Db?s0jvR#F?(i7L_t&-m1AH)0yAY8{xhHfCS=JMsf`SKlu;EiB1^)6^`d$P zm%9)-CUnWm)@K-;@BD|G#K^$Fz_3S|;s4RNMusoftr@zOJ3~|&Ffz<~i)7axWrqLA k0Gop$ie52bm&D~&03hQw+f74)1poj507*qoM6N<$f@$hFe*gdg diff --git a/assets/projectileCard5.png b/assets/projectileCard5.png new file mode 100755 index 0000000000000000000000000000000000000000..d65b1c7aa6365668bfc29b205bce1bbd9ada4e47 GIT binary patch literal 182 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|3OrpLLnNjq zrz9jK%+NgiA%5muM%FujPac@?ucdJ!t6G7{IziXQBX6qMKtK&dl-xa$R3N-BW_ub? zPr{D*MiU!>;9!;Dq*u15c>Z5JD3{vyzd-u~quPva$v9)D4U8=J|8_oW+dJ)sF9So6 WvU=@xj*uLn-3*?telF{r5}E)$Y(Oml literal 0 HcmV?d00001 diff --git a/assets/projectileCard6.png b/assets/projectileCard6.png new file mode 100755 index 0000000000000000000000000000000000000000..adf507644b28798a06ca29ee7b56950dfb58fd35 GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|$~;{hLnNjq zCpa)0r%L>LADH%o|FN;6_d6itztYx;58wH7%x(k%!N^Y;G0HI;kG!d3OD$W$Sv^Ja zpY{Ep=RZ8%Wg5eHMx|}05zqhs`;&g~Gb>it{5Ll|NsAAY#|gn i(T;hU$}XjnLI$ZA&-fQEHZedKFnGH9xvX_>bNa)K7-eQ3 zLFF?d&#nJUI(`3T_(IOKQG42q*z*UD95`^`LDBTa!u4FrZA*--#g3bqnf;ru*?e@P dL4zJAgWyJ+{KuaprGPdwc)I$ztaD0e0st1%Ln8nH literal 0 HcmV?d00001 diff --git a/main.lua b/main.lua index 900f6d3..1d38063 100644 --- a/main.lua +++ b/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 diff --git a/scripts.lua b/scripts.lua index 3dbe3c8..2facf80 100644 --- a/scripts.lua +++ b/scripts.lua @@ -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" diff --git a/scripts/animations.lua b/scripts/animations.lua index 2d1b1ea..bbc1f64 100644 --- a/scripts/animations.lua +++ b/scripts/animations.lua @@ -29,6 +29,11 @@ Animation = { path = "assets/projectileBlueRocket", frames = 1, speed = 1 + }, + projectileCard = { + path = "assets/projectileCard", + frames = 8, + speed = 1/24 } } diff --git a/scripts/attack_patterns.lua b/scripts/attack_patterns.lua index 7ec4a6d..1821159 100644 --- a/scripts/attack_patterns.lua +++ b/scripts/attack_patterns.lua @@ -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 diff --git a/scripts/entities/bullet.lua b/scripts/entities/bullet.lua index f7bf81f..9b62c2d 100644 --- a/scripts/entities/bullet.lua +++ b/scripts/entities/bullet.lua @@ -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, diff --git a/scripts/entities/enemy/fang.lua b/scripts/entities/enemy/fang.lua index addf0b3..97f9ee0 100644 --- a/scripts/entities/enemy/fang.lua +++ b/scripts/entities/enemy/fang.lua @@ -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 diff --git a/scripts/entities/enemy/shooter.lua b/scripts/entities/enemy/shooter.lua index 61b0067..5f95d7b 100644 --- a/scripts/entities/enemy/shooter.lua +++ b/scripts/entities/enemy/shooter.lua @@ -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 diff --git a/scripts/entities/player.lua b/scripts/entities/player.lua index 900fbd9..b1f325c 100644 --- a/scripts/entities/player.lua +++ b/scripts/entities/player.lua @@ -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 diff --git a/scripts/entity.lua b/scripts/entity.lua index 9a28f2d..1c9a256 100644 --- a/scripts/entity.lua +++ b/scripts/entity.lua @@ -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 diff --git a/scripts/lists.lua b/scripts/lists.lua index 77c1fd0..448a407 100644 --- a/scripts/lists.lua +++ b/scripts/lists.lua @@ -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 +]] diff --git a/scripts/math.lua b/scripts/math.lua index 380c045..649fa85 100644 --- a/scripts/math.lua +++ b/scripts/math.lua @@ -1,4 +1,4 @@ -function GetAngle(x,y) +function GetAngleFromVector(x,y) local reduce = 0 if x < 0 then reduce = math.rad(180) diff --git a/scripts/menus.lua b/scripts/menus.lua new file mode 100644 index 0000000..3c096a7 --- /dev/null +++ b/scripts/menus.lua @@ -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 diff --git a/scripts/score.lua b/scripts/score.lua new file mode 100644 index 0000000..492c944 --- /dev/null +++ b/scripts/score.lua @@ -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 diff --git a/scripts/stage.lua b/scripts/stage.lua new file mode 100644 index 0000000..0ffd580 --- /dev/null +++ b/scripts/stage.lua @@ -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 diff --git a/scripts/ui/button.lua b/scripts/ui/button.lua new file mode 100644 index 0000000..8a13e2d --- /dev/null +++ b/scripts/ui/button.lua @@ -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