diff --git a/bigballmode.lua b/bigballmode.lua new file mode 100644 index 0000000..88dad01 --- /dev/null +++ b/bigballmode.lua @@ -0,0 +1,25 @@ +Class = require 'hump/class' +require 'powerupmode' +require 'settings' + +BigBallMode = Class{ + __include = PowerUpMode, + + init = function(self) + PowerUpMode.init(self, 10) + end; + + update = function(self, dt) + PowerUpMode.update(self, dt) + end; + + activate = function(self, plane) + PowerUpMode.activate(self, plane) + plane.machinegun:setType("bigball") + end; + + deactivate = function(self) + PowerUpMode.deactivate(self) + self.plane.machinegun:setType(PLANE_DEFAULT_GUN) + end; +} \ No newline at end of file diff --git a/chaingunmode.lua b/chaingunmode.lua index 4cf494e..2eb1802 100644 --- a/chaingunmode.lua +++ b/chaingunmode.lua @@ -20,6 +20,6 @@ ChaingunMode = Class{ deactivate = function(self) PowerUpMode.deactivate(self) - self.plane.machinegun:setType("vickers77") + self.plane.machinegun:setType(PLANE_DEFAULT_GUN) end; } \ No newline at end of file diff --git a/conf.lua b/conf.lua index 51851f2..aed99d5 100644 --- a/conf.lua +++ b/conf.lua @@ -8,6 +8,7 @@ function love.conf(t) t.window.width = 1280 t.window.height = 768 t.window.resizable = false + t.window.vsync = false -- LÖVE version t.version = "0.9.1" diff --git a/entities/bigball.lua b/entities/bigball.lua new file mode 100644 index 0000000..e8daba5 --- /dev/null +++ b/entities/bigball.lua @@ -0,0 +1,43 @@ +Class = require 'hump.class' +require 'entities/physicsentity' +require 'entities/animation' +require 'settings' + +local BIGBALL_SOUND = love.audio.newSource("resources/audio/boom9.wav", "static") + +BigBall = Class{ + __includes = Rectangle, + + MAX_LIFETIME = 60 * 10, + img = nil, + frame = 0, + + init = function(self, x, y, level) + local xsize = 2.0 * PIXELS_PER_METER + local ysize = 2.0 * PIXELS_PER_METER + + Rectangle.init(self, x, y, level, "dynamic", 1, xsize, ysize, 50, nil) + self.body:setBullet(true) + self.collisionCategory = 3 + self.fixture:setCategory(self.collisionCategory) + + BIGBALL_SOUND:rewind() + BIGBALL_SOUND:play() + end; + + update = function(self, dt) + Rectangle.update(self, dt) + + self.frame = self.frame + 1 + + if self.frame >= self.MAX_LIFETIME then + self:delete() + end + end; + + draw = function(self) + love.graphics.setColor({0, 0, 255, 255}) + Rectangle.draw(self) + end; +} + diff --git a/entities/bigballpowerup.lua b/entities/bigballpowerup.lua new file mode 100644 index 0000000..8e2277f --- /dev/null +++ b/entities/bigballpowerup.lua @@ -0,0 +1,19 @@ +Class = require 'hump.class' +require 'entities/powerup' +require 'bigballmode' + +local BIGBALLPOWERUP_IMG = love.graphics.newImage("resources/graphics/bigballpowerup.png") +local BIGBALLPOWERUP_QUAD = love.graphics.newQuad(0, 0, 32, 32, 32, 32) + +BigBallPowerUp = Class{ + __includes = PowerUp, + + init = function(self, x, y, level) + PowerUp.init(self, x, y, level, 10, 16) + self.mode = BigBallMode() + end; + + draw = function(self) + love.graphics.draw(BIGBALLPOWERUP_IMG, BIGBALLPOWERUP_QUAD, self.x, self.y, self.angle, 1, 1, 16, 16) + end; +} diff --git a/entities/chaingunpowerup.lua b/entities/chaingunpowerup.lua index 5550868..28fc6a2 100644 --- a/entities/chaingunpowerup.lua +++ b/entities/chaingunpowerup.lua @@ -1,5 +1,6 @@ Class = require 'hump.class' require 'entities/powerup' +require 'chaingunmode' local CHAINGUNPOWERUP_IMG = love.graphics.newImage("resources/graphics/chaingunpowerup.png") local CHAINGUNPOWERUP_QUAD = love.graphics.newQuad(0, 0, 32, 32, 32, 32) @@ -9,6 +10,7 @@ ChaingunPowerUp = Class{ init = function(self, x, y, level) PowerUp.init(self, x, y, level, 10, 16) + self.mode = ChaingunMode() end; draw = function(self) diff --git a/entities/powerup.lua b/entities/powerup.lua index b591b35..6461fc6 100644 --- a/entities/powerup.lua +++ b/entities/powerup.lua @@ -19,6 +19,8 @@ PowerUp = Class{ -- Don't collide with ammo self.fixture:setMask(3) + + self.mode = nil end; draw = function(self) @@ -27,7 +29,7 @@ PowerUp = Class{ update = function(self, dt) PhysicsEntity.update(self, dt) - + self.angle = self.angle + ROTATION_SPEED * dt if self.angle > math.pi * 2 then diff --git a/level_state.lua b/level_state.lua index e8faddc..4fb5941 100644 --- a/level_state.lua +++ b/level_state.lua @@ -2,7 +2,9 @@ Gamestate = require 'hump.gamestate' require 'level' require 'player' require 'scoreboard' +require 'entities/powerup' require 'entities/chaingunpowerup' +require 'entities/bigballpowerup' require 'entities/plane' require 'entities/debug' require 'chaingunmode' @@ -24,6 +26,11 @@ local paused = false local POWERUP_POSSIBILITY = 0.001 +local POWERUPS = { + BigBallPowerUp, + ChaingunPowerUp +} + function level_state:init() end @@ -50,8 +57,6 @@ function level_state:enter(previous, level_file) scoreboards[i] = Scoreboard(x, 20, players[i]) end - - ChaingunPowerUp(750, 750, current_level) end @@ -78,7 +83,8 @@ function level_state:update(dt) if r <= POWERUP_POSSIBILITY then local x = love.math.random(love.window.getWidth()) local y = love.math.random(love.window.getHeight()) - ChaingunPowerUp(x, y, current_level) + + POWERUPS[love.math.random(1, #POWERUPS)](x, y, current_level) end if not paused then @@ -148,13 +154,13 @@ function begin_contact(a, b, coll) local bObj = b:getUserData() if aObj ~= nil and bObj ~= nil then - if aObj:isinstance(Plane) and bObj:isinstance(ChaingunPowerUp) then + if aObj:isinstance(Plane) and bObj:isinstance(PowerUp) then bObj.deleteLater = true - aObj:setPowerUpMode(ChaingunMode()) + aObj:setPowerUpMode(bObj.mode) coll:setEnabled(false) - elseif bObj:isinstance(Plane) and aObj:isinstance(ChaingunPowerUp) then + elseif bObj:isinstance(Plane) and aObj:isinstance(PowerUp) then aObj.deleteLater = true - bObj:setPowerUpMode(ChaingunMode()) + bObj:setPowerUpMode(bObj.mode) coll:setEnabled(false) else aObj:wasHit() diff --git a/machinegun.lua b/machinegun.lua index 67dfced..7be5bff 100644 --- a/machinegun.lua +++ b/machinegun.lua @@ -3,6 +3,7 @@ Class = require 'hump/class' require 'entities/vickers77' require 'entities/tinyshot' +require 'entities/bigball' GUNS = { chaingun = { @@ -12,6 +13,13 @@ GUNS = { damage = 5 }, + bigball = { + interval = 1, + force = 1000000, + projectile = BigBall, + damage = 0 + }, + vickers77 = { interval = 0.1, force = 300000, @@ -31,18 +39,15 @@ MachineGun = Class{ end; update = function(self, dt) - if self.shooting then - if self.since_last_shot >= self.gun['interval'] then - self:fire() - self.since_last_shot = 0 - else - self.since_last_shot = self.since_last_shot + dt - end + if self.shooting and self.since_last_shot >= self.gun['interval'] then + self:fire() + self.since_last_shot = 0 + else + self.since_last_shot = self.since_last_shot + dt end end; setType = function(self, type) - print(GUNS['vickers77']) self.gun = GUNS[type] self.since_last_shot = 0 end; @@ -62,7 +67,6 @@ MachineGun = Class{ startShooting = function(self) self.shooting = true - self.since_last_shot = self.gun['interval'] end; stopShooting = function(self) diff --git a/powerupmode.lua b/powerupmode.lua index 0db5957..e58bf87 100644 --- a/powerupmode.lua +++ b/powerupmode.lua @@ -6,10 +6,13 @@ PowerUpMode = Class{ self.age = 0 self.duration = duration self.plane = nil + self.active = false end; update = function(self, dt) - self.age = self.age + dt + if active then + self.age = self.age + dt + end if self.age >= self.duration then self:deactivate() @@ -27,6 +30,7 @@ PowerUpMode = Class{ activate = function(self, plane) plane.powerupmode = self self.plane = plane + self.active = true end; deactivate = function(self) diff --git a/resources/audio/boom9.wav b/resources/audio/boom9.wav new file mode 100755 index 0000000..c413f9d Binary files /dev/null and b/resources/audio/boom9.wav differ diff --git a/resources/graphics/bigballpowerup.png b/resources/graphics/bigballpowerup.png new file mode 100644 index 0000000..4bb1a1c Binary files /dev/null and b/resources/graphics/bigballpowerup.png differ diff --git a/settings.lua b/settings.lua index be05d6f..fa7d83c 100644 --- a/settings.lua +++ b/settings.lua @@ -26,7 +26,7 @@ KEYMAP = { } } -PLANE_HEALTH = 1000 +PLANE_HEALTH = 500 PLANE_DEFAULT_GUN = "vickers77" SCOREBOARD_WIDTH = 250