@@ -19,6 +19,7 @@ self.vector = 1.5708 | |||
self.color = {1,1,1,1} | |||
self.path = {} | |||
self.dottimer = 0.5 | |||
self.exploded = false | |||
self.fuel = 0 | |||
self.destX = x | |||
end | |||
@@ -147,4 +148,5 @@ function ship:reset() | |||
self.destX = self.x | |||
self.path = {} | |||
self.dottimer = 0.5 | |||
self.exploded = false | |||
end |
@@ -7,6 +7,7 @@ function explosion:init(x, y, v, color, type) | |||
self.y = y | |||
self.v = v | |||
self.range = 0 | |||
self.maxRange = WINDOW_WIDTH*2 | |||
self.killed = false | |||
if type ~= nil then | |||
self.type = type | |||
@@ -16,14 +17,17 @@ end | |||
function explosion:update(dt) | |||
self.range = self.range + dt * 24 | |||
local maxRange = WINDOW_WIDTH*2 | |||
if (self.type == 0) then | |||
--print("my range is " .. self.range) | |||
end | |||
self.maxRange = WINDOW_WIDTH*2 | |||
if self.type == 1 then | |||
maxRange = WINDOW_WIDTH*6 | |||
self.maxRange = WINDOW_WIDTH*6 | |||
elseif self.type == 2 then | |||
maxRange = 200 | |||
self.maxRange = 200 | |||
end | |||
if self.range * self.v > maxRange then | |||
--print("killing myself with range" .. self.range) | |||
if self.range * self.v > self.maxRange then | |||
--print("killing myself with range" .. self.range .. " " .. self.v .. " " .. self.maxRange .. " and type " .. self.type) | |||
self.killed = true | |||
end | |||
end | |||
@@ -36,7 +40,7 @@ function explosion:render(toggle) | |||
if self.type == 2 then | |||
love.graphics.setColor(1,1,1,0.7/(self.range)) | |||
-- print(self.range) | |||
elseif toggle == "special" then | |||
elseif self.type == 1 then | |||
love.graphics.setColor(1,1,1,0.7/(self.range/6)) | |||
-- print(self.range) | |||
end | |||
@@ -1,15 +1,7 @@ | |||
level7 = Class{} | |||
local levelLoaded = false | |||
local M = {} | |||
function love.wheelmoved(x, y) | |||
if gameStatus == "play" then | |||
if y > 0 and camera.scale < 1 then | |||
camera.scale = camera.scale + 0.1 | |||
elseif y < 0 and camera.scale > 0.5 then | |||
camera.scale = camera.scale - 0.1 | |||
end | |||
end | |||
end | |||
function level7.load() | |||
shipsleft = 1 | |||
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||
@@ -23,6 +15,7 @@ function level7.load() | |||
explosions = {} | |||
shipIsHit = false | |||
guimenu = mainMenu() | |||
cameraControl = true | |||
reachedGoal = false | |||
lvlbase = base(1400, WINDOW_HEIGHT/2) | |||
levelLoaded = true | |||
@@ -119,7 +112,8 @@ function level7.bonusUpdate(dt) | |||
if not cannons[i].appeared then | |||
sounds["appear"]:stop() | |||
sounds["appear"]:play() | |||
table.insert(explosions, explosion(1500, cannons[i].y, 100, {1,1,1,1}, 1)) | |||
local coolx, cooly = camera:toWorldCoords(1280, 720) | |||
table.insert(explosions, explosion(coolx, cannons[i].y, 100, {1,1,1,1}, 1)) | |||
cannons[i].appeared = true | |||
end | |||
end | |||
@@ -34,9 +34,10 @@ function levelgeneral.update(dt) | |||
--print(camera.x .. " " .. camera.y) | |||
for i, explosion in ipairs(explosions) do | |||
explosion:update(dt) | |||
if explosion.killed then | |||
table.remove(explosions, i) | |||
if shipIsHit then | |||
if shipIsHit and explosion.type == 0 then | |||
gameStatus = "setup" | |||
levelgeneral.reset() | |||
end | |||
@@ -45,10 +46,9 @@ function levelgeneral.update(dt) | |||
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 | |||
if shipIsHit and not firstShip.exploded then | |||
table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1}, 0)) | |||
firstShip.exploded = true | |||
end | |||
firstShip:update(dt) | |||
@@ -105,11 +105,7 @@ function levelgeneral.draw() | |||
end | |||
firstShip:draw() | |||
for i, explosion in ipairs(explosions) do | |||
if shipIsHit then | |||
explosion:render() | |||
else | |||
explosion:render("special") | |||
end | |||
--print("exploding") | |||
end | |||
camera:detach() | |||
@@ -145,6 +141,7 @@ function levelgeneral.goBack() | |||
levelgeneral.reset() | |||
lvlbase = nil | |||
gameStatus = "setup" | |||
cameraControl = false | |||
firstShip.path = {} | |||
cannons = {} | |||
levelLoaded = false | |||
@@ -2,15 +2,7 @@ practice = Class{} | |||
local levelLoaded = false | |||
local M = {} | |||
local currenctScore = 0 | |||
function love.wheelmoved(x, y) | |||
if gameStatus == "play" then | |||
if y > 0 and camera.scale < 1 then | |||
camera.scale = camera.scale + 0.1 | |||
elseif y < 0 and camera.scale > 0.5 then | |||
camera.scale = camera.scale - 0.1 | |||
end | |||
end | |||
end | |||
function practice.update(dt) | |||
if not levelLoaded then | |||
shipsleft = 1 | |||
@@ -21,6 +13,7 @@ function practice.update(dt) | |||
guibutts = {} | |||
XCAM = 0 | |||
currentScore = 0 | |||
cameraControl = true | |||
thrusterMax = 0 | |||
YCAM = 0 | |||
firstShip.fuel = 0 | |||
@@ -48,6 +41,7 @@ function practice.update(dt) | |||
--print(camera.x .. " " .. camera.y) | |||
for i, explosion in ipairs(explosions) do | |||
explosion:update(dt) | |||
-- print("1 update done") | |||
if explosion.killed then | |||
table.remove(explosions, i) | |||
if shipIsHit then | |||
@@ -59,12 +53,10 @@ function practice.update(dt) | |||
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 | |||
if shipIsHit and not firstShip.exploded then | |||
table.insert(explosions, explosion(firstShip.x, firstShip.y, 100, {1,1,1,1})) | |||
explosions[#explosions].type = 0 | |||
firstShip.exploded = true | |||
end | |||
firstShip:update(dt) | |||
for i in ipairs(planets) do | |||
@@ -138,6 +130,7 @@ function practice.draw() | |||
end | |||
function practice.goBack() | |||
practice.reset() | |||
cameraControl = false | |||
gameStatus = "setup" | |||
levelLoaded = false | |||
gameState = "menu" | |||
@@ -11,7 +11,7 @@ WINDOW_WIDTH = 1280 | |||
WINDOW_HEIGHT = 720 | |||
OFFSET_X = 0 | |||
OFFSET_Y = 0 | |||
cameraControl = false | |||
currentLevel = 0 | |||
saveData = { | |||
@@ -24,7 +24,15 @@ buttons = {} | |||
cannons = {} | |||
projectiles = {} | |||
menu = mainMenu() | |||
function love.wheelmoved(x, y) | |||
if gameStatus == "play" and cameraControl then | |||
if y > 0 and camera.scale < 1 then | |||
camera.scale = camera.scale + 0.1 | |||
elseif y < 0 and camera.scale > 0.5 then | |||
camera.scale = camera.scale - 0.1 | |||
end | |||
end | |||
end | |||
function love.load() | |||
print(love.filesystem.getAppdataDirectory()) | |||
print(love.filesystem.getSaveDirectory()) | |||
@@ -50,11 +50,9 @@ 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 | |||
if #explosions == 0 then | |||
local zerox, zeroy = camera:toWorldCoords(0, 0) | |||
table.insert(explosions, explosion(zerox, my, 100, {1,1,1,1})) | |||
explosions[1].type = 1 | |||
end | |||
explosions[#explosions].type = 1 | |||
firstShip.destX = vmx | |||
firstShip.y = vmy | |||
@@ -84,8 +82,8 @@ function GUIDraw(mode) | |||
if #explosions == 0 then | |||
local zerox, zeroy = camera:toWorldCoords(0, 0) | |||
table.insert(explosions, explosion(zerox, my, 100, {1,1,1,1})) | |||
explosions[1].type = 1 | |||
end | |||
explosions[#explosions].type = 1 | |||
end | |||
sounds["appear"]:play() | |||
firstShip.destX = 250 | |||
@@ -111,10 +109,8 @@ function GUIDraw(mode) | |||
end | |||
if love.keyboard.mouseisReleased then | |||
love.keyboard.mouseisReleased = false | |||
if #explosions == 0 then | |||
table.insert(explosions, explosion(0, 100, 100, {1,1,1,1})) | |||
explosions[1].type = 1 | |||
end | |||
explosions[#explosions].type = 1 | |||
sounds["appear"]:play() | |||
firstShip.destX = vmx | |||
firstShip.y = 100 | |||