ExperimentalGear/scripts/graphics/background.lua

137 lines
4.2 KiB
Lua

local Display = require("scripts.graphics.display")
---@class Background
local Background = {
-- Images
bgBaseImage = gfx.CreateSkinImage("components/background/bg.png", 0),
dotsOverlayImage = gfx.CreateSkinImage("components/background/dots.png", 0),
valkRasisImage = gfx.CreateSkinImage("components/background/rasis_panel.png", 0),
valkGraceImage = gfx.CreateSkinImage("components/background/grace_panel.png", 0),
mainRingImage = gfx.CreateSkinImage("components/background/main_ring.png", 0),
blueFlareImage = gfx.CreateSkinImage("components/background/blue_flare.png", 0),
pinkFlareImage = gfx.CreateSkinImage("components/background/pink_flare.png", 0),
hexagonImages = {
gfx.CreateSkinImage("components/background/hex1.png", 0),
gfx.CreateSkinImage("components/background/hex2.png", 0),
gfx.CreateSkinImage("components/background/hex3.png", 0)
},
-- Animation related
animationProgress = 0
}
function Background:drawValkyrie(spinProgressionScale, valkImage)
local w = 1390 * 0.7
local h = 3356 * 0.7
local piProgression = spinProgressionScale * 2 * math.pi
local distanceScaleMultiplier = 0.3 + 0.7 * ((1 + math.sin(piProgression)) / 2)
local xScale = math.sin(piProgression) * distanceScaleMultiplier;
local yScale = 1 * distanceScaleMultiplier
gfx.Save()
local xTranslate = math.sin(piProgression + 2) * 0.6 * Display.design.width + 0.3 * Display.design.width
local yTranslate = (1 - distanceScaleMultiplier) * Display.design.height * 0.4
gfx.Translate(xTranslate, yTranslate)
-- gfx.Scale(xScale, yScale)
gfx.SkewY((1 + math.sin(piProgression + 0.5 * math.pi)) / 2 * -0.3)
--gfx.SkewX(-math.sin(piProgression)*0.2)
gfx.ImageRect(0, 0, w * xScale, h * yScale, valkImage, 0.5, 0);
gfx.Restore()
-- ===================== Draw the inner one
gfx.Save()
xTranslate = math.sin(piProgression + 2) * 0.57 * Display.design.width + 0.3 * Display.design.width
yTranslate = (1 - distanceScaleMultiplier) * Display.design.height * 0.4
gfx.Translate(xTranslate, yTranslate)
-- gfx.Scale(xScale, yScale)
gfx.SkewY((1 + math.sin(piProgression + 0.5 * math.pi)) / 2 * -0.3)
--gfx.SkewX(-math.sin(piProgression)*0.2)
gfx.ImageRect(0, 0, w * xScale, h * yScale, valkImage, 0.5, 0);
gfx.Restore()
end
function Background:drawValkyries()
gfx.Save()
gfx.Rotate(-0.3)
self:drawValkyrie(self.animationProgress, self.valkRasisImage)
self:drawValkyrie(self.animationProgress + 0.25, self.valkGraceImage)
self:drawValkyrie(self.animationProgress + 0.50, self.valkRasisImage)
self:drawValkyrie(self.animationProgress + 0.75, self.valkGraceImage)
gfx.Restore()
end
function Background:drawRings()
gfx.Save()
gfx.BeginPath()
gfx.SkewX(-0.95)
gfx.Translate(675, 225)
gfx.Rotate(-self.animationProgress * 2 * math.pi);
gfx.Translate(-200, -200)
gfx.ImageRect(0, 0, 400, 400, self.mainRingImage, 0.5, 0);
gfx.Restore()
end
function Background:drawHexagons()
gfx.ImageRect(0, 0, Display.design.width, Display.design.height, self.hexagonImages[1], 1, 0);
gfx.ImageRect(0, 0, Display.design.width, Display.design.height, self.hexagonImages[2], 1, 0);
gfx.ImageRect(0, 0, Display.design.width, Display.design.height, self.hexagonImages[3], 1, 0);
end
function Background:drawFlares()
gfx.ImageRect(0, 0, Display.design.width, Display.design.height, self.blueFlareImage, 1, 0);
gfx.ImageRect(0, 0, Display.design.width, Display.design.height, self.pinkFlareImage, 1, 0);
end
function Background:render()
gfx.Save()
gfx.ResetTransform()
Display.transformToScreenSpace()
gfx.ImageRect(0, 0, Display.design.width, Display.design.height, self.bgBaseImage, 1, 0);
self:drawRings();
self:drawHexagons();
self:drawFlares();
self:drawValkyries();
gfx.ImageRect(0, 0, Display.design.width, Display.design.height, self.dotsOverlayImage, 1, 0);
gfx.Restore()
end
function Background:update(deltaTime)
Display.updateResolution()
self.animationProgress = self.animationProgress + deltaTime / 20;
if (self.animationProgress > 1) then
self.animationProgress = 0;
end
end
return {
Background = Background
}