fysplane/entities/tinyshot.lua

52 lines
1.4 KiB
Lua
Raw Normal View History

2014-10-18 17:20:37 +00:00
Class = require 'hump.class'
require 'entities/physicsentity'
require 'entities/animation'
2014-10-18 17:20:37 +00:00
require 'settings'
2014-10-18 19:15:30 +00:00
local TINYSHOT_SOUND = love.audio.newSource("resources/audio/chaingun.mp3", "static")
local explosionFrames = AnimationFrames("resources/graphics/miniexplosion-%04d.png", 4, 15, false)
2014-10-18 17:20:37 +00:00
TinyShot = Class{
2014-10-18 17:20:37 +00:00
__includes = Rectangle,
MAX_LIFETIME = 60 * 5,
img = nil,
frame = 0,
init = function(self, x, y, level)
2014-10-19 00:07:09 +00:00
local xsize = 0.3 * PIXELS_PER_METER
local ysize = 0.3 * PIXELS_PER_METER
2014-10-18 17:20:37 +00:00
2014-10-19 01:35:07 +00:00
Rectangle.init(self, x, y, level, "dynamic", 0.2, xsize, ysize, 1, nil)
2014-10-18 17:20:37 +00:00
self.body:setBullet(true)
2014-10-19 01:35:07 +00:00
self.collisionCategory = 3
self.fixture:setCategory(self.collisionCategory)
2014-10-18 17:20:37 +00:00
TINYSHOT_SOUND:rewind()
TINYSHOT_SOUND:play()
2014-10-18 17:20:37 +00:00
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;
wasHitBy = function(self, by)
Animation(self.body:getX(), self.body:getY(), self.level, explosionFrames)
end;
2014-10-18 17:20:37 +00:00
draw = function(self)
love.graphics.setColor({255, 0, 0, 255})
local ratio = 1.0 / 2400 * PIXELS_PER_METER
local velX, velY = self.body:getLinearVelocity()
love.graphics.line(self.body:getX(), self.body:getY(),
self.body:getX() + velX * ratio, self.body:getY() + velY * ratio)
2014-10-18 17:20:37 +00:00
end;
}