@@ -22,7 +22,7 @@ function planet:update(dt) | |||||
local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2) | local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2) | ||||
local gravitationalAttraction = G*self.mass/(distanceToShip^2) | local gravitationalAttraction = G*self.mass/(distanceToShip^2) | ||||
print((firstShip.x - self.x) .. " " .. (firstShip.y - self.y)) | |||||
--print((firstShip.x - self.x) .. " " .. (firstShip.y - self.y)) | |||||
self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x)) | self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x)) | ||||
if self.x < firstShip.x then | if self.x < firstShip.x then | ||||
self.angle = self.angle - 3.14159 | self.angle = self.angle - 3.14159 | ||||
@@ -66,7 +66,7 @@ function ship:update(dt) | |||||
self.dy = self.dy + 0.5 | self.dy = self.dy + 0.5 | ||||
end | end | ||||
]]-- | ]]-- | ||||
print(self.speed) | |||||
--print(self.speed) | |||||
--[[ | --[[ | ||||
if love.keyboard.isDown('right') then | if love.keyboard.isDown('right') then | ||||
@@ -75,8 +75,8 @@ function ship:update(dt) | |||||
self.rotation = self.rotation - 10 | self.rotation = self.rotation - 10 | ||||
end]]-- | end]]-- | ||||
print("rotation:" .. self.rotation) | |||||
print("speed:" .. self.dx .. " " .. self.dy) | |||||
--print("rotation:" .. self.rotation) | |||||
--print("speed:" .. self.dx .. " " .. self.dy) | |||||
if self.dx < 0 then | if self.dx < 0 then | ||||
self.vector = self.vector - 3.14159 | self.vector = self.vector - 3.14159 | ||||
@@ -89,12 +89,12 @@ function ship:draw() | |||||
-- Draw the `self.canvas` to screen | -- Draw the `self.canvas` to screen | ||||
love.graphics.setColor(unpack(self.color)) | love.graphics.setColor(unpack(self.color)) | ||||
print("DAW" .. camera.x) | |||||
--print("DAW" .. camera.x) | |||||
love.graphics.draw(self.image, self.x, self.y, self.vector, 1, 1, self.width/2, self.height/2) | 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 | for i in ipairs(self.path) do | ||||
if i > 1 then | if i > 1 then | ||||
love.graphics.setColor(0.9,0.9,0.9,1) | love.graphics.setColor(0.9,0.9,0.9,1) | ||||
print("DOING".. i) | |||||
--print("DOING".. i) | |||||
love.graphics.line(self.path[i].x, self.path[i].y, self.path[i-1].x, self.path[i-1].y) | love.graphics.line(self.path[i].x, self.path[i].y, self.path[i-1].x, self.path[i-1].y) | ||||
end | end | ||||
end | end | ||||
@@ -7,13 +7,13 @@ function explosion:init(x, y, v, color) | |||||
self.v = v | self.v = v | ||||
self.range = 0 | self.range = 0 | ||||
self.killed = false | self.killed = false | ||||
print(self.i) | |||||
--print(self.i) | |||||
end | end | ||||
function explosion:update(dt) | function explosion:update(dt) | ||||
self.range = self.range + dt * 24 | self.range = self.range + dt * 24 | ||||
if self.range * self.v > WINDOW_WIDTH * 2 then | if self.range * self.v > WINDOW_WIDTH * 2 then | ||||
print("killing myself with range" .. self.range) | |||||
--print("killing myself with range" .. self.range) | |||||
self.killed = true | self.killed = true | ||||
end | end | ||||
end | end | ||||
@@ -21,7 +21,7 @@ end | |||||
function explosion:render() | function explosion:render() | ||||
print("rendering myself" .. self.x .. " " .. self.y .. " " .. self.range .. " " .. self.v) | |||||
--print("rendering myself" .. self.x .. " " .. self.y .. " " .. self.range .. " " .. self.v) | |||||
love.graphics.setColor(unpack(self.color)) | love.graphics.setColor(unpack(self.color)) | ||||
love.graphics.circle("fill", self.x, self.y, self.range * self.v, 100) | love.graphics.circle("fill", self.x, self.y, self.range * self.v, 100) | ||||
end | end |
@@ -37,7 +37,7 @@ function level1.update(dt) | |||||
if saveData.levelsBeaten < 1 then | if saveData.levelsBeaten < 1 then | ||||
saveData.levelsBeaten = 1 | saveData.levelsBeaten = 1 | ||||
end | end | ||||
print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
love.filesystem.write("save", serialize(saveData)) | love.filesystem.write("save", serialize(saveData)) | ||||
level1.goBack() | level1.goBack() | ||||
end | end | ||||
@@ -37,7 +37,7 @@ function level2.update(dt) | |||||
if saveData.levelsBeaten < 2 then | if saveData.levelsBeaten < 2 then | ||||
saveData.levelsBeaten = 2 | saveData.levelsBeaten = 2 | ||||
end | end | ||||
print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
love.filesystem.write("save", serialize(saveData)) | love.filesystem.write("save", serialize(saveData)) | ||||
level2.goBack() | level2.goBack() | ||||
end | end | ||||
@@ -0,0 +1,144 @@ | |||||
level3 = Class{} | |||||
local levelLoaded = false | |||||
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 | |||||
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})) | |||||
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 | |||||
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() | |||||
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 level3.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 level3 | |||||
@@ -22,7 +22,7 @@ function menu.update(dt) | |||||
firstShip.x = -100 | firstShip.x = -100 | ||||
firstShip.speed = 10 | firstShip.speed = 10 | ||||
firstShip.y = love.math.random(0, WINDOW_HEIGHT) | firstShip.y = love.math.random(0, WINDOW_HEIGHT) | ||||
print("ship is hit") | |||||
--print("ship is hit") | |||||
end | end | ||||
end | end | ||||
@@ -32,7 +32,7 @@ function practice.update(dt) | |||||
end | end | ||||
camera:update(dt) | camera:update(dt) | ||||
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) | ||||
if explosion.killed then | if explosion.killed then | ||||
@@ -43,7 +43,7 @@ function practice.update(dt) | |||||
end | end | ||||
if gameStatus == "play" then | if gameStatus == "play" then | ||||
camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width | camera.x, camera.y = firstShip.x - firstShip.height*4, firstShip.y- firstShip.width | ||||
print(camera.x .. firstShip.x) | |||||
--print(camera.x .. firstShip.x) | |||||
if shipIsHit then | if shipIsHit then | ||||
if #explosions == 0 then | if #explosions == 0 then | ||||
table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1})) | table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1})) | ||||
@@ -12,7 +12,13 @@ table.insert(levels, menu:addButton("Level 2", function () | |||||
gameState = "level2" | gameState = "level2" | ||||
end | end | ||||
end )) | end )) | ||||
table.insert(levels, menu:addButton("Level 3", function () | |||||
if saveData.levelsBeaten > 1 then | |||||
menuLoaded = false | |||||
objReset() | |||||
gameState = "level3" | |||||
end | |||||
end )) | |||||
@@ -38,7 +44,7 @@ function selectlv.update(dt) | |||||
firstShip.x = -100 | firstShip.x = -100 | ||||
firstShip.speed = 10 | firstShip.speed = 10 | ||||
firstShip.y = love.math.random(0, WINDOW_HEIGHT) | firstShip.y = love.math.random(0, WINDOW_HEIGHT) | ||||
print("ship is hit") | |||||
--print("ship is hit") | |||||
end | end | ||||
end | end | ||||
@@ -24,9 +24,9 @@ function love.load() | |||||
testwalls = love.filesystem.load("save") | testwalls = love.filesystem.load("save") | ||||
if testwalls ~= nil then | if testwalls ~= nil then | ||||
saveData = love.filesystem.load("save")() | saveData = love.filesystem.load("save")() | ||||
print("Save file found") | |||||
--print("Save file found") | |||||
else | else | ||||
print("No save file found!") | |||||
--print("No save file found!") | |||||
end | end | ||||
tick.framerate = 60 | tick.framerate = 60 | ||||
camera = Camera() | camera = Camera() | ||||
@@ -104,7 +104,7 @@ function GUIDraw(mode) | |||||
end | end | ||||
if lvlbase ~= nil then | if lvlbase ~= nil then | ||||
local dx, dy = camera:toCameraCoords(lvlbase.x, lvlbase.y) | local dx, dy = camera:toCameraCoords(lvlbase.x, lvlbase.y) | ||||
print("YESYEYSYSYADSYADYASD") | |||||
--print("YESYEYSYSYADSYADYASD") | |||||
if VCAM.x - WINDOW_WIDTH/2+250 > lvlbase.x then | if VCAM.x - WINDOW_WIDTH/2+250 > lvlbase.x then | ||||
love.graphics.setColor(0,1,0,1) | love.graphics.setColor(0,1,0,1) | ||||
love.graphics.rectangle("fill", 0, dy-lvlbase.w/2, 10, lvlbase.w) | love.graphics.rectangle("fill", 0, dy-lvlbase.w/2, 10, lvlbase.w) | ||||
@@ -141,10 +141,10 @@ function GUIDraw(mode) | |||||
local hot = (vmx > firstShip.x-firstShip.height/2 and vmx < firstShip.x+firstShip.height and vmy > firstShip.y-firstShip.width/2 and vmy < firstShip.y - firstShip.width/2 + firstShip.width) | local hot = (vmx > firstShip.x-firstShip.height/2 and vmx < firstShip.x+firstShip.height and vmy > firstShip.y-firstShip.width/2 and vmy < firstShip.y - firstShip.width/2 + firstShip.width) | ||||
if hot then | if hot then | ||||
firstShip.color = {1,0,0,1} | firstShip.color = {1,0,0,1} | ||||
print("hot") | |||||
--print("hot") | |||||
else | else | ||||
firstShip.color = {1,1,1,1} | firstShip.color = {1,1,1,1} | ||||
print(mx .. " " .. my .. " " .. firstShip.x .. " " .. firstShip.y .. " " .. firstShip.width .. firstShip.height) | |||||
--print(mx .. " " .. my .. " " .. firstShip.x .. " " .. firstShip.y .. " " .. firstShip.width .. firstShip.height) | |||||
end | end | ||||
local pressed = love.keyboard.mouseisReleased | local pressed = love.keyboard.mouseisReleased | ||||
if location == "android" then | if location == "android" then | ||||
@@ -162,7 +162,7 @@ function GUIDraw(mode) | |||||
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) | 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 | if hot then | ||||
planets[j].color = {1,0,0,1} | planets[j].color = {1,0,0,1} | ||||
print("hot") | |||||
--print("hot") | |||||
else | else | ||||
planets[j].color = {1,1,1,1} | planets[j].color = {1,1,1,1} | ||||
--print(mx .. " " .. my .. " " .. firstShip.x .. " " .. firstShip.y .. " " .. firstShip.width .. firstShip.height) | --print(mx .. " " .. my .. " " .. firstShip.x .. " " .. firstShip.y .. " " .. firstShip.width .. firstShip.height) | ||||