fysplane/entities/powerup.lua

51 lines
1.2 KiB
Lua
Raw Normal View History

2014-10-18 22:46:27 +00:00
Class = require 'hump.class'
require 'entities/physicsentity'
-- rad per second
local ROTATION_SPEED = math.pi / 2
local HIT_SOUND = love.audio.newSource("resources/audio/PowerUp.wav", "static")
2014-10-18 22:46:27 +00:00
PowerUp = Class{
__includes = PhysicsEntity,
2014-10-18 23:02:50 +00:00
init = function(self, x, y, level, lifetime, radius)
2014-10-18 22:46:27 +00:00
PhysicsEntity.init(self, x, y, level, "static", 0)
self.angle = 0
self.age = 0
self.lifetime = lifetime
2014-10-18 23:02:50 +00:00
self.shape = love.physics.newCircleShape(radius)
2014-10-19 01:35:07 +00:00
self.collisionCategory = 2
2014-10-18 23:02:50 +00:00
PhysicsEntity.attachShape(self, 1)
2014-10-19 01:35:07 +00:00
-- Don't collide with ammo
self.fixture:setMask(3)
2014-10-19 03:19:01 +00:00
self.mode = nil
2014-10-18 22:46:27 +00:00
end;
draw = function(self)
-- Noop, implement in child
end;
wasHitBy = function(self, by)
HIT_SOUND:rewind()
HIT_SOUND:play()
end;
2014-10-18 22:46:27 +00:00
update = function(self, dt)
2014-10-18 23:02:50 +00:00
PhysicsEntity.update(self, dt)
2014-10-19 03:19:01 +00:00
2014-10-18 22:46:27 +00:00
self.angle = self.angle + ROTATION_SPEED * dt
if self.angle > math.pi * 2 then
self.angle = self.angle - math.pi * 2
end
self.age = self.age + dt
if self.age > self.lifetime then
self:delete()
end
end;
}