ExperimentalGear/scripts/graphics/background.lua

137 lines
4.2 KiB
Lua
Raw Normal View History

2024-02-02 02:50:48 +01:00
local Display = require("scripts.graphics.display")
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
---@class Background
local Background = {
-- Images
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
bgBaseImage = gfx.CreateSkinImage("components/background/bg.png", 0),
dotsOverlayImage = gfx.CreateSkinImage("components/background/dots.png", 0),
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
valkRasisImage = gfx.CreateSkinImage("components/background/rasis_panel.png", 0),
valkGraceImage = gfx.CreateSkinImage("components/background/grace_panel.png", 0),
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
mainRingImage = gfx.CreateSkinImage("components/background/main_ring.png", 0),
2021-08-22 19:15:18 +02:00
2024-02-02 02:50:48 +01:00
blueFlareImage = gfx.CreateSkinImage("components/background/blue_flare.png", 0),
pinkFlareImage = gfx.CreateSkinImage("components/background/pink_flare.png", 0),
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
hexagonImages = {
gfx.CreateSkinImage("components/background/hex1.png", 0),
gfx.CreateSkinImage("components/background/hex2.png", 0),
gfx.CreateSkinImage("components/background/hex3.png", 0)
},
2021-08-22 20:00:36 +02:00
2024-02-02 02:50:48 +01:00
-- Animation related
animationProgress = 0
2021-08-22 20:00:36 +02:00
}
2024-02-02 02:50:48 +01:00
function Background:drawValkyrie(spinProgressionScale, valkImage)
local w = 1390 * 0.7
local h = 3356 * 0.7
local piProgression = spinProgressionScale * 2 * math.pi
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
local distanceScaleMultiplier = 0.3 + 0.7 * ((1 + math.sin(piProgression)) / 2)
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
local xScale = math.sin(piProgression) * distanceScaleMultiplier;
local yScale = 1 * distanceScaleMultiplier
2021-08-21 13:49:51 +02:00
gfx.Save()
2024-02-02 02:50:48 +01:00
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)
2021-08-22 19:15:18 +02:00
--gfx.SkewX(-math.sin(piProgression)*0.2)
2024-02-02 02:50:48 +01:00
gfx.ImageRect(0, 0, w * xScale, h * yScale, valkImage, 0.5, 0);
2021-08-22 19:15:18 +02:00
2024-02-02 02:50:48 +01:00
gfx.Restore()
2021-08-21 13:49:51 +02:00
2021-08-22 19:15:18 +02:00
-- ===================== Draw the inner one
gfx.Save()
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
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)
2021-08-22 19:15:18 +02:00
--gfx.SkewX(-math.sin(piProgression)*0.2)
2024-02-02 02:50:48 +01:00
gfx.ImageRect(0, 0, w * xScale, h * yScale, valkImage, 0.5, 0);
2021-08-22 19:15:18 +02:00
2024-02-02 02:50:48 +01:00
gfx.Restore()
2021-08-21 13:49:51 +02:00
end
2024-02-02 02:50:48 +01:00
function Background:drawValkyries()
2021-08-22 19:15:18 +02:00
gfx.Save()
2021-08-21 13:49:51 +02:00
2021-08-22 19:15:18 +02:00
gfx.Rotate(-0.3)
2024-02-02 02:50:48 +01:00
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)
2021-08-22 19:15:18 +02:00
gfx.Restore()
end
2024-02-02 02:50:48 +01:00
function Background:drawRings()
2021-08-22 19:15:18 +02:00
gfx.Save()
gfx.BeginPath()
gfx.SkewX(-0.95)
2024-02-02 02:50:48 +01:00
gfx.Translate(675, 225)
2021-08-22 19:15:18 +02:00
2024-02-02 02:50:48 +01:00
gfx.Rotate(-self.animationProgress * 2 * math.pi);
gfx.Translate(-200, -200)
2021-08-22 19:15:18 +02:00
2024-02-02 02:50:48 +01:00
gfx.ImageRect(0, 0, 400, 400, self.mainRingImage, 0.5, 0);
2021-08-22 19:15:18 +02:00
gfx.Restore()
2021-08-21 13:49:51 +02:00
end
2024-02-02 02:50:48 +01:00
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);
2021-08-22 20:00:36 +02:00
end
2024-02-02 02:50:48 +01:00
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
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
function Background:render()
gfx.Save()
2021-08-22 19:15:18 +02:00
2024-02-02 02:50:48 +01:00
gfx.ResetTransform()
Display.transformToScreenSpace()
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
gfx.ImageRect(0, 0, Display.design.width, Display.design.height, self.bgBaseImage, 1, 0);
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
self:drawRings();
self:drawHexagons();
self:drawFlares();
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
self:drawValkyries();
2021-08-21 13:49:51 +02:00
2024-02-02 02:50:48 +01:00
gfx.ImageRect(0, 0, Display.design.width, Display.design.height, self.dotsOverlayImage, 1, 0);
2021-08-21 13:49:51 +02:00
gfx.Restore()
end
2024-02-02 02:50:48 +01:00
function Background:update(deltaTime)
Display.updateResolution()
self.animationProgress = self.animationProgress + deltaTime / 20;
if (self.animationProgress > 1) then
self.animationProgress = 0;
end
end
2021-08-21 13:49:51 +02:00
return {
2024-02-02 02:50:48 +01:00
Background = Background
}