sonic-radiance/sonic-radiance.love/scenes/overworld/init.lua

224 lines
6.3 KiB
Lua

-- scenes/moveplayer :: a basic player movement example
--[[
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.
]]
local Scene = require "birb.modules.scenes"
local OverWorld = Scene:extend()
local World = require "scenes.overworld.world"
local CharsetManager = require "scenes.overworld.charsetmanager"
local screens = require "scenes.overworld.screens"
local gui = require "game.modules.gui"
local TweenManager = require "birb.classes.time"
local EventManager = require "game.events"
local MessageQueue = require "game.modules.messagequeue"
function OverWorld:new(area, playerx, playery)
OverWorld.super.new(self)
self.charsetManager = CharsetManager(self)
self.assets:batchImport("assets.commons")
self.assets:batchImport("assets.overworld")
self.assets.fonts["small"]:setLineHeight(16/18)
self.assets.fonts["small"]:setFilter("shadow")
self.tweens = TweenManager(self)
self.screens = screens
World(self, area, playerx, playery)
self.world:setPlayerNumber(1)
self.world:loadMap()
self.currentScreen = nil
self.backGroundOpacity = 0
self.borderPosition = 0
self.isPaused = false
self.canPause = true
self.borders = gui.newBorder(424, 30, 8)
self.emblemPosition = 368
self.ringBorder = -16
self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad")
self.timeBorder = -10
self.messages = MessageQueue(self)
self.isPlaying = ""
self.events = EventManager(self)
end
function OverWorld:updateCurrentMap(map)
self:playMapMusic(map)
self:showMessage(map.name)
game.mapName = map.name
end
function OverWorld:playMapMusic(map)
local newMusic = map.music
if (newMusic ~= self.isPlaying) then
self.assets:setMusic("assets/music/" .. newMusic .. ".mp3")
self.assets:playMusic()
self.isPlaying = newMusic
end
end
function OverWorld:startEvent()
self.world.isActive = false
self.canPause = false
end
function OverWorld:endEvent()
self.world.isActive = true
self.canPause = true
end
function OverWorld:showMessage(message)
self.messages:addMessage(message)
end
function OverWorld:registerScreen(screen)
if (self.currentScreen ~= nil) then
self.currentScreen:quit()
end
self.currentScreen = screen
end
function OverWorld:update(dt)
local keys = self:getKeys(1)
self.tweens:update(dt)
self.events:update(dt)
self.messages:update(dt)
if (self.world.isActive) then
self.charsetManager:update(dt)
end
if (self.currentScreen ~= nil) then
self.currentScreen:update(dt)
end
if (keys["start"].isPressed and self.canPause) then
if (not self.isPaused) then
self.assets.sfx["mSelect"]:play()
self:pause()
else
self.assets.sfx["mBack"]:play()
self:unpause()
end
end
end
function OverWorld:pause()
self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad")
self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad")
self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad")
self.tweens:newTween(0, 0.3, {ringBorder=8}, "inOutQuad")
self.tweens:newTween(0, 0.3, {timeBorder=19}, "inOutQuad")
self.isPaused = true
self.world.isActive = false
screens.mainmenu.pause(self)
end
function OverWorld:gameover()
self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad")
self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad")
self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad")
self.tweens:newTween(0, 0.3, {ringBorder=-16}, "inOutQuad")
self.world.isActive = false
screens.gameover(self)
end
function OverWorld:restored()
self.world:restoreActions()
end
function OverWorld:timerResponse(timer)
if (timer == "unPause") then
self.isPaused = false
self.world.isActive = true
end
end
function OverWorld:unpause()
self.tweens:newTween(0.1, 0.2, {backGroundOpacity=0}, "inQuad")
self.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad")
self.tweens:newTween(0, 0.3, {emblemPosition=368}, "inOutQuad")
self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad")
self.tweens:newTween(0, 0.3, {timeBorder=-20}, "inOutQuad")
self.tweens:newTimer(0.2, "unPause")
if (self.currentScreen ~= nil) then
self.currentScreen:quit()
end
end
function OverWorld:quitScreen()
self.currentScreen = nil
end
function OverWorld:getEmblemsPosition()
return self.emblemPosition
end
function OverWorld:draw()
self.events:draw()
self.messages:draw()
self:drawScreenBottomLayer()
end
function OverWorld:drawOverTransition()
self:drawScreenTopLayer()
end
function OverWorld:drawScreenBottomLayer()
love.graphics.setColor(0, 0, 0, self.backGroundOpacity)
love.graphics.rectangle("fill", 0, 0, 424, 240)
utils.graphics.resetColor()
if (self.currentScreen ~= nil) then
self.currentScreen:drawBackground()
self.currentScreen:drawForeground()
end
end
function OverWorld:drawScreenTopLayer()
love.graphics.draw(self.borders, 0, self.borderPosition, 0, 1, -1)
love.graphics.draw(self.borders, 424, 240 - self.borderPosition, 0, -1, 1)
self.assets.images["guiRing"]:draw(self.ringBorder, self.ringBorder)
local ringString = utils.math.numberToString(game.loot.rings, 3)
self.assets.fonts["hudnbrs"]:print(ringString, self.ringBorder + 14, self.ringBorder + 1)
self.assets.fonts["hudnbrs"]:print(game:getTimeString(), 424 - 16, 240 - self.timeBorder, "right")
if (self.currentScreen ~= nil) then
self.currentScreen:drawOverEverything()
end
end
return OverWorld