| @@ -0,0 +1,3 @@ | |||
| function love.conf(t) | |||
| t.identity = "gravity" | |||
| end | |||
| @@ -2,7 +2,7 @@ enemy = Class{} | |||
| G = 6.67e-5 | |||
| function enemy:init(x, y, del, tm) | |||
| function enemy:init(x, y, del, tm, atm) | |||
| self.x = x | |||
| self.y = y | |||
| self.image = love.graphics.newImage("entities/enemy/enemy.png") | |||
| @@ -18,9 +18,11 @@ self.destX = x | |||
| self.timer = tm | |||
| self.color = {1,1,1,1} | |||
| self.appeared = false | |||
| self.appeartimer = atm | |||
| end | |||
| function enemy:update(dt) | |||
| self.timer = self.timer - dt | |||
| if self.timer <= 0 then | |||
| self.timer = self.maxtimer | |||
| @@ -32,7 +34,9 @@ function enemy:update(dt) | |||
| self.angle = self.angle - 3.14159 | |||
| end | |||
| end | |||
| function enemy:time(dt) | |||
| self.appeartimer = self.appeartimer - dt | |||
| end | |||
| function enemy:draw() | |||
| love.graphics.setColor(unpack(self.color)) | |||
| love.graphics.draw(self.image, self.x, self.y, 0, 1, 1, self.w/2, self.w/2) | |||
| @@ -30,11 +30,25 @@ function projectile:update(dt) | |||
| self.vy = self.vy + self.dy | |||
| self.x = self.x + self.vx | |||
| self.y = self.y + self.vy | |||
| if distanceToShip < firstShip.width/3 then | |||
| if distanceToShip < firstShip.width/2 then | |||
| shipIsHit = true | |||
| sounds["close"]:stop() | |||
| sounds["boom"]:play() | |||
| end | |||
| for i in ipairs(planets) do | |||
| if planets[i].deletable == false then | |||
| distanceToShip = math.sqrt((planets[i].x - self.x)^2 + (planets[i].y - self.y)^2) | |||
| if distanceToShip < planets[i].w/4 then | |||
| sounds["boom"]:play() | |||
| local q = #explosions | |||
| table.insert(explosions, explosion(self.x, self.y, 100, {1,1,1,1})) | |||
| explosions[q+1].type = 2 | |||
| table.remove(planets, i) | |||
| self.killed = true | |||
| end | |||
| end | |||
| end | |||
| end | |||
| function projectile:draw() | |||
| @@ -37,7 +37,7 @@ function planet:update(dt) | |||
| love.window.setTitle(self.attractionX) | |||
| firstShip.dx = firstShip.dx + self.attractionX | |||
| firstShip.dy = firstShip.dy + self.attractionY | |||
| if distanceToShip < self.w/4 then | |||
| if distanceToShip < self.w/4 and not reachedGoal then | |||
| shipIsHit = true | |||
| sounds["close"]:stop() | |||
| sounds["boom"]:play() | |||
| @@ -10,6 +10,8 @@ self.dy = 0 | |||
| self.dx = 5 | |||
| self.speed = 1 | |||
| self.image = love.graphics.newImage(image) | |||
| self.oimage = self.image | |||
| self.timage = love.graphics.newImage("entities/ship/thrusting01.png") | |||
| self.width = self.image:getWidth() | |||
| self.height = self.image:getHeight() | |||
| self.rotation = 1.5708 | |||
| @@ -31,9 +33,11 @@ function ship:update(dt) | |||
| if not shipIsHit then | |||
| self.dottimer = self.dottimer - dt | |||
| if self.dottimer < 0 then | |||
| if (love.keyboard.isDown('w') and self.fuel > 0 and gameState == "levelgeneral") then | |||
| if (love.keyboard.isDown('w') and self.fuel > 0 and gameState == "levelgeneral") then | |||
| self.image = self.timage | |||
| table.insert(self.path, self:newPathDot(self.x, self.y, 1)) | |||
| else | |||
| self.image = self.oimage | |||
| table.insert(self.path, self:newPathDot(self.x, self.y, 2)) | |||
| end | |||
| self.dottimer = 0.2 | |||
| @@ -67,6 +71,13 @@ function ship:update(dt) | |||
| tag = true | |||
| end | |||
| end | |||
| for i in ipairs(projectiles) do | |||
| local distanceToShip = math.sqrt((firstShip.x - projectiles[i].x)^2 + (firstShip.y - projectiles[i].y)^2) | |||
| if distanceToShip < 200 and not shipIsHit and gameStatus == "play" then | |||
| sounds["close"]:play() | |||
| tag = true | |||
| end | |||
| end | |||
| if not tag or shipIsHit then | |||
| sounds["close"]:stop() | |||
| end | |||
| @@ -108,7 +119,7 @@ function ship:draw() | |||
| -- Draw the `self.canvas` to screen | |||
| love.graphics.setColor(unpack(self.color)) | |||
| --print("DAW" .. camera.x) | |||
| love.graphics.draw(self.image, self.x, self.y, self.vector, 1, 1, self.width/2, self.height/2) | |||
| for i in ipairs(self.path) do | |||
| if i > 1 then | |||
| @@ -121,7 +132,7 @@ function ship:draw() | |||
| end | |||
| end | |||
| love.graphics.setColor(1,1,1,1) | |||
| love.graphics.draw(self.image, self.x, self.y, self.vector, 1, 1, self.width/2, self.height/2) | |||
| end | |||
| function ship:reset() | |||
| @@ -1,6 +1,6 @@ | |||
| explosion = Class{} | |||
| function explosion:init(x, y, v, color) | |||
| function explosion:init(x, y, v, color, type) | |||
| self.color = color | |||
| self.type = 0 | |||
| self.x = x | |||
| @@ -8,13 +8,16 @@ function explosion:init(x, y, v, color) | |||
| self.v = v | |||
| self.range = 0 | |||
| self.killed = false | |||
| if type ~= nil then | |||
| self.type = type | |||
| end | |||
| --print(self.i) | |||
| end | |||
| function explosion:update(dt) | |||
| self.range = self.range + dt * 24 | |||
| local maxRange = WINDOW_WIDTH*2 | |||
| if self.type == 1 then | |||
| if self.type >= 1 then | |||
| maxRange = WINDOW_WIDTH*6 | |||
| end | |||
| if self.range * self.v > maxRange then | |||
| @@ -56,6 +56,13 @@ function level6.hint() | |||
| end | |||
| function level6.reset() | |||
| firstShip:reset() | |||
| for i in ipairs(planets) do | |||
| if not planets[i].deletable then | |||
| table.remove(planets, i) | |||
| end | |||
| end | |||
| table.insert(planets, planet(1600, 250, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1600, 550, 50, 0.3, asteroidImage, "nodelete")) | |||
| local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||
| shipsleft = 1 | |||
| projectiles = {} | |||
| @@ -79,15 +86,22 @@ function level6.bonusUpdate(dt) | |||
| sounds["appear"]:stop() | |||
| sounds["appear"]:play() | |||
| if #explosions == 0 then | |||
| table.insert(explosions, explosion(1400, 400, 100, {1,40/255,40/255,1})) | |||
| table.insert(explosions, explosion(1400, 400, 100, {1,1,1,1})) | |||
| explosions[1].type = 1 | |||
| end | |||
| camera:shake(8, 1, 60, 'X') | |||
| cannons[1].appeared = true | |||
| end | |||
| end | |||
| for i in ipairs(projectiles) do | |||
| projectiles[i]:update(dt) | |||
| end | |||
| for i in ipairs(projectiles) do | |||
| if projectiles[i].killed then | |||
| table.remove(projectiles, i) | |||
| --print("killing") | |||
| end | |||
| end | |||
| cannons[1].x = cannons[1].x - (math.abs(cannons[1].destX-cannons[1].x)/5) | |||
| end | |||
| end | |||
| @@ -0,0 +1,143 @@ | |||
| level7 = Class{} | |||
| local levelLoaded = false | |||
| local M = {} | |||
| function level7.load() | |||
| shipsleft = 1 | |||
| local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||
| planetsleft = 3 | |||
| gameStatus = "setup" | |||
| playbutts = {} | |||
| thrusterMax = 75 | |||
| firstShip.fuel = 75 | |||
| guibutts = {} | |||
| VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2 | |||
| explosions = {} | |||
| shipIsHit = false | |||
| guimenu = mainMenu() | |||
| reachedGoal = false | |||
| lvlbase = base(1400, WINDOW_HEIGHT/2) | |||
| levelLoaded = true | |||
| attackTimer = 5 | |||
| table.insert(playbutts, menu:addButton("Return to setup", function() | |||
| gameStatus = "setup" | |||
| levelgeneral.reset() | |||
| end )) | |||
| table.insert(guibutts, menu:addButton("Release brake!", function () | |||
| if shipsleft == 0 then | |||
| selectedItem = "none" | |||
| gameStatus = "play" | |||
| end | |||
| end | |||
| )) | |||
| table.insert(guibutts, menu:addButton("To menu", function () | |||
| levelgeneral.goBack() | |||
| end)) | |||
| table.insert(cannons, enemy(10000, 100, false, 3, 5)) | |||
| table.insert(cannons, enemy(10000, 700, false, 3, 4)) | |||
| table.insert(planets, planet(1000, -100, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 0, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 100, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 200, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 300, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 400, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 500, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 600, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 700, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 800, 50, 0.3, asteroidImage, "nodelete")) | |||
| end | |||
| function level7.hint() | |||
| GUIDraw("left") | |||
| love.graphics.setFont(tinyfont) | |||
| if (VCAM.x > WINDOW_WIDTH/2) then | |||
| if love.keyboard.isDown('a') then | |||
| love.graphics.setColor(1,0,0,1) | |||
| end | |||
| love.graphics.print("←[A]",10,50) | |||
| end | |||
| love.graphics.setColor(1,1,1,1) | |||
| if (VCAM.x < WINDOW_WIDTH*2) then | |||
| if love.keyboard.isDown('d') then | |||
| love.graphics.setColor(1,0,0,1) | |||
| end | |||
| love.graphics.print("[D]→",100,50) | |||
| end | |||
| love.graphics.setColor(1,1,1,1) | |||
| end | |||
| function level7.reset() | |||
| firstShip:reset() | |||
| for i in ipairs(planets) do | |||
| if not planets[i].deletable then | |||
| table.remove(planets, i) | |||
| end | |||
| end | |||
| table.insert(planets, planet(1000, -100, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 0, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 100, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 200, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 300, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 400, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 500, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 600, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 700, 50, 0.3, asteroidImage, "nodelete")) | |||
| table.insert(planets, planet(1000, 800, 50, 0.3, asteroidImage, "nodelete")) | |||
| local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||
| shipsleft = 1 | |||
| projectiles = {} | |||
| for i in ipairs(cannons) do | |||
| cannons[i].x = 100000 | |||
| cannons[i].destX = 100000 | |||
| cannons[i].appeared = false | |||
| end | |||
| cannons[1].appeartimer = 5 | |||
| cannons[2].appeartimer = 4 | |||
| firstShip.fuel = 75 | |||
| shipIsHit = false | |||
| attackTimer = 5 | |||
| end | |||
| function level7.bonusUpdate(dt) | |||
| if not reachedGoal then | |||
| for i in ipairs(cannons) do | |||
| cannons[i]:time(dt) | |||
| cannons[i].x = cannons[i].x - (math.abs(cannons[i].destX-cannons[i].x)/5) | |||
| if cannons[i].appeartimer <= 0 then | |||
| cannons[i].destX = 1200 | |||
| cannons[i]:update(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)) | |||
| cannons[i].appeared = true | |||
| end | |||
| end | |||
| end | |||
| for i in ipairs(projectiles) do | |||
| projectiles[i]:update(dt) | |||
| end | |||
| for i in ipairs(projectiles) do | |||
| if projectiles[i].killed then | |||
| table.remove(projectiles, i) | |||
| --print("killing") | |||
| end | |||
| end | |||
| end | |||
| end | |||
| function level7.GUIControl() | |||
| if (love.keyboard.isDown('a') and VCAM.x > WINDOW_WIDTH/2) then | |||
| VCAM.x = VCAM.x - 10 | |||
| end | |||
| if (love.keyboard.isDown('d')) then | |||
| VCAM.x = VCAM.x + 10 | |||
| end | |||
| end | |||
| function level7.goBack() | |||
| levelgeneral.goBack() | |||
| end | |||
| return level7 | |||
| @@ -85,27 +85,33 @@ function levelgeneral.draw() | |||
| projectiles[i]:draw(dt) | |||
| end | |||
| for i, explosion in ipairs(explosions) do | |||
| if shipIsHit then | |||
| explosion:render() | |||
| else | |||
| explosion:render("special") | |||
| end | |||
| --print("exploding") | |||
| end | |||
| if reachedGoal then | |||
| if frame <= WINDOW_WIDTH*1.1 then | |||
| stopMusic() | |||
| sounds["finish"]:play() | |||
| love.graphics.setColor(1,1,1,1) | |||
| love.graphics.circle("fill", firstShip.x, firstShip.y, frame) | |||
| end | |||
| if frame > WINDOW_WIDTH*1.1 then | |||
| love.graphics.clear(0,0,0,1) | |||
| love.graphics.setColor(30/255, 30/255, 30/255, 1) | |||
| if frame < WINDOW_WIDTH then | |||
| stopMusic() | |||
| sounds["finish"]:play() | |||
| love.graphics.circle("fill", firstShip.x, firstShip.y, WINDOW_WIDTH - frame) | |||
| love.graphics.setColor(1, 1, 1, 1) | |||
| if frame-WINDOW_WIDTH*1.1 < WINDOW_WIDTH then | |||
| love.graphics.circle("fill", firstShip.x, firstShip.y, WINDOW_WIDTH - (frame - WINDOW_WIDTH*1.1)) | |||
| end | |||
| end | |||
| frame = frame + 20 | |||
| frame = frame + 40 | |||
| 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() | |||
| camera:draw() | |||
| @@ -140,6 +146,7 @@ function levelgeneral.goBack() | |||
| lvlbase = nil | |||
| gameStatus = "setup" | |||
| firstShip.path = {} | |||
| cannons = {} | |||
| levelLoaded = false | |||
| for k in pairs(planets) do | |||
| planets[k] = nil | |||
| @@ -2,6 +2,15 @@ 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 | |||
| @@ -72,9 +81,10 @@ function practice.update(dt) | |||
| table.remove(projectiles, i) | |||
| --print("killing") | |||
| end | |||
| end | |||
| if math.sqrt(firstShip.dx^2 + firstShip.dy^2) < 40 then | |||
| currentScore = currentScore + math.sqrt(firstShip.dx^2 + firstShip.dy^2) | |||
| end | |||
| currentScore = currentScore + math.sqrt(firstShip.dx^2 + firstShip.dy^2) | |||
| else | |||
| camera:follow(VCAM.x, VCAM.y) | |||
| end | |||
| @@ -96,11 +106,13 @@ function practice.draw() | |||
| projectiles[i]:draw(dt) | |||
| end | |||
| --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30) | |||
| if shipIsHit then | |||
| for i, explosion in ipairs(explosions) do | |||
| for i, explosion in ipairs(explosions) do | |||
| if shipIsHit then | |||
| explosion:render() | |||
| --print("exploding") | |||
| else | |||
| explosion:render("special") | |||
| end | |||
| --print("exploding") | |||
| end | |||
| camera:detach() | |||
| @@ -133,6 +145,7 @@ function practice.goBack() | |||
| end | |||
| function practice.reset() | |||
| firstShip:reset() | |||
| camera.scale = 1 | |||
| projectiles = {} | |||
| shipsleft = 1 | |||
| if currentScore > saveData.score then | |||
| @@ -46,6 +46,14 @@ table.insert(levels, menu:addButton("Level 2", function () | |||
| currentLevel = 6 | |||
| end | |||
| end )) | |||
| table.insert(levels, menu:addButton("Level 7", function () | |||
| if saveData.levelsBeaten > 5 then | |||
| menuLoaded = false | |||
| objReset() | |||
| gameState = "levelgeneral" | |||
| currentLevel = 7 | |||
| end | |||
| end )) | |||
| table.insert(levels, menu:addButton("Go Back", function () | |||
| @@ -51,7 +51,8 @@ function GUIDraw(mode) | |||
| if love.keyboard.mouseisReleased then | |||
| love.keyboard.mouseisReleased = false | |||
| if #explosions == 0 then | |||
| table.insert(explosions, explosion(0, my, 100, {1,1,1,1})) | |||
| local zerox, zeroy = camera:toWorldCoords(0, 0) | |||
| table.insert(explosions, explosion(zerox, my, 100, {1,1,1,1})) | |||
| explosions[1].type = 1 | |||
| end | |||
| @@ -81,9 +82,11 @@ function GUIDraw(mode) | |||
| if love.keyboard.mouseisReleased then | |||
| love.keyboard.mouseisReleased = false | |||
| if #explosions == 0 then | |||
| table.insert(explosions, explosion(0, my, 100, {1,1,1,1})) | |||
| local zerox, zeroy = camera:toWorldCoords(0, 0) | |||
| table.insert(explosions, explosion(zerox, my, 100, {1,1,1,1})) | |||
| explosions[1].type = 1 | |||
| end | |||
| sounds["appear"]:play() | |||
| firstShip.destX = 250 | |||
| firstShip.y = vmy | |||