@@ -1,9 +1,8 @@ | |||||
level1 = Class{} | level1 = Class{} | ||||
local levelLoaded = false | local levelLoaded = false | ||||
local M = {} | local M = {} | ||||
function level1.update(dt) | |||||
if not levelLoaded then | |||||
shipsleft = 1 | |||||
function level1.load() | |||||
shipsleft = 1 | |||||
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | ||||
planetsleft = 3 | planetsleft = 3 | ||||
gameStatus = "setup" | gameStatus = "setup" | ||||
@@ -31,93 +30,6 @@ function level1.update(dt) | |||||
level1.goBack() | level1.goBack() | ||||
end)) | end)) | ||||
table.insert(planets, planet(700, 200, 50, 0.3, planetImage, "nodelete")) | table.insert(planets, planet(700, 200, 50, 0.3, planetImage, "nodelete")) | ||||
end | |||||
if reachedGoal then | |||||
if saveData.levelsBeaten < 1 then | |||||
saveData.levelsBeaten = 1 | |||||
end | |||||
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
love.filesystem.write("save", serialize(saveData)) | |||||
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) | |||||
if explosion.killed then | |||||
table.remove(explosions, i) | |||||
gameStatus = "setup" | |||||
level1.reset() | |||||
end | |||||
end | |||||
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 | |||||
end | |||||
firstShip:update(dt) | |||||
for i in ipairs(planets) do | |||||
planets[i]:update(dt) | |||||
end | |||||
else | |||||
camera:follow(VCAM.x, VCAM.y) | |||||
end | |||||
level1.GUIControl() | |||||
end | |||||
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 | |||||
--love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30) | |||||
if shipIsHit then | |||||
for i, explosion in ipairs(explosions) do | |||||
explosion:render() | |||||
--print("exploding") | |||||
end | |||||
end | |||||
camera:detach() | |||||
camera:draw() | |||||
if gameStatus == "setup" then | |||||
GUIDraw("left") | |||||
elseif gameStatus == "play" then | |||||
guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3) | |||||
end | |||||
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 | end | ||||
function level1.reset() | function level1.reset() | ||||
firstShip:reset() | firstShip:reset() | ||||
@@ -1,122 +1,35 @@ | |||||
level2 = Class{} | level2 = Class{} | ||||
local levelLoaded = false | local levelLoaded = false | ||||
local M = {} | local M = {} | ||||
function level2.update(dt) | |||||
if not levelLoaded then | |||||
shipsleft = 1 | |||||
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||||
planetsleft = 3 | |||||
function level2.load() | |||||
shipsleft = 1 | |||||
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||||
planetsleft = 3 | |||||
gameStatus = "setup" | |||||
playbutts = {} | |||||
guibutts = {} | |||||
VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2 | |||||
explosions = {} | |||||
shipIsHit = false | |||||
guimenu = mainMenu() | |||||
reachedGoal = false | |||||
lvlbase = base(1800, 500) | |||||
levelLoaded = true | |||||
table.insert(playbutts, menu:addButton("Return to setup", function() | |||||
gameStatus = "setup" | gameStatus = "setup" | ||||
playbutts = {} | |||||
guibutts = {} | |||||
VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2 | |||||
explosions = {} | |||||
shipIsHit = false | |||||
guimenu = mainMenu() | |||||
reachedGoal = false | |||||
lvlbase = base(1800, 500) | |||||
levelLoaded = true | |||||
table.insert(playbutts, menu:addButton("Return to setup", function() | |||||
gameStatus = "setup" | |||||
level2.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 () | |||||
level2.goBack() | |||||
end)) | |||||
table.insert(planets, planet(700, 500, 50, 0.3, planetImage, "nodelete")) | |||||
level2.reset() | |||||
end )) | |||||
table.insert(guibutts, menu:addButton("Release brake!", function () | |||||
if shipsleft == 0 then | |||||
selectedItem = "none" | |||||
gameStatus = "play" | |||||
end | |||||
end | end | ||||
if reachedGoal then | |||||
if saveData.levelsBeaten < 2 then | |||||
saveData.levelsBeaten = 2 | |||||
end | |||||
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
love.filesystem.write("save", serialize(saveData)) | |||||
)) | |||||
table.insert(guibutts, menu:addButton("To menu", function () | |||||
level2.goBack() | level2.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) | |||||
if explosion.killed then | |||||
table.remove(explosions, i) | |||||
gameStatus = "setup" | |||||
level2.reset() | |||||
end | |||||
end | |||||
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 | |||||
end | |||||
firstShip:update(dt) | |||||
for i in ipairs(planets) do | |||||
planets[i]:update(dt) | |||||
end | |||||
else | |||||
camera:follow(VCAM.x, VCAM.y) | |||||
end | |||||
level2.GUIControl() | |||||
end | |||||
function level2.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 | |||||
--love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30) | |||||
if shipIsHit then | |||||
for i, explosion in ipairs(explosions) do | |||||
explosion:render() | |||||
--print("exploding") | |||||
end | |||||
end | |||||
camera:detach() | |||||
camera:draw() | |||||
if gameStatus == "setup" then | |||||
GUIDraw("left") | |||||
elseif gameStatus == "play" then | |||||
guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3) | |||||
end | |||||
end | |||||
function level2.goBack() | |||||
level2.reset() | |||||
lvlbase = nil | |||||
gameStatus = "setup" | |||||
firstShip.path = {} | |||||
levelLoaded = false | |||||
for k in pairs(planets) do | |||||
planets[k] = nil | |||||
end | |||||
gameState = "selectlv" | |||||
end)) | |||||
table.insert(planets, planet(700, 500, 50, 0.3, planetImage, "nodelete")) | |||||
end | end | ||||
function level2.reset() | function level2.reset() | ||||
firstShip:reset() | firstShip:reset() | ||||
@@ -1,125 +1,39 @@ | |||||
level3 = Class{} | level3 = Class{} | ||||
local levelLoaded = false | local levelLoaded = false | ||||
local M = {} | local M = {} | ||||
function level3.update(dt) | |||||
if not levelLoaded then | |||||
shipsleft = 1 | |||||
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||||
planetsleft = 3 | |||||
function level3.load() | |||||
shipsleft = 1 | |||||
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||||
planetsleft = 3 | |||||
gameStatus = "setup" | |||||
playbutts = {} | |||||
guibutts = {} | |||||
VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2 | |||||
explosions = {} | |||||
shipIsHit = false | |||||
guimenu = mainMenu() | |||||
reachedGoal = false | |||||
lvlbase = base(900, 300) | |||||
levelLoaded = true | |||||
table.insert(playbutts, menu:addButton("Return to setup", function() | |||||
gameStatus = "setup" | gameStatus = "setup" | ||||
playbutts = {} | |||||
guibutts = {} | |||||
VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2 | |||||
explosions = {} | |||||
shipIsHit = false | |||||
guimenu = mainMenu() | |||||
reachedGoal = false | |||||
lvlbase = base(900, 300) | |||||
levelLoaded = true | |||||
table.insert(playbutts, menu:addButton("Return to setup", function() | |||||
gameStatus = "setup" | |||||
level3.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 () | |||||
level3.goBack() | |||||
end)) | |||||
table.insert(planets, planet(900, 400, 50, 0.3, planetImage, "nodelete")) | |||||
table.insert(planets, planet(700, 300, 50, 0.3, planetImage, "nodelete")) | |||||
table.insert(planets, planet(900, 200, 50, 0.3, planetImage, "nodelete")) | |||||
end | |||||
if reachedGoal then | |||||
if saveData.levelsBeaten < 3 then | |||||
saveData.levelsBeaten = 3 | |||||
end | |||||
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
love.filesystem.write("save", serialize(saveData)) | |||||
level3.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) | |||||
if explosion.killed then | |||||
table.remove(explosions, i) | |||||
gameStatus = "setup" | |||||
level3.reset() | |||||
end | |||||
end | |||||
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})) | |||||
levelgeneral.reset() | |||||
end )) | |||||
table.insert(guibutts, menu:addButton("Release brake!", function () | |||||
if shipsleft == 0 then | |||||
selectedItem = "none" | |||||
gameStatus = "play" | |||||
end | end | ||||
end | |||||
firstShip:update(dt) | |||||
for i in ipairs(planets) do | |||||
planets[i]:update(dt) | |||||
end | |||||
else | |||||
camera:follow(VCAM.x, VCAM.y) | |||||
end | |||||
level3.GUIControl() | |||||
end | |||||
)) | |||||
table.insert(guibutts, menu:addButton("To menu", function () | |||||
levelgeneral.goBack() | |||||
end)) | |||||
table.insert(planets, planet(900, 400, 50, 0.3, planetImage, "nodelete")) | |||||
table.insert(planets, planet(700, 300, 50, 0.3, planetImage, "nodelete")) | |||||
table.insert(planets, planet(900, 200, 50, 0.3, planetImage, "nodelete")) | |||||
end | end | ||||
function level3.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 | |||||
--love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30) | |||||
if shipIsHit then | |||||
for i, explosion in ipairs(explosions) do | |||||
explosion:render() | |||||
--print("exploding") | |||||
end | |||||
end | |||||
camera:detach() | |||||
camera:draw() | |||||
if gameStatus == "setup" then | |||||
GUIDraw("left") | |||||
elseif gameStatus == "play" then | |||||
guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3) | |||||
end | |||||
end | |||||
function level3.goBack() | |||||
level3.reset() | |||||
lvlbase = nil | |||||
gameStatus = "setup" | |||||
firstShip.path = {} | |||||
levelLoaded = false | |||||
for k in pairs(planets) do | |||||
planets[k] = nil | |||||
end | |||||
gameState = "selectlv" | |||||
end | |||||
function level3.reset() | function level3.reset() | ||||
firstShip:reset() | firstShip:reset() | ||||
for k in pairs(planets) do | for k in pairs(planets) do | ||||
@@ -0,0 +1,58 @@ | |||||
level4 = Class{} | |||||
local levelLoaded = false | |||||
local M = {} | |||||
function level4.load() | |||||
shipsleft = 1 | |||||
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||||
planetsleft = 3 | |||||
gameStatus = "setup" | |||||
playbutts = {} | |||||
guibutts = {} | |||||
VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2 | |||||
explosions = {} | |||||
shipIsHit = false | |||||
guimenu = mainMenu() | |||||
reachedGoal = false | |||||
lvlbase = base(400, 300) | |||||
levelLoaded = true | |||||
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(planets, planet(900, 400, 50, 0.3, planetImage, "nodelete")) | |||||
table.insert(planets, planet(700, 300, 50, 0.3, planetImage, "nodelete")) | |||||
table.insert(planets, planet(900, 200, 50, 0.3, planetImage, "nodelete")) | |||||
end | |||||
function level4.reset() | |||||
firstShip:reset() | |||||
for k in pairs(planets) do | |||||
if planets[k].deletable then | |||||
planets[k] = nil | |||||
end | |||||
end | |||||
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||||
shipsleft = 1 | |||||
shipIsHit = false | |||||
planetsleft = 3 | |||||
end | |||||
function level4.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 | |||||
return level4 | |||||
@@ -0,0 +1,102 @@ | |||||
levelgeneral = Class{} | |||||
local levelLoaded = false | |||||
local M = {} | |||||
function levelgeneral.update(dt) | |||||
if not levelLoaded then | |||||
level = require("levels/level" .. currentLevel) | |||||
level.load() | |||||
levelLoaded = true | |||||
end | |||||
if reachedGoal then | |||||
if saveData.levelsBeaten < currentLevel then | |||||
saveData.levelsBeaten = currentLevel | |||||
end | |||||
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
love.filesystem.write("save", serialize(saveData)) | |||||
levelgeneral.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) | |||||
if explosion.killed then | |||||
table.remove(explosions, i) | |||||
gameStatus = "setup" | |||||
levelgeneral.reset() | |||||
end | |||||
end | |||||
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 | |||||
end | |||||
firstShip:update(dt) | |||||
for i in ipairs(planets) do | |||||
planets[i]:update(dt) | |||||
end | |||||
else | |||||
camera:follow(VCAM.x, VCAM.y) | |||||
end | |||||
levelgeneral.GUIControl() | |||||
end | |||||
function levelgeneral.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 | |||||
--love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30) | |||||
if shipIsHit then | |||||
for i, explosion in ipairs(explosions) do | |||||
explosion:render() | |||||
--print("exploding") | |||||
end | |||||
end | |||||
camera:detach() | |||||
camera:draw() | |||||
if gameStatus == "setup" then | |||||
GUIDraw("left") | |||||
elseif gameStatus == "play" then | |||||
guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3) | |||||
end | |||||
end | |||||
function levelgeneral.goBack() | |||||
levelgeneral.reset() | |||||
lvlbase = nil | |||||
gameStatus = "setup" | |||||
firstShip.path = {} | |||||
levelLoaded = false | |||||
for k in pairs(planets) do | |||||
planets[k] = nil | |||||
end | |||||
gameState = "selectlv" | |||||
end | |||||
function levelgeneral.reset() | |||||
level.reset() | |||||
end | |||||
function levelgeneral.GUIControl() | |||||
level.GUIControl() | |||||
end | |||||
return levelgeneral | |||||
@@ -3,20 +3,23 @@ levels = {} | |||||
table.insert(levels, menu:addButton("Level 1", function () | table.insert(levels, menu:addButton("Level 1", function () | ||||
menuLoaded = false | menuLoaded = false | ||||
objReset() | objReset() | ||||
gameState = "level1" | |||||
gameState = "levelgeneral" | |||||
currentLevel = 1 | |||||
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 | menuLoaded = false | ||||
objReset() | objReset() | ||||
gameState = "level2" | |||||
gameState = "levelgeneral" | |||||
currentLevel = 2 | |||||
end | end | ||||
end )) | end )) | ||||
table.insert(levels, menu:addButton("Level 3", function () | table.insert(levels, menu:addButton("Level 3", function () | ||||
if saveData.levelsBeaten > 1 then | if saveData.levelsBeaten > 1 then | ||||
menuLoaded = false | menuLoaded = false | ||||
objReset() | objReset() | ||||
gameState = "level3" | |||||
gameState = "levelgeneral" | |||||
currentLevel = 3 | |||||
end | end | ||||
end )) | end )) | ||||
@@ -12,6 +12,8 @@ WINDOW_HEIGHT = 720 | |||||
OFFSET_X = 0 | OFFSET_X = 0 | ||||
OFFSET_Y = 0 | OFFSET_Y = 0 | ||||
currentLevel = 0 | |||||
saveData = { | saveData = { | ||||
levelsBeaten = 0 | levelsBeaten = 0 | ||||
} | } | ||||