| @@ -0,0 +1,46 @@ | |||||
| enemy = Class{} | |||||
| G = 6.67e-5 | |||||
| function enemy:init(x, y, del, tm) | |||||
| self.x = x | |||||
| self.y = y | |||||
| self.image = love.graphics.newImage("entities/enemy/enemy.png") | |||||
| self.cannon = love.graphics.newImage("entities/enemy/cannon.png") | |||||
| self.w = self.image:getWidth() | |||||
| self.h = self.image:getHeight() | |||||
| self.cannonw = self.cannon:getWidth() | |||||
| self.cannonh = self.cannon:getHeight() | |||||
| self.angle = 0 | |||||
| self.deletable = del | |||||
| self.maxtimer = tm | |||||
| self.destX = x | |||||
| self.timer = tm | |||||
| self.color = {1,1,1,1} | |||||
| self.appeared = false | |||||
| end | |||||
| function enemy:update(dt) | |||||
| self.timer = self.timer - dt | |||||
| if self.timer <= 0 then | |||||
| self.timer = self.maxtimer | |||||
| self:shoot() | |||||
| end | |||||
| local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2) | |||||
| self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x)) | |||||
| if self.x < firstShip.x then | |||||
| self.angle = self.angle - 3.14159 | |||||
| end | |||||
| end | |||||
| function enemy:draw() | |||||
| love.graphics.setColor(unpack(self.color)) | |||||
| love.graphics.draw(self.image, self.x, self.y, 0, 1, 1, self.w/2, self.w/2) | |||||
| love.graphics.draw(self.cannon, self.x, self.y, self.angle-1.57, 1, 1, self.cannonw/2, self.cannonh/2) | |||||
| end | |||||
| function enemy:shoot() | |||||
| table.insert(projectiles, projectile(self.x, self.y, 0.5, self.angle+3.14, 5)) | |||||
| sounds["launch"]:stop() | |||||
| sounds["launch"]:play() | |||||
| end | |||||
| @@ -0,0 +1,42 @@ | |||||
| projectile = Class{} | |||||
| G = 6.67e-5 | |||||
| function projectile:init(x, y, v, angle, timer) | |||||
| self.x = x | |||||
| self.y = y | |||||
| self.dx = 0 | |||||
| self.dy = 0 | |||||
| self.image = love.graphics.newImage("entities/enemy/missile-01.png") | |||||
| self.w = self.image:getWidth() | |||||
| self.h = self.image:getHeight() | |||||
| self.angle = angle | |||||
| self.v = v | |||||
| self.timer = timer | |||||
| self.killed = false | |||||
| self.dx = math.cos(self.angle) * self.v | |||||
| self.dy = math.sin(self.angle) * self.v | |||||
| self.vx = 0 | |||||
| self.vy = 0 | |||||
| end | |||||
| function projectile:update(dt) | |||||
| local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2) | |||||
| self.timer = self.timer - dt | |||||
| if self.timer <= 0 then | |||||
| self.killed = true | |||||
| end | |||||
| self.vx = self.vx + self.dx | |||||
| self.vy = self.vy + self.dy | |||||
| self.x = self.x + self.vx | |||||
| self.y = self.y + self.vy | |||||
| if distanceToShip < firstShip.width/3 then | |||||
| shipIsHit = true | |||||
| sounds["close"]:stop() | |||||
| sounds["boom"]:play() | |||||
| end | |||||
| end | |||||
| function projectile:draw() | |||||
| love.graphics.draw(self.image, self.x, self.y, self.angle, 1, 1, self.w/2, self.w/2) | |||||
| end | |||||
| @@ -30,7 +30,8 @@ function explosion:render(toggle) | |||||
| love.graphics.setColor(unpack(self.color)) | love.graphics.setColor(unpack(self.color)) | ||||
| if toggle == "special" then | if toggle == "special" then | ||||
| love.graphics.setColor(1,1,1,0.7/(self.range/6)) | love.graphics.setColor(1,1,1,0.7/(self.range/6)) | ||||
| print(self.range) | |||||
| -- print(self.range) | |||||
| end | end | ||||
| 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) | ||||
| love.graphics.setColor(1,1,1,1) | |||||
| end | end | ||||
| @@ -55,15 +55,11 @@ function level1.hint() | |||||
| end | end | ||||
| function level1.reset() | function level1.reset() | ||||
| firstShip:reset() | firstShip:reset() | ||||
| for k in pairs(planets) do | |||||
| planets[k] = nil | |||||
| end | |||||
| local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | ||||
| table.insert(planets, planet(700, 200, 50, 0.3, asteroidImage)) | table.insert(planets, planet(700, 200, 50, 0.3, asteroidImage)) | ||||
| shipsleft = 1 | shipsleft = 1 | ||||
| shipIsHit = false | shipIsHit = false | ||||
| firstShip.fuel = 25 | firstShip.fuel = 25 | ||||
| planetsleft = 3 | |||||
| end | end | ||||
| function level1.GUIControl() | function level1.GUIControl() | ||||
| if (love.keyboard.isDown('a') and VCAM.x > WINDOW_WIDTH/2) then | if (love.keyboard.isDown('a') and VCAM.x > WINDOW_WIDTH/2) then | ||||
| @@ -35,15 +35,11 @@ function level2.load() | |||||
| end | end | ||||
| function level2.reset() | function level2.reset() | ||||
| firstShip:reset() | firstShip:reset() | ||||
| for k in pairs(planets) do | |||||
| planets[k] = nil | |||||
| end | |||||
| firstShip.fuel = 50 | firstShip.fuel = 50 | ||||
| local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | ||||
| table.insert(planets, planet(700, 500, 50, 0.3, asteroidImage)) | table.insert(planets, planet(700, 500, 50, 0.3, asteroidImage)) | ||||
| shipsleft = 1 | shipsleft = 1 | ||||
| shipIsHit = false | shipIsHit = false | ||||
| planetsleft = 3 | |||||
| end | end | ||||
| function level2.hint() | function level2.hint() | ||||
| GUIDraw("left") | GUIDraw("left") | ||||
| @@ -57,7 +53,7 @@ function level2.hint() | |||||
| love.graphics.setColor(1,1,1,1) | love.graphics.setColor(1,1,1,1) | ||||
| end | end | ||||
| if (VCAM.x < WINDOW_WIDTH*2) then | if (VCAM.x < WINDOW_WIDTH*2) then | ||||
| if love.keyboard.isDown('a') then | |||||
| if love.keyboard.isDown('d') then | |||||
| love.graphics.setColor(1,0,0,1) | love.graphics.setColor(1,0,0,1) | ||||
| end | end | ||||
| love.graphics.print("[D]→",100,50) | love.graphics.print("[D]→",100,50) | ||||
| @@ -55,16 +55,10 @@ function level3.hint() | |||||
| end | end | ||||
| function level3.reset() | function level3.reset() | ||||
| firstShip: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") | local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | ||||
| shipsleft = 1 | shipsleft = 1 | ||||
| firstShip.fuel = 75 | firstShip.fuel = 75 | ||||
| shipIsHit = false | shipIsHit = false | ||||
| planetsleft = 3 | |||||
| end | end | ||||
| function level3.GUIControl() | function level3.GUIControl() | ||||
| @@ -37,16 +37,10 @@ end | |||||
| function level4.reset() | function level4.reset() | ||||
| firstShip: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") | local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | ||||
| shipsleft = 1 | shipsleft = 1 | ||||
| firstShip.fuel = 100 | firstShip.fuel = 100 | ||||
| shipIsHit = false | shipIsHit = false | ||||
| planetsleft = 3 | |||||
| end | end | ||||
| function level4.GUIControl() | function level4.GUIControl() | ||||
| if (love.keyboard.isDown('a') and VCAM.x > -WINDOW_WIDTH/2) then | if (love.keyboard.isDown('a') and VCAM.x > -WINDOW_WIDTH/2) then | ||||
| @@ -38,16 +38,10 @@ end | |||||
| function level5.reset() | function level5.reset() | ||||
| firstShip: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") | local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | ||||
| shipsleft = 1 | shipsleft = 1 | ||||
| firstShip.fuel = 100 | firstShip.fuel = 100 | ||||
| shipIsHit = false | shipIsHit = false | ||||
| planetsleft = 10 | |||||
| end | end | ||||
| function level5.GUIControl() | function level5.GUIControl() | ||||
| if (love.keyboard.isDown('w') and VCAM.y > -WINDOW_WIDTH) then | if (love.keyboard.isDown('w') and VCAM.y > -WINDOW_WIDTH) then | ||||
| @@ -0,0 +1,107 @@ | |||||
| level6 = Class{} | |||||
| local levelLoaded = false | |||||
| local M = {} | |||||
| function level6.load() | |||||
| shipsleft = 1 | |||||
| local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||||
| planetsleft = 3 | |||||
| gameStatus = "setup" | |||||
| playbutts = {} | |||||
| thrusterMax = 0 | |||||
| firstShip.fuel = 0 | |||||
| guibutts = {} | |||||
| VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2 | |||||
| explosions = {} | |||||
| shipIsHit = false | |||||
| guimenu = mainMenu() | |||||
| reachedGoal = false | |||||
| lvlbase = base(1600, 400) | |||||
| levelLoaded = true | |||||
| attackTimer = 5 | |||||
| table.insert(playbutts, menu:addButton("Return to setup", function() | |||||
| gameStatus = "setup" | |||||
| levelgeneral.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 () | |||||
| levelgeneral.goBack() | |||||
| end)) | |||||
| table.insert(cannons, enemy(10000, 400, false, 3)) | |||||
| table.insert(planets, planet(1600, 250, 50, 0.3, asteroidImage, "nodelete")) | |||||
| table.insert(planets, planet(1600, 550, 50, 0.3, asteroidImage, "nodelete")) | |||||
| end | |||||
| function level6.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('d') 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 level6.reset() | |||||
| firstShip:reset() | |||||
| local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | |||||
| shipsleft = 1 | |||||
| projectiles = {} | |||||
| cannons[1].x = 100000 | |||||
| cannons[1].destX = 100000 | |||||
| firstShip.fuel = 0 | |||||
| shipIsHit = false | |||||
| attackTimer = 5 | |||||
| cannons[1].appeared = false | |||||
| end | |||||
| function level6.bonusUpdate(dt) | |||||
| if not reachedGoal then | |||||
| if attackTimer >= 0 then | |||||
| attackTimer = attackTimer - dt | |||||
| else | |||||
| cannons[1].destX = 1200 | |||||
| cannons[1]:update(dt) | |||||
| if not cannons[1].appeared then | |||||
| sounds["appear"]:stop() | |||||
| sounds["appear"]:play() | |||||
| if #explosions == 0 then | |||||
| table.insert(explosions, explosion(1400, 400, 100, {1,40/255,40/255,1})) | |||||
| explosions[1].type = 1 | |||||
| end | |||||
| cannons[1].appeared = true | |||||
| end | |||||
| end | |||||
| for i in ipairs(projectiles) do | |||||
| projectiles[i]:update(dt) | |||||
| end | |||||
| cannons[1].x = cannons[1].x - (math.abs(cannons[1].destX-cannons[1].x)/5) | |||||
| end | |||||
| end | |||||
| function level6.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 | |||||
| function level6.goBack() | |||||
| levelgeneral.goBack() | |||||
| end | |||||
| return level6 | |||||
| @@ -56,6 +56,9 @@ function levelgeneral.update(dt) | |||||
| for i in ipairs(planets) do | for i in ipairs(planets) do | ||||
| planets[i]:update(dt) | planets[i]:update(dt) | ||||
| end | end | ||||
| if currentLevel > 5 then | |||||
| level.bonusUpdate(dt) | |||||
| end | |||||
| else | else | ||||
| camera:follow(VCAM.x, VCAM.y) | camera:follow(VCAM.x, VCAM.y) | ||||
| end | end | ||||
| @@ -75,12 +78,22 @@ function levelgeneral.draw() | |||||
| planets[i]:draw(dt) | planets[i]:draw(dt) | ||||
| end | end | ||||
| --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30) | --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30) | ||||
| if shipIsHit then | |||||
| for i, explosion in ipairs(explosions) do | |||||
| for i in ipairs(cannons) do | |||||
| cannons[i]:draw(dt) | |||||
| end | |||||
| for i in ipairs(projectiles) do | |||||
| projectiles[i]:draw(dt) | |||||
| end | |||||
| for i, explosion in ipairs(explosions) do | |||||
| if shipIsHit then | |||||
| explosion:render() | explosion:render() | ||||
| --print("exploding") | |||||
| else | |||||
| explosion:render("special") | |||||
| end | end | ||||
| --print("exploding") | |||||
| end | end | ||||
| if reachedGoal then | if reachedGoal then | ||||
| love.graphics.clear(0,0,0,1) | love.graphics.clear(0,0,0,1) | ||||
| love.graphics.setColor(30/255, 30/255, 30/255, 1) | love.graphics.setColor(30/255, 30/255, 30/255, 1) | ||||
| @@ -92,6 +105,7 @@ function levelgeneral.draw() | |||||
| frame = frame + 20 | frame = frame + 20 | ||||
| end | end | ||||
| firstShip:draw() | firstShip:draw() | ||||
| camera:detach() | camera:detach() | ||||
| camera:draw() | camera:draw() | ||||
| @@ -8,9 +8,9 @@ function menu.update(dt) | |||||
| planets = {} | planets = {} | ||||
| table.insert(planets, planet(love.math.random(100, WINDOW_WIDTH-100), love.math.random(100, WINDOW_HEIGHT-100), 90000000, 0.3, love.graphics.newImage("entities/planet/planet.png"))) | table.insert(planets, planet(love.math.random(100, WINDOW_WIDTH-100), love.math.random(100, WINDOW_HEIGHT-100), 90000000, 0.3, love.graphics.newImage("entities/planet/planet.png"))) | ||||
| if (planets[1].y < WINDOW_HEIGHT/2) then | if (planets[1].y < WINDOW_HEIGHT/2) then | ||||
| firstShip.y = love.math.random(WINDOW_HEIGHT/2, WINDOW_HEIGHT) | |||||
| firstShip.y = planets[1].y + love.math.random(300, 500) | |||||
| else | else | ||||
| firstShip.y = love.math.random(0, WINDOW_HEIGHT/2) | |||||
| firstShip.y = planets[1].y - love.math.random(300, 500) | |||||
| end | end | ||||
| end | end | ||||
| for i in ipairs(planets) do | for i in ipairs(planets) do | ||||
| @@ -6,6 +6,7 @@ function practice.update(dt) | |||||
| if not levelLoaded then | if not levelLoaded then | ||||
| shipsleft = 1 | shipsleft = 1 | ||||
| planetsleft = 10 | planetsleft = 10 | ||||
| cannonsleft = 10 | |||||
| gameStatus = "setup" | gameStatus = "setup" | ||||
| playbutts = {} | playbutts = {} | ||||
| guibutts = {} | guibutts = {} | ||||
| @@ -60,6 +61,19 @@ function practice.update(dt) | |||||
| for i in ipairs(planets) do | for i in ipairs(planets) do | ||||
| planets[i]:update(dt) | planets[i]:update(dt) | ||||
| end | end | ||||
| for i in ipairs(cannons) do | |||||
| cannons[i]:update(dt) | |||||
| end | |||||
| for i in ipairs(projectiles) do | |||||
| projectiles[i]:update(dt) | |||||
| end | |||||
| for i in ipairs(projectiles) do | |||||
| if projectiles[i].killed then | |||||
| table.remove(projectiles, i) | |||||
| --print("killing") | |||||
| end | |||||
| end | |||||
| currentScore = currentScore + math.sqrt(firstShip.dx^2 + firstShip.dy^2) | currentScore = currentScore + math.sqrt(firstShip.dx^2 + firstShip.dy^2) | ||||
| else | else | ||||
| camera:follow(VCAM.x, VCAM.y) | camera:follow(VCAM.x, VCAM.y) | ||||
| @@ -75,6 +89,12 @@ function practice.draw() | |||||
| for i in ipairs(planets) do | for i in ipairs(planets) do | ||||
| planets[i]:draw(dt) | planets[i]:draw(dt) | ||||
| end | end | ||||
| for i in ipairs(cannons) do | |||||
| cannons[i]:draw(dt) | |||||
| end | |||||
| for i in ipairs(projectiles) do | |||||
| projectiles[i]:draw(dt) | |||||
| end | |||||
| --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30) | --love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30) | ||||
| if shipIsHit then | if shipIsHit then | ||||
| for i, explosion in ipairs(explosions) do | for i, explosion in ipairs(explosions) do | ||||
| @@ -109,12 +129,11 @@ function practice.goBack() | |||||
| gameStatus = "setup" | gameStatus = "setup" | ||||
| levelLoaded = false | levelLoaded = false | ||||
| gameState = "menu" | gameState = "menu" | ||||
| cannons = {} | |||||
| end | end | ||||
| function practice.reset() | function practice.reset() | ||||
| firstShip:reset() | firstShip:reset() | ||||
| for k in pairs(planets) do | |||||
| planets[k] = nil | |||||
| end | |||||
| projectiles = {} | |||||
| shipsleft = 1 | shipsleft = 1 | ||||
| if currentScore > saveData.score then | if currentScore > saveData.score then | ||||
| @@ -123,7 +142,6 @@ function practice.reset() | |||||
| end | end | ||||
| currentScore = 0 | currentScore = 0 | ||||
| shipIsHit = false | shipIsHit = false | ||||
| planetsleft = 10 | |||||
| firstShip.fuel = 99999 | firstShip.fuel = 99999 | ||||
| end | end | ||||
| function practice.GUIControl() | function practice.GUIControl() | ||||
| @@ -38,6 +38,14 @@ table.insert(levels, menu:addButton("Level 2", function () | |||||
| currentLevel = 5 | currentLevel = 5 | ||||
| end | end | ||||
| end )) | end )) | ||||
| table.insert(levels, menu:addButton("Level 6", function () | |||||
| if saveData.levelsBeaten > 4 then | |||||
| menuLoaded = false | |||||
| objReset() | |||||
| gameState = "levelgeneral" | |||||
| currentLevel = 6 | |||||
| end | |||||
| end )) | |||||
| table.insert(levels, menu:addButton("Go Back", function () | table.insert(levels, menu:addButton("Go Back", function () | ||||
| @@ -21,9 +21,16 @@ saveData = { | |||||
| planets = {} | planets = {} | ||||
| buttons = {} | buttons = {} | ||||
| cannons = {} | |||||
| projectiles = {} | |||||
| menu = mainMenu() | menu = mainMenu() | ||||
| function love.load() | function love.load() | ||||
| print(love.filesystem.getAppdataDirectory()) | |||||
| print(love.filesystem.getSaveDirectory()) | |||||
| print(love.filesystem.areSymlinksEnabled()) | |||||
| print(love.filesystem.createDirectory('.')) | |||||
| love.filesystem.newFile("File") | |||||
| 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")() | ||||
| @@ -1,11 +1,24 @@ | |||||
| #Nuclear Gravity (name subjecct for change) | |||||
| # NuclearGravity | |||||
| ## _The long-awaited sequel to NuclearPong (totally not)_ | |||||
| Have you ever used gravity to escape to your base when your spaceship's fuel runs out? no? well you should | |||||
| In this new game you do exactly that. WASD controls camera, everything else is done via the mouse button. | |||||
| NuclearGravity is a game about... well, gravity! | |||||
| You have to strategically place planets in space in order for your ship to use their gravitational fields to get itself to its base. | |||||
| Some nice features include: | |||||
| - Realistic gravity | |||||
| - Practice to beat your score! | |||||
| - More coming... | |||||
| Installation is simple, just download the windows EXE release from the releases tab! | |||||
| If you're on linux, then clone the repo, and use debug.sh to launch the game. Linux binary coming soon! | |||||
| The prerequisites are **love** and **zip** | |||||
| If you're on arch, install the prerequisites with: | |||||
| ``sudo pacman -S love zip | |||||
| `` | |||||
| To launch the game, use debuggame.sh. Lua is required | |||||
| @@ -1,5 +1,6 @@ | |||||
| selectedItem = "none" | selectedItem = "none" | ||||
| local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png") | ||||
| local cannonImage = love.graphics.newImage("entities/enemy/enemy.png") | |||||
| function GUIDraw(mode) | function GUIDraw(mode) | ||||
| --MAIN | --MAIN | ||||
| love.graphics.setColor(1,1,1,1) | love.graphics.setColor(1,1,1,1) | ||||
| @@ -20,13 +21,17 @@ function GUIDraw(mode) | |||||
| 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) | |||||
| for i, explosion in ipairs(explosions) do | |||||
| explosion:render("special") | |||||
| --print("exploding") | |||||
| end | |||||
| if gameState == "practice" then | |||||
| GUIButton(cannonsleft, cannonImage, menuX + 240, menuY+WINDOW_HEIGHT*0.4, function() selectedItem = "cannon" end, 1, 1, {1,1,1,1}, 0) | |||||
| end | |||||
| --PLANET | --PLANET | ||||
| --CANNON | |||||
| GUIButton(planetsleft, planetImage, menuX + 60, menuY+WINDOW_HEIGHT*0.4, function() selectedItem = "planet" end, 0.5, 0.5, {1,1,1,1}, 1.57) | |||||
| --CANNON | |||||
| --PLACING | --PLACING | ||||
| local mx, my = love.mouse.getPosition() | local mx, my = love.mouse.getPosition() | ||||
| @@ -182,6 +187,8 @@ function GUIDraw(mode) | |||||
| if love.keyboard.mouseisReleased then | if love.keyboard.mouseisReleased then | ||||
| love.keyboard.mouseisReleased = false | love.keyboard.mouseisReleased = false | ||||
| table.insert(planets, planet(vmx, vmy, 100000000, 0.3, planetImage)) | table.insert(planets, planet(vmx, vmy, 100000000, 0.3, planetImage)) | ||||
| sounds["planet"]:stop() | |||||
| sounds["planet"]:play() | |||||
| 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 | ||||
| @@ -189,6 +196,21 @@ function GUIDraw(mode) | |||||
| selectedItem = "none" | selectedItem = "none" | ||||
| end | end | ||||
| end | end | ||||
| if selectedItem == "cannon" and mx < menuX then | |||||
| local shipW = cannonImage:getWidth() | |||||
| local shipH = cannonImage:getHeight() | |||||
| love.graphics.draw(cannonImage,mx,my,0, 1, 1, shipW/2, shipH/2) | |||||
| if love.keyboard.mouseisReleased then | |||||
| love.keyboard.mouseisReleased = false | |||||
| table.insert(cannons, enemy(vmx, vmy, true, love.math.random(1,3))) | |||||
| sounds["planet"]:stop() | |||||
| sounds["planet"]:play() | |||||
| cannonsleft = cannonsleft - 1 | |||||
| end | |||||
| if cannonsleft == 0 then | |||||
| selectedItem = "none" | |||||
| end | |||||
| end | |||||
| if selectedItem == "eraser" then | if selectedItem == "eraser" then | ||||
| 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 | ||||
| @@ -232,6 +254,28 @@ function GUIDraw(mode) | |||||
| end | end | ||||
| end | end | ||||
| end | end | ||||
| for j in ipairs(cannons) do | |||||
| if cannons[j].deletable then | |||||
| local hot = (vmx > cannons[j].x-cannons[j].w*0.3/2 and vmx < cannons[j].x+cannons[j].w*0.3 and vmy > cannons[j].y-cannons[j].w*0.3/2 and vmy < cannons[j].y + cannons[j].w*0.3) | |||||
| if hot then | |||||
| cannons[j].color = {1,0,0,1} | |||||
| --print("hot") | |||||
| else | |||||
| cannons[j].color = {1,1,1,1} | |||||
| --print(mx .. " " .. my .. " " .. firstShip.x .. " " .. firstShip.y .. " " .. firstShip.width .. firstShip.height) | |||||
| end | |||||
| local pressed = love.keyboard.mouseisReleased | |||||
| if location == "android" then | |||||
| pressed = love.mouse.isDown(1) | |||||
| end | |||||
| if pressed and hot then | |||||
| love.keyboard.mouseisReleased = false | |||||
| table.remove(cannons, j) | |||||
| cannonsleft = cannonsleft + 1 | |||||
| break | |||||
| end | |||||
| end | |||||
| end | |||||
| end | end | ||||
| --PLACING | --PLACING | ||||
| @@ -239,6 +283,9 @@ function GUIDraw(mode) | |||||
| --REMOVE TOOL | --REMOVE TOOL | ||||
| trashbin = love.graphics.newImage("entities/trashbin.png") | trashbin = love.graphics.newImage("entities/trashbin.png") | ||||
| GUIButton("inf", trashbin, menuX + 60, menuY+WINDOW_HEIGHT*0.6, function() selectedItem = "eraser" end, 1, 1, {1,1,1,1}, 0) | GUIButton("inf", trashbin, menuX + 60, menuY+WINDOW_HEIGHT*0.6, function() selectedItem = "eraser" end, 1, 1, {1,1,1,1}, 0) | ||||
| GUIButton("clr", trashbin, menuX + 240, menuY+WINDOW_HEIGHT*0.6, function() for i in ipairs(planets) do if planets[i].deletable then planetsleft = planetsleft + 1 planets[i] = nil end end for i in ipairs(cannons) do if cannons[i].deletable then cannonsleft = cannonsleft + 1 cannons[i] = nil end end firstShip.x = -9000 | |||||
| firstShip.destX = -9000 | |||||
| shipsleft = 1 end, 1, 1, {0,0,1,1}, 0) | |||||
| --REMOVE TOOL | --REMOVE TOOL | ||||
| --START BUTTON | --START BUTTON | ||||
| @@ -12,6 +12,8 @@ require 'stateMachine' | |||||
| require 'entities/base/base' | require 'entities/base/base' | ||||
| require 'entities/camera/VCAM' | require 'entities/camera/VCAM' | ||||
| require 'src/musicController' | require 'src/musicController' | ||||
| require 'entities/enemy/enemy' | |||||
| require 'entities/enemy/projectile' | |||||
| tick = require 'src/tick' | tick = require 'src/tick' | ||||
| utf8 = require("utf8") | utf8 = require("utf8") | ||||
| serialize = require 'src/ser' | serialize = require 'src/ser' | ||||
| @@ -2,11 +2,13 @@ sounds = { | |||||
| ["boom"] = love.audio.newSource("entities/planet/boom.wav", "static"), | ["boom"] = love.audio.newSource("entities/planet/boom.wav", "static"), | ||||
| ["close"] = love.audio.newSource("entities/planet/close.wav", "static"), | ["close"] = love.audio.newSource("entities/planet/close.wav", "static"), | ||||
| ["appear"] = love.audio.newSource("entities/ship/Appear.wav", "static"), | ["appear"] = love.audio.newSource("entities/ship/Appear.wav", "static"), | ||||
| ["finish"] = love.audio.newSource("entities/ship/Finish.wav", "static") | |||||
| ["finish"] = love.audio.newSource("entities/ship/Finish.wav", "static"), | |||||
| ["planet"] = love.audio.newSource("entities/planet/teleport.wav", "static"), | |||||
| ["launch"] = love.audio.newSource("entities/enemy/rlaunch.wav", "static") | |||||
| } | } | ||||
| music = { | music = { | ||||
| ["menu"] = love.audio.newSource("entities/music/menu.ogg", "static"), | ["menu"] = love.audio.newSource("entities/music/menu.ogg", "static"), | ||||
| ["play"] = love.audio.newSource("entities/music/play.wav", "static") | |||||
| ["play"] = love.audio.newSource("entities/music/play.mp3", "static") | |||||
| } | } | ||||
| mute = false | mute = false | ||||
| function musicController(orders, toggling) | function musicController(orders, toggling) | ||||