bullets and sounds
This commit is contained in:
parent
c555cb0e76
commit
a6ecbfd7f0
8 changed files with 98 additions and 9 deletions
|
@ -11,7 +11,8 @@ multilily = lily.loadMulti({
|
||||||
{lily.newImage, "assets/ships/particle.png"},
|
{lily.newImage, "assets/ships/particle.png"},
|
||||||
{lily.newImage, "assets/particle.png"},
|
{lily.newImage, "assets/particle.png"},
|
||||||
{lily.newImage, "assets/tiles/gf.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)
|
multilily:onComplete(function(_, lilies)
|
||||||
gameLogo = lilies[1][1]
|
gameLogo = lilies[1][1]
|
||||||
|
@ -27,6 +28,7 @@ multilily:onComplete(function(_, lilies)
|
||||||
titleParticle = lilies[11][1]
|
titleParticle = lilies[11][1]
|
||||||
tileGroundFull = lilies[12][1]
|
tileGroundFull = lilies[12][1]
|
||||||
explosionParticle = lilies[13][1]
|
explosionParticle = lilies[13][1]
|
||||||
|
bulletShot = lilies[14][1]
|
||||||
|
|
||||||
windowWidth = love.graphics.getWidth()
|
windowWidth = love.graphics.getWidth()
|
||||||
windowHeight = love.graphics.getHeight()
|
windowHeight = love.graphics.getHeight()
|
||||||
|
|
2
main.lua
2
main.lua
|
@ -44,6 +44,8 @@ function love.load()
|
||||||
require "ship/excaliburiv"
|
require "ship/excaliburiv"
|
||||||
require "ship/decorator"
|
require "ship/decorator"
|
||||||
|
|
||||||
|
require "bullet/bullet"
|
||||||
|
|
||||||
require "planet/planet"
|
require "planet/planet"
|
||||||
|
|
||||||
LoadScene = LoadScene()
|
LoadScene = LoadScene()
|
||||||
|
|
|
@ -51,6 +51,8 @@ function GameScene:init()
|
||||||
1,1,1,0.3
|
1,1,1,0.3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
GameScene.bullets = {}
|
||||||
|
|
||||||
GameScene.explosionObj = {angle=100, radius=100}
|
GameScene.explosionObj = {angle=100, radius=100}
|
||||||
GameScene.godsrayObj = {weight=0}
|
GameScene.godsrayObj = {weight=0}
|
||||||
|
|
||||||
|
@ -60,12 +62,27 @@ end
|
||||||
|
|
||||||
function GameScene:update(dt)
|
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
|
if currentPlayer.death == false and currentPlanet.hasGeneratedMap == true then
|
||||||
pSystem:update(dt)
|
pSystem:update(dt)
|
||||||
|
|
||||||
GameScene:updateInput(dt)
|
GameScene:updateInput(dt)
|
||||||
GameScene:updateBounds(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()
|
GameScene:checkCollisions()
|
||||||
else
|
else
|
||||||
|
@ -84,7 +101,6 @@ function GameScene:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
if currentPlayer.death == false then
|
if currentPlayer.death == false then
|
||||||
|
|
||||||
love.graphics.setColor(1,1,1, 1)
|
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)
|
||||||
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:getWidth()/2,
|
||||||
currentPlayer.ship.image:getHeight()/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
|
else
|
||||||
love.graphics.draw(eSystem, currentPlayer.px, currentPlayer.py)
|
love.graphics.draw(eSystem, currentPlayer.px, currentPlayer.py)
|
||||||
end
|
end
|
||||||
|
@ -125,6 +149,10 @@ function GameScene:drawHud()
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.print( "death: " .. deathval, 10, 24 )
|
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
|
end
|
||||||
|
|
||||||
function GameScene:keypressed(key,unicode)
|
function GameScene:keypressed(key,unicode)
|
||||||
|
@ -157,13 +185,20 @@ function GameScene:updateInput(dt)
|
||||||
local isDown = false
|
local isDown = false
|
||||||
local isRight = false
|
local isRight = false
|
||||||
|
|
||||||
--local hAxis, vAxis, hAxis2, vAxis2 = love.joystick.getAxes(1)
|
local isBUp = false
|
||||||
--local axisMargin = 0.5
|
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)
|
isUp = love.keyboard.isDown( "w" )
|
||||||
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)
|
isDown = love.keyboard.isDown( "s" )
|
||||||
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)
|
isLeft = love.keyboard.isDown( "a" )
|
||||||
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)
|
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
|
if isUp and isLeft then
|
||||||
currentPlayer.rot = 315
|
currentPlayer.rot = 315
|
||||||
|
@ -219,6 +254,38 @@ function GameScene:updateInput(dt)
|
||||||
if isRight then
|
if isRight then
|
||||||
currentPlayer.px = math.floor(currentPlayer.px + (currentPlayer.ship.speed*currentPlayer.acc))
|
currentPlayer.px = math.floor(currentPlayer.px + (currentPlayer.ship.speed*currentPlayer.acc))
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -273,7 +340,7 @@ function GameScene:generateExplosionSound(px,py)
|
||||||
|
|
||||||
local soundData = sound:generateSoundData()
|
local soundData = sound:generateSoundData()
|
||||||
local source = love.audio.newSource(soundData)
|
local source = love.audio.newSource(soundData)
|
||||||
source:setVolume(2)
|
source:setVolume(1)
|
||||||
source:setPosition(px,py)
|
source:setPosition(px,py)
|
||||||
source:play()
|
source:play()
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,4 +6,5 @@ function Blackstar5:new()
|
||||||
self.image = nil
|
self.image = nil
|
||||||
self.speed = 5
|
self.speed = 5
|
||||||
self.accIncr = 0.1
|
self.accIncr = 0.1
|
||||||
|
self.cooldownPeriod = 0.1
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,4 +6,5 @@ function Decorator:new()
|
||||||
self.image = nil
|
self.image = nil
|
||||||
self.speed = 6
|
self.speed = 6
|
||||||
self.accIncr = 0.2
|
self.accIncr = 0.2
|
||||||
|
self.cooldownPeriod = 0.3
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,4 +6,5 @@ function ExcaliburIV:new()
|
||||||
self.image = nil
|
self.image = nil
|
||||||
self.speed = 4
|
self.speed = 4
|
||||||
self.accIncr = 0.3
|
self.accIncr = 0.3
|
||||||
|
self.cooldownPeriod = 0.2
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,4 +3,7 @@ Ship = Object.extend(Object)
|
||||||
function Ship:new()
|
function Ship:new()
|
||||||
self.name = "";
|
self.name = "";
|
||||||
self.image = nil
|
self.image = nil
|
||||||
|
self.weaponrot = 0
|
||||||
|
self.cooldown = 0
|
||||||
|
self.cooldownPeriod = 100
|
||||||
end
|
end
|
||||||
|
|
12
vendor/math.lua
vendored
12
vendor/math.lua
vendored
|
@ -3,6 +3,18 @@ function math.variance(seed, variance)
|
||||||
return seed * ((math.random( 100 - (variance/2), 100 + (variance/2)))/100)
|
return seed * ((math.random( 100 - (variance/2), 100 + (variance/2)))/100)
|
||||||
end
|
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).
|
-- Averages an arbitrary number of angles (in radians).
|
||||||
function math.averageAngles(...)
|
function math.averageAngles(...)
|
||||||
local x,y = 0,0
|
local x,y = 0,0
|
||||||
|
|
Loading…
Reference in a new issue