| @@ -1,6 +1,8 @@ | |||
| function buttonClutter() | |||
| table.insert(buttons, menu:addButton("Practice", | |||
| function() | |||
| menuLoaded = false | |||
| objReset() | |||
| gameState = "practice" | |||
| end)) | |||
| table.insert(buttons, menu:addButton("Levels", | |||
| @@ -2,7 +2,7 @@ planet = Class{} | |||
| 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.y = y | |||
| self.mass = mass | |||
| @@ -11,6 +11,11 @@ self.w = img:getWidth() | |||
| self.image = img | |||
| self.angle = 0 | |||
| self.color = {1,1,1,1} | |||
| if arg == "nodelete" then | |||
| self.deletable = false | |||
| else | |||
| self.deletable = true | |||
| end | |||
| end | |||
| function planet:update(dt) | |||
| @@ -21,14 +21,16 @@ function level1.update(dt) | |||
| level1.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 () | |||
| level1.goBack() | |||
| end)) | |||
| table.insert(planets, planet(700, 200, 50, 0.3, planetImage)) | |||
| table.insert(planets, planet(700, 200, 50, 0.3, planetImage, "nodelete")) | |||
| end | |||
| if reachedGoal then | |||
| @@ -40,7 +42,9 @@ function level1.update(dt) | |||
| level1.goBack() | |||
| end | |||
| camera:update(dt) | |||
| if lvlbase ~= nil then | |||
| lvlbase:update(dt) | |||
| end | |||
| --print(camera.x .. " " .. camera.y) | |||
| for i, explosion in ipairs(explosions) do | |||
| explosion:update(dt) | |||
| @@ -76,7 +80,9 @@ function level1.draw() | |||
| love.graphics.setColor(1,1,1,1) | |||
| camera:attach() | |||
| firstShip:draw() | |||
| if lvlbase ~= nil then | |||
| lvlbase:draw() | |||
| end | |||
| for i in ipairs(planets) do | |||
| planets[i]:draw(dt) | |||
| end | |||
| @@ -103,12 +109,14 @@ function level1.draw() | |||
| end | |||
| function level1.goBack() | |||
| level1.reset() | |||
| gameStatus = "setup" | |||
| firstShip.path = {} | |||
| levelLoaded = false | |||
| for k in pairs(planets) do | |||
| planets[k] = nil | |||
| end | |||
| lvlbase = nil | |||
| gameState = "selectlv" | |||
| end | |||
| function level1.reset() | |||
| @@ -21,14 +21,16 @@ function level2.update(dt) | |||
| level2.reset() | |||
| end )) | |||
| table.insert(guibutts, menu:addButton("Release brake!", function () | |||
| selectedItem = "none" | |||
| gameStatus = "play" | |||
| if shipsleft == 0 then | |||
| selectedItem = "none" | |||
| gameStatus = "play" | |||
| end | |||
| end | |||
| )) | |||
| table.insert(guibutts, menu:addButton("To menu", function () | |||
| level2.goBack() | |||
| end)) | |||
| table.insert(planets, planet(700, 500, 50, 0.3, planetImage)) | |||
| table.insert(planets, planet(700, 500, 50, 0.3, planetImage, "nodelete")) | |||
| end | |||
| if reachedGoal then | |||
| @@ -40,7 +42,9 @@ function level2.update(dt) | |||
| level2.goBack() | |||
| end | |||
| camera:update(dt) | |||
| lvlbase:update(dt) | |||
| if lvlbase ~= nil then | |||
| lvlbase:update(dt) | |||
| end | |||
| --print(camera.x .. " " .. camera.y) | |||
| for i, explosion in ipairs(explosions) do | |||
| explosion:update(dt) | |||
| @@ -76,7 +80,9 @@ function level2.draw() | |||
| love.graphics.setColor(1,1,1,1) | |||
| camera:attach() | |||
| firstShip:draw() | |||
| lvlbase:draw() | |||
| if lvlbase ~= nil then | |||
| lvlbase:draw() | |||
| end | |||
| for i in ipairs(planets) do | |||
| planets[i]:draw(dt) | |||
| end | |||
| @@ -103,6 +109,7 @@ function level2.draw() | |||
| end | |||
| function level2.goBack() | |||
| level2.reset() | |||
| lvlbase = nil | |||
| gameStatus = "setup" | |||
| firstShip.path = {} | |||
| levelLoaded = false | |||
| @@ -1,12 +1,36 @@ | |||
| menu = Class{} | |||
| local M = {} | |||
| menuLoaded = false | |||
| 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 | |||
| animationSecsLeft = animationSecsLeft - 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 | |||
| function menu.draw(dt) | |||
| firstShip:draw() | |||
| for i in ipairs(planets) do | |||
| planets[i]:draw(dt) | |||
| end | |||
| if animationSecsLeft > 0 then | |||
| love.graphics.setColor(1,1,1,1-1/(animationSecsLeft+0.000001)) | |||
| love.graphics.draw(logo, 0,0) | |||
| @@ -18,8 +18,10 @@ function practice.update(dt) | |||
| practice.reset() | |||
| end )) | |||
| table.insert(guibutts, menu:addButton("Release brake!", function () | |||
| selectedItem = "none" | |||
| gameStatus = "play" | |||
| if shipsleft == 0 then | |||
| selectedItem = "none" | |||
| gameStatus = "play" | |||
| end | |||
| end | |||
| )) | |||
| table.insert(guibutts, menu:addButton("To menu", function () | |||
| @@ -1,10 +1,14 @@ | |||
| selectlv = Class{} | |||
| levels = {} | |||
| table.insert(levels, menu:addButton("Level 1", function () | |||
| menuLoaded = false | |||
| objReset() | |||
| gameState = "level1" | |||
| end )) | |||
| table.insert(levels, menu:addButton("Level 2", function () | |||
| if saveData.levelsBeaten > 0 then | |||
| menuLoaded = false | |||
| objReset() | |||
| gameState = "level2" | |||
| end | |||
| end )) | |||
| @@ -17,10 +21,32 @@ table.insert(levels, menu:addButton("Go Back", function () | |||
| end )) | |||
| local M = {} | |||
| 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 | |||
| 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") | |||
| end | |||
| @@ -61,3 +61,7 @@ function love.mousereleased(x, y, button) | |||
| end | |||
| function objReset() | |||
| firstShip:reset() | |||
| planets = {} | |||
| end | |||
| @@ -158,23 +158,25 @@ function GUIDraw(mode) | |||
| 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 | |||
| @@ -187,9 +189,7 @@ function GUIDraw(mode) | |||
| --REMOVE TOOL | |||
| --START BUTTON | |||
| if shipsleft == 0 then | |||
| guimenu:butt(guibutts, WINDOW_WIDTH, WINDOW_HEIGHT, menuX + 200, WINDOW_HEIGHT-100, 40, WINDOW_WIDTH/3.7) | |||
| end | |||
| --START BUTTON | |||
| love.window.setTitle(selectedItem) | |||
| end | |||