From b2af5195a72e416a35fee2667e095d241d46a920 Mon Sep 17 00:00:00 2001 From: Madiwka3 Date: Sun, 16 May 2021 19:02:30 +0600 Subject: [PATCH] Bug fixes --- entities/ship/ship.lua | 2 ++ explosion.lua | 16 ++++++++++------ levels/level7.lua | 14 ++++---------- levels/levelgeneral.lua | 15 ++++++--------- levels/practice.lua | 23 ++++++++--------------- main.lua | 12 ++++++++++-- src/GUI.lua | 12 ++++-------- 7 files changed, 44 insertions(+), 50 deletions(-) diff --git a/entities/ship/ship.lua b/entities/ship/ship.lua index 581bda9..5b7a9e4 100644 --- a/entities/ship/ship.lua +++ b/entities/ship/ship.lua @@ -19,6 +19,7 @@ self.vector = 1.5708 self.color = {1,1,1,1} self.path = {} self.dottimer = 0.5 +self.exploded = false self.fuel = 0 self.destX = x end @@ -147,4 +148,5 @@ function ship:reset() self.destX = self.x self.path = {} self.dottimer = 0.5 + self.exploded = false end diff --git a/explosion.lua b/explosion.lua index bfec7be..21d735f 100644 --- a/explosion.lua +++ b/explosion.lua @@ -7,6 +7,7 @@ function explosion:init(x, y, v, color, type) self.y = y self.v = v self.range = 0 + self.maxRange = WINDOW_WIDTH*2 self.killed = false if type ~= nil then self.type = type @@ -16,14 +17,17 @@ end function explosion:update(dt) self.range = self.range + dt * 24 - local maxRange = WINDOW_WIDTH*2 + if (self.type == 0) then + --print("my range is " .. self.range) + end + self.maxRange = WINDOW_WIDTH*2 if self.type == 1 then - maxRange = WINDOW_WIDTH*6 + self.maxRange = WINDOW_WIDTH*6 elseif self.type == 2 then - maxRange = 200 + self.maxRange = 200 end - if self.range * self.v > maxRange then - --print("killing myself with range" .. self.range) + if self.range * self.v > self.maxRange then + --print("killing myself with range" .. self.range .. " " .. self.v .. " " .. self.maxRange .. " and type " .. self.type) self.killed = true end end @@ -36,7 +40,7 @@ function explosion:render(toggle) if self.type == 2 then love.graphics.setColor(1,1,1,0.7/(self.range)) -- print(self.range) - elseif toggle == "special" then + elseif self.type == 1 then love.graphics.setColor(1,1,1,0.7/(self.range/6)) -- print(self.range) end diff --git a/levels/level7.lua b/levels/level7.lua index 816ce90..bad8dd8 100644 --- a/levels/level7.lua +++ b/levels/level7.lua @@ -1,15 +1,7 @@ level7 = Class{} local levelLoaded = false local M = {} -function love.wheelmoved(x, y) - if gameStatus == "play" then - if y > 0 and camera.scale < 1 then - camera.scale = camera.scale + 0.1 - elseif y < 0 and camera.scale > 0.5 then - camera.scale = camera.scale - 0.1 - end -end -end + function level7.load() shipsleft = 1 local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") @@ -23,6 +15,7 @@ function level7.load() explosions = {} shipIsHit = false guimenu = mainMenu() + cameraControl = true reachedGoal = false lvlbase = base(1400, WINDOW_HEIGHT/2) levelLoaded = true @@ -119,7 +112,8 @@ function level7.bonusUpdate(dt) if not cannons[i].appeared then sounds["appear"]:stop() sounds["appear"]:play() - table.insert(explosions, explosion(1500, cannons[i].y, 100, {1,1,1,1}, 1)) + local coolx, cooly = camera:toWorldCoords(1280, 720) + table.insert(explosions, explosion(coolx, cannons[i].y, 100, {1,1,1,1}, 1)) cannons[i].appeared = true end end diff --git a/levels/levelgeneral.lua b/levels/levelgeneral.lua index 4004b0f..ff952e8 100644 --- a/levels/levelgeneral.lua +++ b/levels/levelgeneral.lua @@ -34,9 +34,10 @@ function levelgeneral.update(dt) --print(camera.x .. " " .. camera.y) for i, explosion in ipairs(explosions) do explosion:update(dt) + if explosion.killed then table.remove(explosions, i) - if shipIsHit then + if shipIsHit and explosion.type == 0 then gameStatus = "setup" levelgeneral.reset() end @@ -45,10 +46,9 @@ function levelgeneral.update(dt) if gameStatus == "play" then camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width --print(camera.x .. firstShip.x) - if shipIsHit then - if #explosions == 0 then - table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1})) - end + if shipIsHit and not firstShip.exploded then + table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}, 0)) + firstShip.exploded = true end firstShip:update(dt) @@ -105,11 +105,7 @@ function levelgeneral.draw() end firstShip:draw() for i, explosion in ipairs(explosions) do - if shipIsHit then explosion:render() - else - explosion:render("special") - end --print("exploding") end camera:detach() @@ -145,6 +141,7 @@ function levelgeneral.goBack() levelgeneral.reset() lvlbase = nil gameStatus = "setup" + cameraControl = false firstShip.path = {} cannons = {} levelLoaded = false diff --git a/levels/practice.lua b/levels/practice.lua index 78169b6..2e8ec6d 100644 --- a/levels/practice.lua +++ b/levels/practice.lua @@ -2,15 +2,7 @@ practice = Class{} local levelLoaded = false local M = {} local currenctScore = 0 -function love.wheelmoved(x, y) - if gameStatus == "play" then - if y > 0 and camera.scale < 1 then - camera.scale = camera.scale + 0.1 - elseif y < 0 and camera.scale > 0.5 then - camera.scale = camera.scale - 0.1 - end -end -end + function practice.update(dt) if not levelLoaded then shipsleft = 1 @@ -21,6 +13,7 @@ function practice.update(dt) guibutts = {} XCAM = 0 currentScore = 0 + cameraControl = true thrusterMax = 0 YCAM = 0 firstShip.fuel = 0 @@ -48,6 +41,7 @@ function practice.update(dt) --print(camera.x .. " " .. camera.y) for i, explosion in ipairs(explosions) do explosion:update(dt) + -- print("1 update done") if explosion.killed then table.remove(explosions, i) if shipIsHit then @@ -59,12 +53,10 @@ function practice.update(dt) if gameStatus == "play" then camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width --print(camera.x .. firstShip.x) - if shipIsHit then - if #explosions == 0 then - - table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1})) - end - + if shipIsHit and not firstShip.exploded then + table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1})) + explosions[#explosions].type = 0 + firstShip.exploded = true end firstShip:update(dt) for i in ipairs(planets) do @@ -138,6 +130,7 @@ function practice.draw() end function practice.goBack() practice.reset() + cameraControl = false gameStatus = "setup" levelLoaded = false gameState = "menu" diff --git a/main.lua b/main.lua index 5a4e07b..652e9ec 100644 --- a/main.lua +++ b/main.lua @@ -11,7 +11,7 @@ WINDOW_WIDTH = 1280 WINDOW_HEIGHT = 720 OFFSET_X = 0 OFFSET_Y = 0 - +cameraControl = false currentLevel = 0 saveData = { @@ -24,7 +24,15 @@ buttons = {} cannons = {} projectiles = {} menu = mainMenu() - +function love.wheelmoved(x, y) + if gameStatus == "play" and cameraControl then + if y > 0 and camera.scale < 1 then + camera.scale = camera.scale + 0.1 + elseif y < 0 and camera.scale > 0.5 then + camera.scale = camera.scale - 0.1 + end +end +end function love.load() print(love.filesystem.getAppdataDirectory()) print(love.filesystem.getSaveDirectory()) diff --git a/src/GUI.lua b/src/GUI.lua index c28a03d..83c515f 100644 --- a/src/GUI.lua +++ b/src/GUI.lua @@ -50,11 +50,9 @@ function GUIDraw(mode) love.graphics.draw(shipImage,mx,my, 1.5708, 1, 1, shipW/2, shipH/2) if love.keyboard.mouseisReleased then love.keyboard.mouseisReleased = false - if #explosions == 0 then local zerox, zeroy = camera:toWorldCoords(0, 0) table.insert(explosions, explosion(zerox, my, 100, {1,1,1,1})) - explosions[1].type = 1 - end + explosions[#explosions].type = 1 firstShip.destX = vmx firstShip.y = vmy @@ -84,8 +82,8 @@ function GUIDraw(mode) if #explosions == 0 then local zerox, zeroy = camera:toWorldCoords(0, 0) table.insert(explosions, explosion(zerox, my, 100, {1,1,1,1})) - explosions[1].type = 1 - end + explosions[#explosions].type = 1 + end sounds["appear"]:play() firstShip.destX = 250 @@ -111,10 +109,8 @@ function GUIDraw(mode) end if love.keyboard.mouseisReleased then love.keyboard.mouseisReleased = false - if #explosions == 0 then table.insert(explosions, explosion(0, 100, 100, {1,1,1,1})) - explosions[1].type = 1 - end + explosions[#explosions].type = 1 sounds["appear"]:play() firstShip.destX = vmx firstShip.y = 100