diff --git a/assets.lua b/assets.lua index 51a70fe..273bc1e 100644 --- a/assets.lua +++ b/assets.lua @@ -11,7 +11,8 @@ multilily = lily.loadMulti({ {lily.newImage, "assets/ships/particle.png"}, {lily.newImage, "assets/particle.png"}, {lily.newImage, "assets/tiles/gf.png"}, - {lily.newImage, "assets/explosion.png"} + {lily.newImage, "assets/explosion.png"}, + {lily.newImage, "assets/weapons/bullet.png"} }) multilily:onComplete(function(_, lilies) gameLogo = lilies[1][1] @@ -27,6 +28,7 @@ multilily:onComplete(function(_, lilies) titleParticle = lilies[11][1] tileGroundFull = lilies[12][1] explosionParticle = lilies[13][1] + bulletShot = lilies[14][1] windowWidth = love.graphics.getWidth() windowHeight = love.graphics.getHeight() diff --git a/main.lua b/main.lua index 3c517ce..3a8e4dc 100644 --- a/main.lua +++ b/main.lua @@ -44,6 +44,8 @@ function love.load() require "ship/excaliburiv" require "ship/decorator" + require "bullet/bullet" + require "planet/planet" LoadScene = LoadScene() diff --git a/scene/game.lua b/scene/game.lua index 66decf8..d410e2b 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -51,6 +51,8 @@ function GameScene:init() 1,1,1,0.3 ) + GameScene.bullets = {} + GameScene.explosionObj = {angle=100, radius=100} GameScene.godsrayObj = {weight=0} @@ -60,12 +62,27 @@ end function GameScene:update(dt) + local bLen = table.getn(GameScene.bullets) + if bLen > 0 then + for y=1, bLen do + if GameScene.bullets[bLen-(y-1)].finished then + table.remove(GameScene.bullets, bLen-(y-1)) + end + end + end + if currentPlayer.death == false and currentPlanet.hasGeneratedMap == true then pSystem:update(dt) GameScene:updateInput(dt) GameScene:updateBounds(dt) + bLen = table.getn(GameScene.bullets) + if bLen > 0 then + for y=1, bLen do + GameScene.bullets[y]:update(dt) + end + end GameScene:checkCollisions() else @@ -84,7 +101,6 @@ function GameScene:draw() end if currentPlayer.death == false then - love.graphics.setColor(1,1,1, 1) love.graphics.draw(pSystem, currentPlayer.px-2, currentPlayer.py) love.graphics.draw(pSystem, currentPlayer.px+2, currentPlayer.py) @@ -97,6 +113,14 @@ function GameScene:draw() currentPlayer.ship.image:getWidth()/2, currentPlayer.ship.image:getHeight()/2 ) + + local bLen = table.getn(GameScene.bullets) + if bLen > 0 then + for y=1, bLen do + GameScene.bullets[y]:draw() + end + end + else love.graphics.draw(eSystem, currentPlayer.px, currentPlayer.py) end @@ -125,6 +149,10 @@ function GameScene:drawHud() end love.graphics.print( "death: " .. deathval, 10, 24 ) + love.graphics.print( "wpnrot: " .. currentPlayer.ship.weaponrot .. " cd: " .. currentPlayer.ship.cooldown, 70, 24 ) + + local bLen = table.getn(GameScene.bullets) + love.graphics.print( "bul: " .. bLen, 10, 38 ) end function GameScene:keypressed(key,unicode) @@ -157,13 +185,20 @@ function GameScene:updateInput(dt) local isDown = false local isRight = false - --local hAxis, vAxis, hAxis2, vAxis2 = love.joystick.getAxes(1) - --local axisMargin = 0.5 + local isBUp = false + local isBLeft = false + local isBDown = false + local isBRight = false - isUp = love.keyboard.isDown( "w" )-- or (not (vAxis == nil) and vAxis < -(1-axisMargin)) or (not (vAxis2 == nil) and vAxis2 < -(1-axisMargin)) or love.joystick.isDown(1, 1) - isDown = love.keyboard.isDown( "s" )-- or (not (vAxis == nil) and vAxis > (1-axisMargin)) or (not (vAxis2 == nil) and vAxis2 > (1-axisMargin)) or love.joystick.isDown(1, 2) - isLeft = love.keyboard.isDown( "a" )-- or (not (hAxis == nil) and hAxis < -(1-axisMargin)) or (not (hAxis2 == nil) and hAxis2 < -(1-axisMargin)) or love.joystick.isDown(1, 3) - isRight = love.keyboard.isDown( "d" )-- or (not (hAxis == nil) and hAxis > (1-axisMargin)) or (not (hAxis2 == nil) and hAxis2 > (1-axisMargin)) or love.joystick.isDown(1, 4) + isUp = love.keyboard.isDown( "w" ) + isDown = love.keyboard.isDown( "s" ) + isLeft = love.keyboard.isDown( "a" ) + isRight = love.keyboard.isDown( "d" ) + + isBUp = love.keyboard.isDown( "up" ) + isBDown = love.keyboard.isDown( "down" ) + isBLeft = love.keyboard.isDown( "left" ) + isBRight = love.keyboard.isDown( "right" ) if isUp and isLeft then currentPlayer.rot = 315 @@ -219,6 +254,38 @@ function GameScene:updateInput(dt) if isRight then currentPlayer.px = math.floor(currentPlayer.px + (currentPlayer.ship.speed*currentPlayer.acc)) end + + love.audio.setPosition( currentPlayer.px, currentPlayer.py,0) + + if isBUp and isBLeft then + currentPlayer.ship.weaponrot = 135 + elseif isBUp and isBRight then + currentPlayer.ship.weaponrot = 45 + elseif isBUp then + currentPlayer.ship.weaponrot = 90 + elseif isBDown and isBLeft then + currentPlayer.ship.weaponrot = 225 + elseif isBDown and isBRight then + currentPlayer.ship.weaponrot = 315 + elseif isBDown then + currentPlayer.ship.weaponrot = 270 + elseif isBLeft then + currentPlayer.ship.weaponrot = 180 + elseif isBRight then + currentPlayer.ship.weaponrot = 0 + end + + if currentPlayer.ship.cooldown == 0 then + if isBUp or isBDown or isBLeft or isBRight then + currentPlayer.ship.cooldown = currentPlayer.ship.cooldownPeriod + + local bullet = Bullet( currentPlayer ) + bullet:emit( currentPlayer.px, currentPlayer.py, 0, 0, currentPlayer.ship.weaponrot, 0.5 ) + table.insert(GameScene.bullets, bullet) + end + end + + currentPlayer.ship.cooldown = math.clamp( 0, currentPlayer.ship.cooldown-dt, currentPlayer.ship.cooldownPeriod ) end end @@ -273,7 +340,7 @@ function GameScene:generateExplosionSound(px,py) local soundData = sound:generateSoundData() local source = love.audio.newSource(soundData) - source:setVolume(2) + source:setVolume(1) source:setPosition(px,py) source:play() end diff --git a/ship/blackstar5.lua b/ship/blackstar5.lua index 03c57e6..dc05892 100644 --- a/ship/blackstar5.lua +++ b/ship/blackstar5.lua @@ -6,4 +6,5 @@ function Blackstar5:new() self.image = nil self.speed = 5 self.accIncr = 0.1 + self.cooldownPeriod = 0.1 end diff --git a/ship/decorator.lua b/ship/decorator.lua index 0719449..4c4e1d2 100644 --- a/ship/decorator.lua +++ b/ship/decorator.lua @@ -6,4 +6,5 @@ function Decorator:new() self.image = nil self.speed = 6 self.accIncr = 0.2 + self.cooldownPeriod = 0.3 end diff --git a/ship/excaliburiv.lua b/ship/excaliburiv.lua index d96d3dd..e3bb83b 100644 --- a/ship/excaliburiv.lua +++ b/ship/excaliburiv.lua @@ -6,4 +6,5 @@ function ExcaliburIV:new() self.image = nil self.speed = 4 self.accIncr = 0.3 + self.cooldownPeriod = 0.2 end diff --git a/ship/ship.lua b/ship/ship.lua index 7658c68..3087334 100644 --- a/ship/ship.lua +++ b/ship/ship.lua @@ -3,4 +3,7 @@ Ship = Object.extend(Object) function Ship:new() self.name = ""; self.image = nil + self.weaponrot = 0 + self.cooldown = 0 + self.cooldownPeriod = 100 end diff --git a/vendor/math.lua b/vendor/math.lua index 2176854..12b173d 100644 --- a/vendor/math.lua +++ b/vendor/math.lua @@ -3,6 +3,18 @@ function math.variance(seed, variance) return seed * ((math.random( 100 - (variance/2), 100 + (variance/2)))/100) end +--Returns the x vector from {len} and {dir} +function math.lengthdir_x( len, dir ) + local dir = math.rad( dir ) + return math.cos( dir ) * len +end + +--Returns the y vector from {len} and {dir} +function math.lengthdir_y( len, dir ) + local dir = math.rad( dir ) + return -math.sin( dir ) * len +end + -- Averages an arbitrary number of angles (in radians). function math.averageAngles(...) local x,y = 0,0