sonic-radiance/sonic-radiance.love/scenes/menus/titlescreen/init.lua

123 lines
4.2 KiB
Lua
Raw Normal View History

-- scenes/test :: a basic test scene
--[[
Copyright © 2019 Kazhnuz
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
2021-05-05 08:30:32 +02:00
local Scene = require "birb.modules.scenes"
local TitleScreen = Scene:extend()
local gui = require "game.modules.gui"
local TweenManager = require "birb.classes.time"
2021-04-05 12:06:02 +02:00
local Menu = require "scenes.menus.titlescreen.menu"
function TitleScreen:new(fromMenu)
TitleScreen.super.new(self)
local fromMenu = (fromMenu == true)
self.borders = gui.newBorder(424, 30, 8)
self.assets:batchImport("assets.commons")
self.assets:addImage("logo", "assets/artworks/logo.png")
2021-04-05 12:06:02 +02:00
self.assets:addTileset("charicons", "assets/sprites/characters/charicons")
self.assets.fonts["small"]:setLineHeight(16/18)
self.assets.fonts["small"]:setFilter("shadow")
self.tweens = TweenManager(self)
self:initBackground()
self.haveMenu = false
self.flashOpacity = 0
self.showPressStart = true
self.showPressStartTimer = 0.5
if (fromMenu) then
self.darkenOpacity = 0
self.canShowPressStart = true
self.borderY = 30
self.logoX = 0
else
self.darkenOpacity = 1
self.canShowPressStart = false
self.borderY = 0
self.logoX = 270
self.tweens:newTween(0.2, 0.5, {borderY = 30}, "inOutQuart")
self.tweens:newTween(0.5, 0.4, {darkenOpacity = 0}, "outExpo")
self.tweens:newTween(0.7, 0.6, {logoX = 0}, "inOutQuart")
self.tweens:newTween(1.3, 0.03, {flashOpacity = 1}, "inQuart")
self.tweens:newTween(1.45, 0.2, {flashOpacity = 0}, "outExpo")
self.tweens:newSwitch(1.4, { "canShowPressStart" })
end
end
function TitleScreen:initBackground()
2021-04-05 12:06:02 +02:00
self.background = love.graphics.newImage("datas/gamedata/maps/sti/stuff/tilescreen.png")
end
function TitleScreen:update(dt)
self.tweens:update(dt)
if (self.canShowPressStart) then
self.showPressStartTimer = self.showPressStartTimer - dt
if self.showPressStartTimer < 0 then
self.showPressStart = (self.showPressStart == false)
self.showPressStartTimer = 0.5
end
local keys = self:getKeys(1)
if (keys["start"].isPressed and (self.haveMenu == false)) then
self.assets:playSFX("mSelect")
2021-04-05 12:06:02 +02:00
Menu(self)
self.haveMenu = true
self.menusystem:setSoundFromSceneAssets("mBeep")
end
end
end
function TitleScreen:draw()
utils.graphics.resetColor()
2021-04-05 12:06:02 +02:00
local w, h = self.background:getDimensions()
love.graphics.draw(self.background,424/2,240/2,0,1,1,w/2,h/2)
love.graphics.setColor(0, 0, 0, self.darkenOpacity)
love.graphics.rectangle("fill", 0, 0, 424, 240)
utils.graphics.resetColor( )
2021-04-05 12:06:02 +02:00
local w, h = self.assets.images["logo"]:getDimensions()
self.assets:drawImage("logo", 240 - 32, 80 - self.logoX, 0, 1, 1, w/2, h/2)
if (self.canShowPressStart) and (self.showPressStart) then
2021-08-15 20:45:15 +02:00
self.assets.fonts["SA2font"]:print("PRESS START", 424/2, 240/1.33, "center", 0, 1, 1)
end
love.graphics.setColor(1, 1, 1, self.flashOpacity)
love.graphics.rectangle("fill", 0, 0, 424, 240)
utils.graphics.resetColor( )
end
2021-04-05 12:06:02 +02:00
function TitleScreen:drawOverTransition()
2021-04-05 12:06:02 +02:00
love.graphics.draw(self.borders, 0, self.borderY, 0, 1, -1)
love.graphics.draw(self.borders, 424, 240 - self.borderY, 0, -1, 1)
self.assets.fonts["small"]:draw("v" .. game.version, 424 - 44, 240 + 10 - self.borderY)
end
return TitleScreen