| @@ -1,6 +1,8 @@ | |||||
| function buttonClutter() | function buttonClutter() | ||||
| table.insert(buttons, menu:addButton("Practice", | table.insert(buttons, menu:addButton("Practice", | ||||
| function() | function() | ||||
| menuLoaded = false | |||||
| objReset() | |||||
| gameState = "practice" | gameState = "practice" | ||||
| end)) | end)) | ||||
| table.insert(buttons, menu:addButton("Levels", | table.insert(buttons, menu:addButton("Levels", | ||||
| @@ -2,7 +2,7 @@ planet = Class{} | |||||
| G = 6.67e-1 | G = 6.67e-1 | ||||
| function planet:init(x, y, mass, radius, img) | |||||
| function planet:init(x, y, mass, radius, img, arg) | |||||
| self.x = x | self.x = x | ||||
| self.y = y | self.y = y | ||||
| self.mass = mass | self.mass = mass | ||||
| @@ -11,6 +11,11 @@ self.w = img:getWidth() | |||||
| self.image = img | self.image = img | ||||
| self.angle = 0 | self.angle = 0 | ||||
| self.color = {1,1,1,1} | self.color = {1,1,1,1} | ||||
| if arg == "nodelete" then | |||||
| self.deletable = false | |||||
| else | |||||
| self.deletable = true | |||||
| end | |||||
| end | end | ||||
| function planet:update(dt) | function planet:update(dt) | ||||
| @@ -21,14 +21,16 @@ function level1.update(dt) | |||||
| level1.reset() | level1.reset() | ||||
| end )) | end )) | ||||
| table.insert(guibutts, menu:addButton("Release brake!", function () | table.insert(guibutts, menu:addButton("Release brake!", function () | ||||
| if shipsleft == 0 then | |||||
| selectedItem = "none" | selectedItem = "none" | ||||
| gameStatus = "play" | gameStatus = "play" | ||||
| end | |||||
| end | end | ||||
| )) | )) | ||||
| table.insert(guibutts, menu:addButton("To menu", function () | table.insert(guibutts, menu:addButton("To menu", function () | ||||
| level1.goBack() | level1.goBack() | ||||
| end)) | end)) | ||||
| table.insert(planets, planet(700, 200, 50, 0.3, planetImage)) | |||||
| table.insert(planets, planet(700, 200, 50, 0.3, planetImage, "nodelete")) | |||||
| end | end | ||||
| if reachedGoal then | if reachedGoal then | ||||
| @@ -40,7 +42,9 @@ function level1.update(dt) | |||||
| level1.goBack() | level1.goBack() | ||||
| end | end | ||||
| camera:update(dt) | camera:update(dt) | ||||
| if lvlbase ~= nil then | |||||
| lvlbase:update(dt) | lvlbase:update(dt) | ||||
| end | |||||
| --print(camera.x .. " " .. camera.y) | --print(camera.x .. " " .. camera.y) | ||||
| for i, explosion in ipairs(explosions) do | for i, explosion in ipairs(explosions) do | ||||
| explosion:update(dt) | explosion:update(dt) | ||||
| @@ -76,7 +80,9 @@ function level1.draw() | |||||
| love.graphics.setColor(1,1,1,1) | love.graphics.setColor(1,1,1,1) | ||||
| camera:attach() | camera:attach() | ||||
| firstShip:draw() | firstShip:draw() | ||||
| if lvlbase ~= nil then | |||||
| lvlbase:draw() | lvlbase:draw() | ||||
| end | |||||
| for i in ipairs(planets) do | for i in ipairs(planets) do | ||||
| planets[i]:draw(dt) | planets[i]:draw(dt) | ||||
| end | end | ||||
| @@ -103,12 +109,14 @@ function level1.draw() | |||||
| end | end | ||||
| function level1.goBack() | function level1.goBack() | ||||
| level1.reset() | level1.reset() | ||||
| gameStatus = "setup" | gameStatus = "setup" | ||||
| firstShip.path = {} | firstShip.path = {} | ||||
| levelLoaded = false | levelLoaded = false | ||||
| for k in pairs(planets) do | for k in pairs(planets) do | ||||
| planets[k] = nil | planets[k] = nil | ||||
| end | end | ||||
| lvlbase = nil | |||||
| gameState = "selectlv" | gameState = "selectlv" | ||||
| end | end | ||||
| function level1.reset() | function level1.reset() | ||||
| @@ -21,14 +21,16 @@ function level2.update(dt) | |||||
| level2.reset() | level2.reset() | ||||
| end )) | end )) | ||||
| table.insert(guibutts, menu:addButton("Release brake!", function () | table.insert(guibutts, menu:addButton("Release brake!", function () | ||||
| selectedItem = "none" | |||||
| gameStatus = "play" | |||||
| if shipsleft == 0 then | |||||
| selectedItem = "none" | |||||
| gameStatus = "play" | |||||
| end | |||||
| end | end | ||||
| )) | )) | ||||
| table.insert(guibutts, menu:addButton("To menu", function () | table.insert(guibutts, menu:addButton("To menu", function () | ||||
| level2.goBack() | level2.goBack() | ||||
| end)) | end)) | ||||
| table.insert(planets, planet(700, 500, 50, 0.3, planetImage)) | |||||
| table.insert(planets, planet(700, 500, 50, 0.3, planetImage, "nodelete")) | |||||
| end | end | ||||
| if reachedGoal then | if reachedGoal then | ||||
| @@ -40,7 +42,9 @@ function level2.update(dt) | |||||
| level2.goBack() | level2.goBack() | ||||
| end | end | ||||
| camera:update(dt) | camera:update(dt) | ||||
| lvlbase:update(dt) | |||||
| if lvlbase ~= nil then | |||||
| lvlbase:update(dt) | |||||
| end | |||||
| --print(camera.x .. " " .. camera.y) | --print(camera.x .. " " .. camera.y) | ||||
| for i, explosion in ipairs(explosions) do | for i, explosion in ipairs(explosions) do | ||||
| explosion:update(dt) | explosion:update(dt) | ||||
| @@ -76,7 +80,9 @@ function level2.draw() | |||||
| love.graphics.setColor(1,1,1,1) | love.graphics.setColor(1,1,1,1) | ||||
| camera:attach() | camera:attach() | ||||
| firstShip:draw() | firstShip:draw() | ||||
| lvlbase:draw() | |||||
| if lvlbase ~= nil then | |||||
| lvlbase:draw() | |||||
| end | |||||
| for i in ipairs(planets) do | for i in ipairs(planets) do | ||||
| planets[i]:draw(dt) | planets[i]:draw(dt) | ||||
| end | end | ||||
| @@ -103,6 +109,7 @@ function level2.draw() | |||||
| end | end | ||||
| function level2.goBack() | function level2.goBack() | ||||
| level2.reset() | level2.reset() | ||||
| lvlbase = nil | |||||
| gameStatus = "setup" | gameStatus = "setup" | ||||
| firstShip.path = {} | firstShip.path = {} | ||||
| levelLoaded = false | levelLoaded = false | ||||
| @@ -1,12 +1,36 @@ | |||||
| menu = Class{} | menu = Class{} | ||||
| local M = {} | local M = {} | ||||
| menuLoaded = false | |||||
| function menu.update(dt) | function menu.update(dt) | ||||
| if not menuLoaded then | |||||
| firstShip.x = -100 | |||||
| firstShip.speed = 10 | |||||
| firstShip.y = love.math.random(0, WINDOW_HEIGHT) | |||||
| menuLoaded = true | |||||
| table.insert(planets, planet(love.math.random(100, WINDOW_WIDTH-100), love.math.random(100, WINDOW_HEIGHT-100), 90000000, 0.3, love.graphics.newImage("entities/planet/planet.png"))) | |||||
| end | |||||
| for i in ipairs(planets) do | |||||
| planets[i]:update(dt) | |||||
| end | |||||
| if animationSecsLeft > 0 then | if animationSecsLeft > 0 then | ||||
| animationSecsLeft = animationSecsLeft - dt | animationSecsLeft = animationSecsLeft - dt | ||||
| end | end | ||||
| firstShip:update(dt) | |||||
| if shipIsHit then | |||||
| shipIsHit = false | |||||
| firstShip:reset() | |||||
| firstShip.x = -100 | |||||
| firstShip.speed = 10 | |||||
| firstShip.y = love.math.random(0, WINDOW_HEIGHT) | |||||
| print("ship is hit") | |||||
| end | |||||
| end | end | ||||
| function menu.draw(dt) | function menu.draw(dt) | ||||
| firstShip:draw() | |||||
| for i in ipairs(planets) do | |||||
| planets[i]:draw(dt) | |||||
| end | |||||
| if animationSecsLeft > 0 then | if animationSecsLeft > 0 then | ||||
| love.graphics.setColor(1,1,1,1-1/(animationSecsLeft+0.000001)) | love.graphics.setColor(1,1,1,1-1/(animationSecsLeft+0.000001)) | ||||
| love.graphics.draw(logo, 0,0) | love.graphics.draw(logo, 0,0) | ||||
| @@ -18,8 +18,10 @@ function practice.update(dt) | |||||
| practice.reset() | practice.reset() | ||||
| end )) | end )) | ||||
| table.insert(guibutts, menu:addButton("Release brake!", function () | table.insert(guibutts, menu:addButton("Release brake!", function () | ||||
| selectedItem = "none" | |||||
| gameStatus = "play" | |||||
| if shipsleft == 0 then | |||||
| selectedItem = "none" | |||||
| gameStatus = "play" | |||||
| end | |||||
| end | end | ||||
| )) | )) | ||||
| table.insert(guibutts, menu:addButton("To menu", function () | table.insert(guibutts, menu:addButton("To menu", function () | ||||
| @@ -1,10 +1,14 @@ | |||||
| selectlv = Class{} | selectlv = Class{} | ||||
| levels = {} | levels = {} | ||||
| table.insert(levels, menu:addButton("Level 1", function () | table.insert(levels, menu:addButton("Level 1", function () | ||||
| menuLoaded = false | |||||
| objReset() | |||||
| gameState = "level1" | gameState = "level1" | ||||
| end )) | end )) | ||||
| table.insert(levels, menu:addButton("Level 2", function () | table.insert(levels, menu:addButton("Level 2", function () | ||||
| if saveData.levelsBeaten > 0 then | if saveData.levelsBeaten > 0 then | ||||
| menuLoaded = false | |||||
| objReset() | |||||
| gameState = "level2" | gameState = "level2" | ||||
| end | end | ||||
| end )) | end )) | ||||
| @@ -17,10 +21,32 @@ table.insert(levels, menu:addButton("Go Back", function () | |||||
| end )) | end )) | ||||
| local M = {} | local M = {} | ||||
| function selectlv.update(dt) | function selectlv.update(dt) | ||||
| if not menuLoaded then | |||||
| firstShip.x = -100 | |||||
| firstShip.speed = 10 | |||||
| firstShip.y = love.math.random(0, WINDOW_HEIGHT) | |||||
| menuLoaded = true | |||||
| table.insert(planets, planet(love.math.random(100, WINDOW_WIDTH-100), love.math.random(100, WINDOW_HEIGHT-100), 90000000, 0.3, love.graphics.newImage("entities/planet/planet.png"))) | |||||
| end | |||||
| for i in ipairs(planets) do | |||||
| planets[i]:update(dt) | |||||
| end | |||||
| firstShip:update(dt) | |||||
| if shipIsHit then | |||||
| shipIsHit = false | |||||
| firstShip:reset() | |||||
| firstShip.x = -100 | |||||
| firstShip.speed = 10 | |||||
| firstShip.y = love.math.random(0, WINDOW_HEIGHT) | |||||
| print("ship is hit") | |||||
| end | |||||
| end | end | ||||
| function selectlv.draw(dt) | function selectlv.draw(dt) | ||||
| firstShip:draw() | |||||
| for i in ipairs(planets) do | |||||
| planets[i]:draw(dt) | |||||
| end | |||||
| menu:butt(levels, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 40, WINDOW_WIDTH/3, "beatenGreen") | menu:butt(levels, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 40, WINDOW_WIDTH/3, "beatenGreen") | ||||
| end | end | ||||
| @@ -61,3 +61,7 @@ function love.mousereleased(x, y, button) | |||||
| end | end | ||||
| function objReset() | |||||
| firstShip:reset() | |||||
| planets = {} | |||||
| end | |||||
| @@ -158,23 +158,25 @@ function GUIDraw(mode) | |||||
| for j in ipairs(planets) do | for j in ipairs(planets) do | ||||
| local hot = (vmx > planets[j].x-planets[j].w*0.3/2 and vmx < planets[j].x+planets[j].w*0.3 and vmy > planets[j].y-planets[j].w*0.3/2 and vmy < planets[j].y + planets[j].w*0.3) | |||||
| if hot then | |||||
| planets[j].color = {1,0,0,1} | |||||
| print("hot") | |||||
| else | |||||
| planets[j].color = {1,1,1,1} | |||||
| --print(mx .. " " .. my .. " " .. firstShip.x .. " " .. firstShip.y .. " " .. firstShip.width .. firstShip.height) | |||||
| end | |||||
| local pressed = love.keyboard.mouseisReleased | |||||
| if location == "android" then | |||||
| pressed = love.mouse.isDown(1) | |||||
| end | |||||
| if pressed and hot then | |||||
| love.keyboard.mouseisReleased = false | |||||
| table.remove(planets, j) | |||||
| planetsleft = planetsleft + 1 | |||||
| break | |||||
| if planets[j].deletable then | |||||
| local hot = (vmx > planets[j].x-planets[j].w*0.3/2 and vmx < planets[j].x+planets[j].w*0.3 and vmy > planets[j].y-planets[j].w*0.3/2 and vmy < planets[j].y + planets[j].w*0.3) | |||||
| if hot then | |||||
| planets[j].color = {1,0,0,1} | |||||
| print("hot") | |||||
| else | |||||
| planets[j].color = {1,1,1,1} | |||||
| --print(mx .. " " .. my .. " " .. firstShip.x .. " " .. firstShip.y .. " " .. firstShip.width .. firstShip.height) | |||||
| end | |||||
| local pressed = love.keyboard.mouseisReleased | |||||
| if location == "android" then | |||||
| pressed = love.mouse.isDown(1) | |||||
| end | |||||
| if pressed and hot then | |||||
| love.keyboard.mouseisReleased = false | |||||
| table.remove(planets, j) | |||||
| planetsleft = planetsleft + 1 | |||||
| break | |||||
| end | |||||
| end | end | ||||
| end | end | ||||
| end | end | ||||
| @@ -187,9 +189,7 @@ function GUIDraw(mode) | |||||
| --REMOVE TOOL | --REMOVE TOOL | ||||
| --START BUTTON | --START BUTTON | ||||
| if shipsleft == 0 then | |||||
| guimenu:butt(guibutts, WINDOW_WIDTH, WINDOW_HEIGHT, menuX + 200, WINDOW_HEIGHT-100, 40, WINDOW_WIDTH/3.7) | guimenu:butt(guibutts, WINDOW_WIDTH, WINDOW_HEIGHT, menuX + 200, WINDOW_HEIGHT-100, 40, WINDOW_WIDTH/3.7) | ||||
| end | |||||
| --START BUTTON | --START BUTTON | ||||
| love.window.setTitle(selectedItem) | love.window.setTitle(selectedItem) | ||||
| end | end | ||||