Implemented splash screen
This commit is contained in:
parent
2f01f9f96c
commit
b586a217a3
|
@ -27,8 +27,25 @@ local function filter(tableIn, predicate)
|
|||
return out
|
||||
end
|
||||
|
||||
local function clamp(x, min, max)
|
||||
if x < min then
|
||||
x = min
|
||||
end
|
||||
if x > max then
|
||||
x = max
|
||||
end
|
||||
|
||||
return x
|
||||
end
|
||||
|
||||
local function round(num)
|
||||
return num + (2^52 + 2^51) - (2^52 + 2^51)
|
||||
end
|
||||
|
||||
return {
|
||||
stopMusic = stopMusic,
|
||||
splitString = splitString,
|
||||
filter = filter
|
||||
filter = filter,
|
||||
clamp = clamp,
|
||||
round = round
|
||||
}
|
|
@ -21,7 +21,7 @@ local screens = {
|
|||
local currentScreen = screens.splash;
|
||||
|
||||
|
||||
local handleScreenResponse = function (res)
|
||||
local function handleScreenResponse(res)
|
||||
if (res.eventType == 'switch') then
|
||||
if (not screens[res.toScreen]) then
|
||||
game.Log('Undefined screen ' .. res.toScreen, game.LOGGER_ERROR);
|
||||
|
|
|
@ -1,29 +1,140 @@
|
|||
local Common = require("common.common")
|
||||
local Dim = require("common.dimensions")
|
||||
local BGPattern = require("components.wallpaper")
|
||||
local Easing = require("common.easing")
|
||||
|
||||
local splash1Image = gfx.CreateSkinImage('titlescreen/splash/splash1.png', 0);
|
||||
local splash1BgColor = {182, 0, 20}
|
||||
local splash1Logo = gfx.CreateSkinImage("titlescreen/splash/ksm.png", 0)
|
||||
local splash1LogoWidth, splash1LogoHeight = gfx.ImageSize(splash1Logo)
|
||||
|
||||
local splashTimer = 5;
|
||||
local splash2BgColor = {255, 255, 255}
|
||||
local splash2Logo = gfx.CreateSkinImage("titlescreen/splash/usc2.png", 0)
|
||||
local splash2LogoWidth, splash2LogoHeight = gfx.ImageSize(splash2Logo)
|
||||
|
||||
game.LoadSkinSample('titlescreen/splash/splash1.wav');
|
||||
local splash1SfxPlayed = false;
|
||||
local splashState = "init"
|
||||
local splashTimer = 0
|
||||
local fadeDuration = 0.5
|
||||
local fadeAlpha = 0
|
||||
local splashInitDuration = 1
|
||||
local splash1Duration = 4
|
||||
local splash2Duration = 4
|
||||
|
||||
render = function (deltaTime)
|
||||
gfx.BeginPath();
|
||||
gfx.ImageRect(0, 0, 1080, 1920, splash1Image, 1, 0);
|
||||
game.LoadSkinSample("titlescreen/splash/splash1.wav")
|
||||
local splash1SfxPlayed = false
|
||||
|
||||
splashTimer = splashTimer - deltaTime
|
||||
|
||||
if (not splash1SfxPlayed) then
|
||||
splash1SfxPlayed = true;
|
||||
game.PlaySample('titlescreen/splash/splash1.wav');
|
||||
local function calcFade(splashDuration)
|
||||
local t = splashDuration - splashTimer
|
||||
if t < fadeDuration then
|
||||
game.Log("fade in: ", game.LOGGER_ERROR)
|
||||
fadeAlpha = Easing.linear(t, 0, 255, fadeDuration) -- fade in
|
||||
elseif splashTimer < fadeDuration then
|
||||
game.Log("fade out: ", game.LOGGER_ERROR)
|
||||
fadeAlpha = Easing.linear(splashTimer, 0, 255, fadeDuration) -- fade out
|
||||
else
|
||||
--fadeAlpha = 255
|
||||
end
|
||||
fadeAlpha = Common.round(Common.clamp(fadeAlpha, 0, 255))
|
||||
end
|
||||
|
||||
local function initSplash(deltaTime)
|
||||
if (splashTimer < 0) then
|
||||
splash1SfxPlayed = false;
|
||||
splashTimer = 5;
|
||||
splashState = "splash1"
|
||||
splashTimer = 0
|
||||
return
|
||||
end
|
||||
|
||||
if splashTimer == 0 then
|
||||
splashTimer = splashInitDuration
|
||||
end
|
||||
|
||||
splashTimer = splashTimer - deltaTime
|
||||
end
|
||||
|
||||
local function splash1(deltaTime)
|
||||
local splash1LogoXOffset = (Dim.design.width - splash1LogoWidth) / 2
|
||||
local splash1LogoYOffset = (Dim.design.height - splash1LogoHeight) / 2
|
||||
|
||||
calcFade(splash1Duration)
|
||||
|
||||
gfx.BeginPath()
|
||||
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
|
||||
gfx.FillColor(splash1BgColor[1], splash1BgColor[2], splash1BgColor[3], fadeAlpha)
|
||||
gfx.Fill()
|
||||
|
||||
gfx.BeginPath()
|
||||
gfx.ImageRect(splash1LogoXOffset, splash1LogoYOffset, splash1LogoWidth, splash1LogoHeight, splash1Logo, fadeAlpha / 255, 0)
|
||||
|
||||
if (splashTimer < 0) then
|
||||
splashState = "splash2"
|
||||
splash1SfxPlayed = false
|
||||
splashTimer = 0
|
||||
return
|
||||
end
|
||||
|
||||
if splashTimer == 0 then
|
||||
splashTimer = splash1Duration
|
||||
end
|
||||
|
||||
if not splash1SfxPlayed then
|
||||
game.PlaySample("titlescreen/splash/splash1.wav")
|
||||
splash1SfxPlayed = true
|
||||
end
|
||||
|
||||
splashTimer = splashTimer - deltaTime
|
||||
end
|
||||
|
||||
local function splash2(deltaTime)
|
||||
local splash2LogoXOffset = (Dim.design.width - splash2LogoWidth) / 2
|
||||
local splash2LogoYOffset = (Dim.design.height - splash2LogoHeight) / 2
|
||||
|
||||
calcFade(splash2Duration)
|
||||
|
||||
gfx.BeginPath()
|
||||
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
|
||||
gfx.FillColor(splash2BgColor[1], splash2BgColor[2], splash2BgColor[3], fadeAlpha)
|
||||
gfx.Fill()
|
||||
|
||||
gfx.BeginPath()
|
||||
gfx.ImageRect(splash2LogoXOffset, splash2LogoYOffset, splash2LogoWidth, splash2LogoHeight, splash2Logo, fadeAlpha / 255, 0)
|
||||
|
||||
if (splashTimer < 0) then
|
||||
splashState = "done"
|
||||
splashTimer = 0
|
||||
return
|
||||
end
|
||||
|
||||
if splashTimer == 0 then
|
||||
splashTimer = splash2Duration
|
||||
end
|
||||
|
||||
splashTimer = splashTimer - deltaTime
|
||||
end
|
||||
|
||||
function render(deltaTime)
|
||||
Dim.updateResolution()
|
||||
|
||||
BGPattern.render()
|
||||
|
||||
gfx.BeginPath()
|
||||
Dim.transformToDesignSpace()
|
||||
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
|
||||
gfx.FillColor(0, 0, 0)
|
||||
gfx.Fill()
|
||||
|
||||
if splashState == "init" then
|
||||
initSplash(deltaTime)
|
||||
elseif splashState == "splash1" then
|
||||
splash1(deltaTime)
|
||||
elseif splashState == "splash2" then
|
||||
splash2(deltaTime)
|
||||
elseif splashState == "done" then
|
||||
return {
|
||||
eventType = 'switch',
|
||||
toScreen = 'title'
|
||||
eventType = "switch",
|
||||
toScreen = "title"
|
||||
}
|
||||
else
|
||||
game.Log("Splash screen state error, splashState: " .. splashState, game.LOGGER_ERROR)
|
||||
splashState = "done"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 51 KiB |
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Loading…
Reference in New Issue