@@ -1,6 +1,6 @@ | |||||
planet = Class{} | planet = Class{} | ||||
G = 6.67e-5 | |||||
G = 6.67e-1 | |||||
function planet:init(x, y, mass, radius, img) | function planet:init(x, y, mass, radius, img) | ||||
self.x = x | self.x = x | ||||
@@ -15,6 +15,7 @@ self.rotation = 1.5708 | |||||
self.vector = 1.5708 | self.vector = 1.5708 | ||||
self.color = {1,1,1,1} | self.color = {1,1,1,1} | ||||
self.path = {} | self.path = {} | ||||
self.dottimer = 0.5 | |||||
end | end | ||||
function ship:newPathDot(dotx, doty) | function ship:newPathDot(dotx, doty) | ||||
return { | return { | ||||
@@ -24,7 +25,14 @@ function ship:newPathDot(dotx, doty) | |||||
end | end | ||||
function ship:update(dt) | function ship:update(dt) | ||||
if not shipIsHit then | if not shipIsHit then | ||||
self.dottimer = self.dottimer - dt | |||||
if self.dottimer < 0 then | |||||
table.insert(self.path, self:newPathDot(self.x, self.y)) | table.insert(self.path, self:newPathDot(self.x, self.y)) | ||||
self.dottimer = 0.5 | |||||
end | |||||
if love.timer.getFPS() < 20 then | |||||
self.path = {} | |||||
end | |||||
self.x = self.x + self.dx/2 | self.x = self.x + self.dx/2 | ||||
self.y = self.y + self.dy/2 | self.y = self.y + self.dy/2 | ||||
if self.dx ~= 0 then | if self.dx ~= 0 then | ||||
@@ -81,7 +89,7 @@ function ship:draw() | |||||
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,1,0,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 | ||||
@@ -94,10 +102,11 @@ function ship:reset() | |||||
self.x = self.ox | self.x = self.ox | ||||
self.y = self.oy | self.y = self.oy | ||||
self.dy = 0 | self.dy = 0 | ||||
self.dx = 20 | |||||
self.dx = 5 | |||||
self.rotation = 1.57 | self.rotation = 1.57 | ||||
self.canvas = love.graphics.newCanvas(WINDOW_WIDTH, WINDOW_HEIGHT) | self.canvas = love.graphics.newCanvas(WINDOW_WIDTH, WINDOW_HEIGHT) | ||||
self.vector = 1.56 | self.vector = 1.56 | ||||
self.speed = 0 | self.speed = 0 | ||||
self.path = {} | self.path = {} | ||||
self.dottimer = 0.5 | |||||
end | end |
@@ -32,11 +32,11 @@ function level1.update(dt) | |||||
end | end | ||||
if reachedGoal then | if reachedGoal then | ||||
if levelsBeaten < 1 then | |||||
levelsBeaten = 1 | |||||
if saveData.levelsBeaten < 1 then | |||||
saveData.levelsBeaten = 1 | |||||
end | end | ||||
print("levelsBeaten is " .. levelsBeaten) | |||||
love.filesystem.write("save", levelsBeaten) | |||||
print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
love.filesystem.write("save", serialize(saveData)) | |||||
level1.goBack() | level1.goBack() | ||||
end | end | ||||
camera:update(dt) | camera:update(dt) | ||||
@@ -32,11 +32,11 @@ function level2.update(dt) | |||||
end | end | ||||
if reachedGoal then | if reachedGoal then | ||||
if levelsBeaten < 2 then | |||||
levelsBeaten = 2 | |||||
if saveData.levelsBeaten < 2 then | |||||
saveData.levelsBeaten = 2 | |||||
end | end | ||||
print("levelsBeaten is " .. levelsBeaten) | |||||
love.filesystem.write("save", levelsBeaten) | |||||
print("saveData.levelsBeaten is " .. saveData.levelsBeaten) | |||||
love.filesystem.write("save", serialize(saveData)) | |||||
level2.goBack() | level2.goBack() | ||||
end | end | ||||
camera:update(dt) | camera:update(dt) | ||||
@@ -1,11 +1,20 @@ | |||||
menu = Class{} | menu = Class{} | ||||
local M = {} | local M = {} | ||||
function menu.update(dt) | function menu.update(dt) | ||||
if animationSecsLeft > 0 then | |||||
animationSecsLeft = animationSecsLeft - dt | |||||
end | |||||
end | end | ||||
function menu.draw(dt) | function menu.draw(dt) | ||||
if animationSecsLeft > 0 then | |||||
love.graphics.setColor(1,1,1,1-1/(animationSecsLeft+0.000001)) | |||||
love.graphics.draw(logo, 0,0) | |||||
else | |||||
love.graphics.setFont(titlefont) | |||||
love.graphics.printf("NuclearGravity", 0, 20, WINDOW_WIDTH, "center") | |||||
menu:butt(buttons, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 40, WINDOW_WIDTH/3) | menu:butt(buttons, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 40, WINDOW_WIDTH/3) | ||||
end | |||||
end | end | ||||
return menu | return menu |
@@ -4,7 +4,7 @@ table.insert(levels, menu:addButton("Level 1", function () | |||||
gameState = "level1" | gameState = "level1" | ||||
end )) | end )) | ||||
table.insert(levels, menu:addButton("Level 2", function () | table.insert(levels, menu:addButton("Level 2", function () | ||||
if levelsBeaten > 0 then | |||||
if saveData.levelsBeaten > 0 then | |||||
gameState = "level2" | gameState = "level2" | ||||
end | end | ||||
end )) | end )) | ||||
@@ -1,4 +1,5 @@ | |||||
gameState = "menu" | gameState = "menu" | ||||
animationSecsLeft = 3 | |||||
require 'src/dependencies' | require 'src/dependencies' | ||||
math.randomseed(os.time()) | math.randomseed(os.time()) | ||||
--VARIABLES | --VARIABLES | ||||
@@ -11,7 +12,10 @@ WINDOW_HEIGHT = 720 | |||||
OFFSET_X = 0 | OFFSET_X = 0 | ||||
OFFSET_Y = 0 | OFFSET_Y = 0 | ||||
levelsBeaten = 0 | |||||
saveData = { | |||||
levelsBeaten = 0 | |||||
} | |||||
planets = {} | planets = {} | ||||
buttons = {} | buttons = {} | ||||
menu = mainMenu() | menu = mainMenu() | ||||
@@ -19,7 +23,7 @@ menu = mainMenu() | |||||
function love.load() | function love.load() | ||||
testwalls = love.filesystem.load("save") | testwalls = love.filesystem.load("save") | ||||
if testwalls ~= nil then | if testwalls ~= nil then | ||||
levelsBeaten = 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!") | ||||
@@ -27,10 +31,12 @@ function love.load() | |||||
tick.framerate = 60 | tick.framerate = 60 | ||||
camera = Camera() | camera = Camera() | ||||
BG = love.graphics.newImage("entities/background.jpg") | BG = love.graphics.newImage("entities/background.jpg") | ||||
logo = love.graphics.newImage("logo.png") | |||||
simpleScale.setWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT) | simpleScale.setWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT) | ||||
firstShip = ship(-500, -500, "entities/ship/smol_red_01.png") | |||||
firstShip = ship(-500, -500, "entities/ship/smol_white_01.png") | |||||
VCAM = VCAM(WINDOW_WIDTH/2, WINDOW_HEIGHT/2) | VCAM = VCAM(WINDOW_WIDTH/2, WINDOW_HEIGHT/2) | ||||
smallfont = love.graphics.newFont("font.ttf", 25) | smallfont = love.graphics.newFont("font.ttf", 25) | ||||
titlefont = love.graphics.newFont("font.ttf", 50) | |||||
--table.insert(planets, planet(100, WINDOW_HEIGHT/2-100, 1010000000, 1)) | --table.insert(planets, planet(100, WINDOW_HEIGHT/2-100, 1010000000, 1)) | ||||
buttonClutter() | buttonClutter() | ||||
--planet2 = planet(1000, 300, 1000000000, 20) | --planet2 = planet(1000, 300, 1000000000, 20) | ||||
@@ -43,7 +49,7 @@ end | |||||
function love.draw() | function love.draw() | ||||
simpleScale.set() | simpleScale.set() | ||||
--love.graphics.draw(BG, 0, 0) | |||||
love.graphics.clear(30 / 255,30 / 255,30 / 255,1) | |||||
stateDraw() | stateDraw() | ||||
simpleScale.unSet() | simpleScale.unSet() | ||||
end | end | ||||
@@ -18,11 +18,12 @@ function GUIDraw(mode) | |||||
--MAIN | --MAIN | ||||
--SHIP | --SHIP | ||||
local shipImage = love.graphics.newImage("entities/ship/smol_red_01.png") | |||||
local shipImage = love.graphics.newImage("entities/ship/smol_white_01.png") | |||||
GUIButton(shipsleft, shipImage, menuX + 60, menuY+WINDOW_HEIGHT*0.2, function() selectedItem = "ship" end, 1, 1, {1,1,1,1}, 1.57) | GUIButton(shipsleft, shipImage, menuX + 60, menuY+WINDOW_HEIGHT*0.2, function() selectedItem = "ship" end, 1, 1, {1,1,1,1}, 1.57) | ||||
--SHIP | --SHIP | ||||
--PLANET | --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) | GUIButton(planetsleft, planetImage, menuX + 60, menuY+WINDOW_HEIGHT*0.4, function() selectedItem = "planet" end, 0.5, 0.5, {1,1,1,1}, 1.57) | ||||
--PLANET | --PLANET | ||||
@@ -121,13 +122,14 @@ function GUIDraw(mode) | |||||
love.graphics.rectangle("fill", menuX-10, dy-lvlbase.w/2, 10, lvlbase.w) | love.graphics.rectangle("fill", menuX-10, dy-lvlbase.w/2, 10, lvlbase.w) | ||||
end | end | ||||
end | end | ||||
love.graphics.setColor(1,1,1,1) | |||||
if selectedItem == "planet" and mx < menuX then | if selectedItem == "planet" and mx < menuX then | ||||
local shipW = planetImage:getWidth() | local shipW = planetImage:getWidth() | ||||
local shipH = planetImage:getHeight() | local shipH = planetImage:getHeight() | ||||
love.graphics.draw(planetImage,mx,my,0, 0.3, 0.3, shipW/2, shipH/2) | love.graphics.draw(planetImage,mx,my,0, 0.3, 0.3, shipW/2, shipH/2) | ||||
if love.keyboard.mouseisReleased then | if love.keyboard.mouseisReleased then | ||||
love.keyboard.mouseisReleased = false | love.keyboard.mouseisReleased = false | ||||
table.insert(planets, planet(vmx, vmy, 1000000000, 0.3, planetImage)) | |||||
table.insert(planets, planet(vmx, vmy, 100000000, 0.3, planetImage)) | |||||
planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | ||||
planetsleft = planetsleft-1 | planetsleft = planetsleft-1 | ||||
end | end | ||||
@@ -27,7 +27,7 @@ function mainMenu:butt(buttons, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, locationx, locati | |||||
break | break | ||||
end | end | ||||
if arg == "beatenGreen" then | if arg == "beatenGreen" then | ||||
if i <= levelsBeaten then | |||||
if i <= saveData.levelsBeaten then | |||||
color = {0,1,0,1} | color = {0,1,0,1} | ||||
end | end | ||||
end | end | ||||