fysplane/powerupmode.lua

40 lines
1,022 B
Lua
Raw Normal View History

2014-10-18 22:46:27 +00:00
Class = require 'hump/class'
require 'settings'
PowerUpMode = Class{
init = function(self, duration)
self.age = 0
self.duration = duration
2014-10-18 23:02:50 +00:00
self.plane = nil
2014-10-19 03:19:01 +00:00
self.active = false
2014-10-18 22:46:27 +00:00
end;
update = function(self, dt)
2014-10-19 03:51:53 +00:00
if self.active then
2014-10-19 03:19:01 +00:00
self.age = self.age + dt
end
2014-10-18 22:46:27 +00:00
2014-10-18 23:02:50 +00:00
if self.age >= self.duration then
2014-10-18 22:46:27 +00:00
self:deactivate()
end
end;
draw = function(self, x, y)
2014-10-19 03:51:53 +00:00
local age_ratio = self.age / self.duration
local start_color = {255, 0, 0}
local end_color = {0, 255, 0}
2014-10-18 22:46:27 +00:00
love.graphics.setColor(colorSlide(start_color, end_color, age_ratio))
2014-10-19 03:51:53 +00:00
love.graphics.rectangle("fill", x, y + 60, 50 * (1 - age_ratio), 5)
2014-10-18 22:46:27 +00:00
end;
activate = function(self, plane)
plane.powerupmode = self
2014-10-18 23:02:50 +00:00
self.plane = plane
2014-10-19 03:19:01 +00:00
self.active = true
2014-10-18 22:46:27 +00:00
end;
2014-10-18 23:02:50 +00:00
deactivate = function(self)
self.plane.powerupmode = nil
2014-10-19 03:51:53 +00:00
self.plane.machinegun:setType(PLANE_DEFAULT_GUN)
2014-10-18 22:46:27 +00:00
end;
}