Add chaingun
This commit is contained in:
parent
4b0191e2f9
commit
d6500622fd
6 changed files with 45 additions and 7 deletions
40
entities/chaingun.lua
Normal file
40
entities/chaingun.lua
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
Class = require 'hump.class'
|
||||||
|
require 'entities/physicsentity'
|
||||||
|
require 'settings'
|
||||||
|
|
||||||
|
CHAINGUN_SOUND = love.audio.newSource("resources/audio/chaingun.mp3", "static")
|
||||||
|
|
||||||
|
Chaingun = Class{
|
||||||
|
__includes = Rectangle,
|
||||||
|
|
||||||
|
MAX_LIFETIME = 60 * 5,
|
||||||
|
img = nil,
|
||||||
|
frame = 0,
|
||||||
|
|
||||||
|
init = function(self, x, y, level)
|
||||||
|
local xsize = 0.2 * PIXELS_PER_METER
|
||||||
|
local ysize = 0.2 * PIXELS_PER_METER
|
||||||
|
|
||||||
|
Rectangle.init(self, x, y, level, "dynamic", 0.2, xsize, ysize, 1000, nil)
|
||||||
|
self.body:setBullet(true)
|
||||||
|
|
||||||
|
CHAINGUN_SOUND:rewind()
|
||||||
|
CHAINGUN_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({255, 0, 0, 255})
|
||||||
|
Rectangle.draw(self)
|
||||||
|
end;
|
||||||
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ PhysicsEntity = Class{
|
||||||
|
|
||||||
-- Reimplement
|
-- Reimplement
|
||||||
draw = function(self)
|
draw = function(self)
|
||||||
love.graphics.setColor({255, 255, 255, 255})
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
-- Only update if physics is not static
|
-- Only update if physics is not static
|
||||||
|
|
|
@ -31,7 +31,6 @@ Rectangle = Class{
|
||||||
end;
|
end;
|
||||||
|
|
||||||
draw = function(self)
|
draw = function(self)
|
||||||
PhysicsEntity.draw(self)
|
|
||||||
if self.img ~= nil then
|
if self.img ~= nil then
|
||||||
love.graphics.draw(self.img, self.quad, self.body:getX(), self.body:getY(), self.angle, 1, 1, self.xsize / 2, self.ysize / 2)
|
love.graphics.draw(self.img, self.quad, self.body:getX(), self.body:getY(), self.angle, 1, 1, self.xsize / 2, self.ysize / 2)
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,7 +13,7 @@ Vickers77 = Class{
|
||||||
|
|
||||||
init = function(self, x, y, level)
|
init = function(self, x, y, level)
|
||||||
local xsize = 0.35 * PIXELS_PER_METER
|
local xsize = 0.35 * PIXELS_PER_METER
|
||||||
local ysize = 0.1 * PIXELS_PER_METER
|
local ysize = 0.2 * PIXELS_PER_METER
|
||||||
|
|
||||||
Rectangle.init(self, x, y, level, "dynamic", 0.2, xsize, ysize, 1000, nil)
|
Rectangle.init(self, x, y, level, "dynamic", 0.2, xsize, ysize, 1000, nil)
|
||||||
self.body:setBullet(true)
|
self.body:setBullet(true)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Gamestate = require 'hump.gamestate'
|
Gamestate = require 'hump.gamestate'
|
||||||
require 'level'
|
require 'level'
|
||||||
require 'player'
|
require 'player'
|
||||||
require 'entities/vickers77'
|
require 'entities/chaingun'
|
||||||
|
|
||||||
level_state = {}
|
level_state = {}
|
||||||
|
|
||||||
|
@ -73,9 +73,9 @@ function level_state:keypressed(key, unicode)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local shot = Vickers77(200, 700, current_level)
|
local shot = Chaingun(200, 700, current_level)
|
||||||
shot:setAngle(-89)
|
shot:setAngle(-45)
|
||||||
shot:punch(-89, 10000)
|
shot:punch(-45, 100000)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
resources/audio/chaingun.mp3
Normal file
BIN
resources/audio/chaingun.mp3
Normal file
Binary file not shown.
Loading…
Reference in a new issue