Add big ball and fix bonuses

This commit is contained in:
Mikko Ahlroth 2014-10-19 06:19:01 +03:00
parent 70127fbfa3
commit fc1e4dfdd6
13 changed files with 126 additions and 20 deletions

25
bigballmode.lua Normal file
View file

@ -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;
}

View file

@ -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;
}

View file

@ -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"

43
entities/bigball.lua Normal file
View file

@ -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;
}

View file

@ -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;
}

View file

@ -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)

View file

@ -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

View file

@ -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()

View file

@ -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)

View file

@ -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)

BIN
resources/audio/boom9.wav Executable file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -26,7 +26,7 @@ KEYMAP = {
}
}
PLANE_HEALTH = 1000
PLANE_HEALTH = 500
PLANE_DEFAULT_GUN = "vickers77"
SCOREBOARD_WIDTH = 250