@@ -22,7 +22,7 @@ function planet:update(dt) | |||
local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^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)) | |||
if self.x < firstShip.x then | |||
self.angle = self.angle - 3.14159 | |||
@@ -66,7 +66,7 @@ function ship:update(dt) | |||
self.dy = self.dy + 0.5 | |||
end | |||
]]-- | |||
print(self.speed) | |||
--print(self.speed) | |||
--[[ | |||
if love.keyboard.isDown('right') then | |||
@@ -75,8 +75,8 @@ function ship:update(dt) | |||
self.rotation = self.rotation - 10 | |||
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 | |||
self.vector = self.vector - 3.14159 | |||
@@ -89,12 +89,12 @@ function ship:draw() | |||
-- Draw the `self.canvas` to screen | |||
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) | |||
for i in ipairs(self.path) do | |||
if i > 1 then | |||
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) | |||
end | |||
end | |||
@@ -7,13 +7,13 @@ function explosion:init(x, y, v, color) | |||
self.v = v | |||
self.range = 0 | |||
self.killed = false | |||
print(self.i) | |||
--print(self.i) | |||
end | |||
function explosion:update(dt) | |||
self.range = self.range + dt * 24 | |||
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 | |||
end | |||
end | |||
@@ -21,7 +21,7 @@ end | |||
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.circle("fill", self.x, self.y, self.range * self.v, 100) | |||
end |
@@ -37,7 +37,7 @@ function level1.update(dt) | |||
if saveData.levelsBeaten < 1 then | |||
saveData.levelsBeaten = 1 | |||
end | |||
print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||
love.filesystem.write("save", serialize(saveData)) | |||
level1.goBack() | |||
end | |||
@@ -37,7 +37,7 @@ function level2.update(dt) | |||
if saveData.levelsBeaten < 2 then | |||
saveData.levelsBeaten = 2 | |||
end | |||
print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||
love.filesystem.write("save", serialize(saveData)) | |||
level2.goBack() | |||
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.speed = 10 | |||
firstShip.y = love.math.random(0, WINDOW_HEIGHT) | |||
print("ship is hit") | |||
--print("ship is hit") | |||
end | |||
end | |||
@@ -32,7 +32,7 @@ function practice.update(dt) | |||
end | |||
camera:update(dt) | |||
print(camera.x .. " " .. camera.y) | |||
--print(camera.x .. " " .. camera.y) | |||
for i, explosion in ipairs(explosions) do | |||
explosion:update(dt) | |||
if explosion.killed then | |||
@@ -43,7 +43,7 @@ function practice.update(dt) | |||
end | |||
if gameStatus == "play" then | |||
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 #explosions == 0 then | |||
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" | |||
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.speed = 10 | |||
firstShip.y = love.math.random(0, WINDOW_HEIGHT) | |||
print("ship is hit") | |||
--print("ship is hit") | |||
end | |||
end | |||
@@ -24,9 +24,9 @@ function love.load() | |||
testwalls = love.filesystem.load("save") | |||
if testwalls ~= nil then | |||
saveData = love.filesystem.load("save")() | |||
print("Save file found") | |||
--print("Save file found") | |||
else | |||
print("No save file found!") | |||
--print("No save file found!") | |||
end | |||
tick.framerate = 60 | |||
camera = Camera() | |||
@@ -104,7 +104,7 @@ function GUIDraw(mode) | |||
end | |||
if lvlbase ~= nil then | |||
local dx, dy = camera:toCameraCoords(lvlbase.x, lvlbase.y) | |||
print("YESYEYSYSYADSYADYASD") | |||
--print("YESYEYSYSYADSYADYASD") | |||
if VCAM.x - WINDOW_WIDTH/2+250 > lvlbase.x then | |||
love.graphics.setColor(0,1,0,1) | |||
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) | |||
if hot then | |||
firstShip.color = {1,0,0,1} | |||
print("hot") | |||
--print("hot") | |||
else | |||
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 | |||
local pressed = love.keyboard.mouseisReleased | |||
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) | |||
if hot then | |||
planets[j].color = {1,0,0,1} | |||
print("hot") | |||
--print("hot") | |||
else | |||
planets[j].color = {1,1,1,1} | |||
--print(mx .. " " .. my .. " " .. firstShip.x .. " " .. firstShip.y .. " " .. firstShip.width .. firstShip.height) | |||