Compare with Previous |
Blame |
View Log
Shockwave = class(Turbine.UI.Window);
local importPath = getfenv(1)._.Name;
local imagePath = string.gsub(string.gsub(importPath, "%.Shockwave$", ""), "%.", "/");
function Shockwave:Constructor()
Turbine.UI.Window.Constructor(self);
self:SetBackground(imagePath .. "/blurry_ring.tga");
self:SetVisible(true);
self:SetMouseVisible(false);
self:SetStretchMode(2); -- resize to image's native size
self:SetStretchMode(1); -- enable scaling
self.x, self.y = self:GetPosition();
self.width = self:GetWidth();
end
function Shockwave:SetCenter(x, y)
self.x, self.y = x, y;
local offset = math.floor(self.width / 2 + 0.5);
self:SetPosition(x - offset, y - offset);
end
function Shockwave:SetDiameter(diameter)
self.width = math.floor(diameter * 1.367 + 0.5);
self:SetSize(self.width, self.width);
self:SetCenter(self.x, self.y);
end
function Shockwave:GetDiameter()
return math.floor(self.width / 1.367 + 0.5);
end
function Shockwave:Explode()
self.startTime = Turbine.Engine.GetGameTime();
self.duration = 1.0;
self.startDiameter = self:GetDiameter();
local displayWidth, displayHeight = Turbine.UI.Display:GetSize();
local maxRadius = math.max(self.x, displayWidth - self.x, self.y, displayHeight - self.y);
self.sizeIncrease = 2 * maxRadius - self.startDiameter;
self.prevProgress = 0;
self:SetWantsUpdates(true);
end
function Shockwave:Update()
local progress = (Turbine.Engine.GetGameTime() - self.startTime) / self.duration;
if ((progress - self.prevProgress) > 0.05) then
-- Enforce at least 20 frames of display
progress = self.prevProgress + 0.05;
end
if (progress >= 1) then
self:Close();
else
self:SetOpacity(1 - progress);
self:SetDiameter(self.startDiameter + progress * self.sizeIncrease);
end
self.prevProgress = progress;
end
function Shockwave:Close()
self:SetVisible(false);
self:SetWantsUpdates(false);
DoCallbacks(self, "Closing");
Turbine.UI.Window.Close(self);
end
Compare with Previous |
Blame
All times are GMT -5. The time now is 12:27 PM.