@@ -24,7 +24,7 @@ end | |||
function planet:update(dt) | |||
if not reachedGoal then | |||
local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2) | |||
--print("update") | |||
local gravitationalAttraction = G*self.mass/(distanceToShip^2) | |||
--print((firstShip.x - self.x) .. " " .. (firstShip.y - self.y)) | |||
self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x)) | |||
@@ -37,9 +37,6 @@ function planet:update(dt) | |||
love.window.setTitle(self.attractionX) | |||
firstShip.dx = firstShip.dx + self.attractionX | |||
firstShip.dy = firstShip.dy + self.attractionY | |||
if distanceToShip < 100 then | |||
sounds["close"]:play() | |||
end | |||
if distanceToShip < self.w/4 then | |||
shipIsHit = true | |||
sounds["close"]:stop() | |||
@@ -18,6 +18,7 @@ self.color = {1,1,1,1} | |||
self.path = {} | |||
self.dottimer = 0.5 | |||
self.fuel = 0 | |||
self.destX = x | |||
end | |||
function ship:newPathDot(dotx, doty, color) | |||
return { | |||
@@ -58,6 +59,17 @@ function ship:update(dt) | |||
self.speed = self.speed + 0.05 | |||
end | |||
local tag = false | |||
for i in ipairs(planets) do | |||
local distanceToShip = math.sqrt((firstShip.x - planets[i].x)^2 + (firstShip.y - planets[i].y)^2) | |||
if distanceToShip < 200 and not shipIsHit and gameStatus == "play" then | |||
sounds["close"]:play() | |||
tag = true | |||
end | |||
end | |||
if not tag or shipIsHit then | |||
sounds["close"]:stop() | |||
end | |||
--[[ | |||
if love.keyboard.isDown('left') then | |||
self.dx = self.dx - 0.5 | |||
@@ -121,6 +133,7 @@ function ship:reset() | |||
self.canvas = love.graphics.newCanvas(WINDOW_WIDTH, WINDOW_HEIGHT) | |||
self.vector = 1.56 | |||
self.speed = 1 | |||
self.destX = self.x | |||
self.path = {} | |||
self.dottimer = 0.5 | |||
end |
@@ -2,6 +2,7 @@ explosion = Class{} | |||
function explosion:init(x, y, v, color) | |||
self.color = color | |||
self.type = 0 | |||
self.x = x | |||
self.y = y | |||
self.v = v | |||
@@ -12,7 +13,11 @@ end | |||
function explosion:update(dt) | |||
self.range = self.range + dt * 24 | |||
if self.range * self.v > WINDOW_WIDTH * 2 then | |||
local maxRange = WINDOW_WIDTH*2 | |||
if self.type == 1 then | |||
maxRange = WINDOW_WIDTH*6 | |||
end | |||
if self.range * self.v > maxRange then | |||
--print("killing myself with range" .. self.range) | |||
self.killed = true | |||
end | |||
@@ -20,8 +25,12 @@ end | |||
function explosion:render() | |||
function explosion:render(toggle) | |||
--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) | |||
if toggle == "special" then | |||
love.graphics.setColor(1,1,1,0.7/(self.range/6)) | |||
print(self.range) | |||
end | |||
love.graphics.circle("fill", self.x, self.y, self.range * self.v, 100) | |||
end |
@@ -36,12 +36,22 @@ end | |||
function level1.hint() | |||
GUIDraw("left") | |||
love.graphics.setFont(tinyfont) | |||
love.graphics.setColor(1,1,1,1) | |||
if (VCAM.x > WINDOW_WIDTH/2) then | |||
if love.keyboard.isDown('a') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("←[A]",10,50) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
if (VCAM.x < WINDOW_WIDTH*2) then | |||
if love.keyboard.isDown('d') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("[D]→",100,50) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
function level1.reset() | |||
firstShip:reset() | |||
@@ -48,11 +48,20 @@ end | |||
function level2.hint() | |||
GUIDraw("left") | |||
love.graphics.setFont(tinyfont) | |||
if (VCAM.x > WINDOW_WIDTH/2) then | |||
if love.keyboard.isDown('a') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("←[A]",10,50) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
if (VCAM.x < WINDOW_WIDTH*2) then | |||
if love.keyboard.isDown('a') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("[D]→",100,50) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
end | |||
function level2.GUIControl() | |||
@@ -39,10 +39,18 @@ function level3.hint() | |||
GUIDraw("left") | |||
love.graphics.setFont(tinyfont) | |||
if (VCAM.x > WINDOW_WIDTH/2) then | |||
if love.keyboard.isDown('a') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("←[A]",10,50) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
if (VCAM.x < WINDOW_WIDTH*2) then | |||
if love.keyboard.isDown('a') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("[D]→",100,50) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
end | |||
function level3.reset() | |||
@@ -60,10 +60,18 @@ function level4.hint() | |||
GUIDraw("left") | |||
love.graphics.setFont(tinyfont) | |||
if (VCAM.x > -WINDOW_WIDTH/2) then | |||
if love.keyboard.isDown('a') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("←[A]",10,50) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
if (VCAM.x < WINDOW_WIDTH) then | |||
if love.keyboard.isDown('a') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("[D]→",100,50) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
end | |||
function level4.goBack() | |||
@@ -61,10 +61,18 @@ function level5.hint() | |||
GUIDraw("up") | |||
love.graphics.setFont(tinyfont) | |||
if (VCAM.y > -WINDOW_WIDTH) then | |||
if love.keyboard.isDown('w') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("↑[W]",50,10) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
if (VCAM.y < WINDOW_WIDTH*2) then | |||
love.graphics.print("↓[D]",50,100) | |||
if love.keyboard.isDown('s') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("↓[S]",50,100) | |||
love.graphics.setColor(1,1,1,1) | |||
end | |||
end | |||
function level5.goBack() | |||
@@ -22,6 +22,7 @@ function levelgeneral.update(dt) | |||
end | |||
--print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||
if animationComplete then | |||
reachedGoal = false | |||
love.filesystem.write("save", serialize(saveData)) | |||
levelgeneral.goBack() | |||
end | |||
@@ -35,8 +36,10 @@ function levelgeneral.update(dt) | |||
explosion:update(dt) | |||
if explosion.killed then | |||
table.remove(explosions, i) | |||
if shipIsHit then | |||
gameStatus = "setup" | |||
levelgeneral.reset() | |||
end | |||
end | |||
end | |||
if gameStatus == "play" then | |||
@@ -82,6 +85,7 @@ function levelgeneral.draw() | |||
love.graphics.clear(0,0,0,1) | |||
love.graphics.setColor(30/255, 30/255, 30/255, 1) | |||
if frame < WINDOW_WIDTH then | |||
stopMusic() | |||
sounds["finish"]:play() | |||
love.graphics.circle("fill", firstShip.x, firstShip.y, WINDOW_WIDTH - frame) | |||
end | |||
@@ -40,8 +40,10 @@ function practice.update(dt) | |||
explosion:update(dt) | |||
if explosion.killed then | |||
table.remove(explosions, i) | |||
if shipIsHit then | |||
gameStatus = "setup" | |||
practice.reset() | |||
end | |||
end | |||
end | |||
if gameStatus == "play" then | |||
@@ -49,6 +51,7 @@ function practice.update(dt) | |||
--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 | |||
@@ -85,9 +88,13 @@ function practice.draw() | |||
if gameStatus == "setup" then | |||
GUIDraw("anywhere") | |||
love.graphics.setFont(tinyfont) | |||
local textW = tinyfont:getWidth("Top score: " .. math.floor(saveData.score/100)) | |||
love.graphics.print("Top score: " .. math.floor(saveData.score/100), WINDOW_WIDTH/2-textW/2, 10) | |||
practice.hint() | |||
elseif gameStatus == "play" then | |||
local textW = tinyfont:getWidth("Score: " .. math.floor(currentScore/100)) | |||
love.graphics.setFont(tinyfont) | |||
love.graphics.print("Score: " .. math.floor(currentScore/100), WINDOW_WIDTH/2-textW/2, 10) | |||
guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3) | |||
love.keyboard.mouseisReleased = false | |||
@@ -110,7 +117,9 @@ function practice.reset() | |||
end | |||
shipsleft = 1 | |||
if currentScore > saveData.score then | |||
saveData.score = currentScore | |||
love.filesystem.write("save", serialize(saveData)) | |||
end | |||
currentScore = 0 | |||
shipIsHit = false | |||
@@ -133,10 +142,26 @@ function practice.GUIControl() | |||
end | |||
function practice.hint() | |||
love.graphics.setFont(tinyfont) | |||
love.graphics.print("↑[W]",50,10) | |||
love.graphics.print("↓[S]",50,100) | |||
if love.keyboard.isDown('w') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("↑[W]",80,10) | |||
love.graphics.setColor(1,1,1,1) | |||
if love.keyboard.isDown('s') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("↓[S]",80,100) | |||
love.graphics.setColor(1,1,1,1) | |||
if love.keyboard.isDown('a') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("←[A]",10,50) | |||
love.graphics.print("→[D]",100,50) | |||
love.graphics.setColor(1,1,1,1) | |||
if love.keyboard.isDown('d') then | |||
love.graphics.setColor(1,0,0,1) | |||
end | |||
love.graphics.print("→[D]",150,50) | |||
love.graphics.setColor(1,1,1,1) | |||
@@ -31,6 +31,9 @@ function love.load() | |||
else | |||
--print("No save file found!") | |||
end | |||
if saveData.score == nil then | |||
saveData.score = 0 | |||
end | |||
tick.framerate = 60 | |||
camera = Camera() | |||
BG = love.graphics.newImage("entities/background.jpg") | |||
@@ -1,7 +1,5 @@ | |||
selectedItem = "none" | |||
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||
function GUIDraw(mode) | |||
--MAIN | |||
love.graphics.setColor(1,1,1,1) | |||
@@ -23,10 +21,12 @@ function GUIDraw(mode) | |||
--SHIP | |||
--PLANET | |||
GUIButton(planetsleft, planetImage, menuX + 60, menuY+WINDOW_HEIGHT*0.4, function() selectedItem = "planet" end, 0.5, 0.5, {1,1,1,1}, 1.57) | |||
for i, explosion in ipairs(explosions) do | |||
explosion:render("special") | |||
--print("exploding") | |||
end | |||
--PLANET | |||
--PLACING | |||
local mx, my = love.mouse.getPosition() | |||
@@ -35,6 +35,8 @@ function GUIDraw(mode) | |||
local mx = mx * DIFFERENCE_X | |||
local my = my * DIFFERENCE_Y | |||
local vmx, vmy = camera:toWorldCoords(mx, my) | |||
firstShip.x = firstShip.x + (math.abs(firstShip.destX-firstShip.x)/5) | |||
if mode == "anywhere" then | |||
love.graphics.setColor(1,1,1,0.5) | |||
if selectedItem == "ship" and mx < menuX then | |||
@@ -43,8 +45,14 @@ function GUIDraw(mode) | |||
love.graphics.draw(shipImage,mx,my, 1.5708, 1, 1, shipW/2, shipH/2) | |||
if love.keyboard.mouseisReleased then | |||
love.keyboard.mouseisReleased = false | |||
firstShip.x = vmx | |||
if #explosions == 0 then | |||
table.insert(explosions, explosion(0, my, 100, {1,1,1,1})) | |||
explosions[1].type = 1 | |||
end | |||
firstShip.destX = vmx | |||
firstShip.y = vmy | |||
sounds["appear"]:play() | |||
shipsleft = shipsleft - 1 | |||
end | |||
@@ -67,7 +75,12 @@ function GUIDraw(mode) | |||
end | |||
if love.keyboard.mouseisReleased then | |||
love.keyboard.mouseisReleased = false | |||
firstShip.x = 250 | |||
if #explosions == 0 then | |||
table.insert(explosions, explosion(0, my, 100, {1,1,1,1})) | |||
explosions[1].type = 1 | |||
end | |||
sounds["appear"]:play() | |||
firstShip.destX = 250 | |||
firstShip.y = vmy | |||
shipsleft = shipsleft - 1 | |||
end | |||
@@ -90,7 +103,12 @@ function GUIDraw(mode) | |||
end | |||
if love.keyboard.mouseisReleased then | |||
love.keyboard.mouseisReleased = false | |||
firstShip.x = vmx | |||
if #explosions == 0 then | |||
table.insert(explosions, explosion(0, 100, 100, {1,1,1,1})) | |||
explosions[1].type = 1 | |||
end | |||
sounds["appear"]:play() | |||
firstShip.destX = vmx | |||
firstShip.y = 100 | |||
shipsleft = shipsleft - 1 | |||
end | |||
@@ -187,6 +205,7 @@ function GUIDraw(mode) | |||
if pressed and hot then | |||
love.keyboard.mouseisReleased = false | |||
firstShip.x = -9000 | |||
firstShip.destX = -9000 | |||
shipsleft = shipsleft + 1 | |||
end | |||
@@ -1,19 +1,25 @@ | |||
sounds = { | |||
["menu"] = love.audio.newSource("entities/music/menu.ogg", "static"), | |||
["boom"] = love.audio.newSource("entities/planet/boom.wav", "static"), | |||
["close"] = love.audio.newSource("entities/planet/close.wav", "static"), | |||
["play"] = love.audio.newSource("entities/music/play.wav", "static"), | |||
["appear"] = love.audio.newSource("entities/ship/Appear.wav", "static"), | |||
["finish"] = love.audio.newSource("entities/ship/Finish.wav", "static") | |||
} | |||
music = { | |||
["menu"] = love.audio.newSource("entities/music/menu.ogg", "static"), | |||
["play"] = love.audio.newSource("entities/music/play.wav", "static") | |||
} | |||
mute = false | |||
function musicController(orders, toggling) | |||
if (orders == 'norm' and not mute) then | |||
if (orders == 'norm' and not mute and not reachedGoal) then | |||
if (gameState == 'menu' or gameState == "selectlv") then | |||
sounds['menu']:play() | |||
music['menu']:play() | |||
music["play"]:play() | |||
music["play"]:setVolume(0) | |||
music["menu"]:setVolume(1) | |||
elseif gameStatus == 'play' then | |||
stopSounds() | |||
sounds["play"]:play() | |||
music["play"]:play() | |||
music["play"]:setVolume(0.4) | |||
music["menu"]:setVolume(1) | |||
end | |||
elseif orders == "mute" then | |||
if toggling == 1 then | |||
@@ -32,4 +38,8 @@ function stopSounds() | |||
sound[i]:stop() | |||
print("stopping sounds") | |||
end | |||
end | |||
function stopMusic() | |||
music["play"]:setVolume(0) | |||
music["menu"]:setVolume(0) | |||
end |