2020-08-01 16:57:12 +02:00
|
|
|
-- 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.
|
|
|
|
]]
|
|
|
|
|
2019-04-01 09:08:53 +02:00
|
|
|
local Scene = require "core.modules.scenes"
|
2021-03-21 16:20:13 +01:00
|
|
|
local OverWorld = Scene:extend()
|
2020-08-01 16:57:12 +02:00
|
|
|
|
|
|
|
local World = require "scenes.overworld.world"
|
2020-08-01 18:54:12 +02:00
|
|
|
local CharsetManager = require "scenes.overworld.charsetmanager"
|
2019-04-01 09:08:53 +02:00
|
|
|
|
2020-08-20 15:39:02 +02:00
|
|
|
local screens = require "scenes.overworld.screens"
|
|
|
|
|
|
|
|
local gui = require "game.modules.gui"
|
|
|
|
local TweenManager = require "game.modules.tweenmanager"
|
|
|
|
|
2021-03-20 21:08:54 +01:00
|
|
|
local EventManager = require "game.events"
|
2021-04-18 17:44:00 +02:00
|
|
|
local MessageQueue = require "game.modules.messagequeue"
|
2021-03-20 21:08:54 +01:00
|
|
|
|
2021-04-02 23:26:22 +02:00
|
|
|
function OverWorld:new(area, playerx, playery)
|
2021-03-21 16:20:13 +01:00
|
|
|
OverWorld.super.new(self)
|
2020-08-01 18:54:12 +02:00
|
|
|
self.charsetManager = CharsetManager(self)
|
2020-08-03 10:28:18 +02:00
|
|
|
self.assets:batchImport("game.modules.gui.assets")
|
2020-08-02 15:56:36 +02:00
|
|
|
self.assets:batchImport("scenes.overworld.assets")
|
2021-04-21 18:36:20 +02:00
|
|
|
self.assets.fonts["small"]:setLineHeight(16/18)
|
|
|
|
self.assets.fonts["small"]:setFilter("shadow")
|
2020-08-01 16:57:12 +02:00
|
|
|
|
2020-08-20 15:39:02 +02:00
|
|
|
self.tweens = TweenManager(self)
|
2020-08-26 18:38:40 +02:00
|
|
|
self.screens = screens
|
2020-08-20 15:39:02 +02:00
|
|
|
|
2021-04-02 23:26:22 +02:00
|
|
|
World(self, area, playerx, playery)
|
2020-08-01 16:57:12 +02:00
|
|
|
self.world:setPlayerNumber(1)
|
|
|
|
self.world:loadMap()
|
2020-08-20 15:39:02 +02:00
|
|
|
|
|
|
|
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
|
2021-04-05 14:20:25 +02:00
|
|
|
self.ringBorder = -16
|
|
|
|
self.tweens:newTween(0, 0.3, {ringBorder=16}, "inOutQuad")
|
2020-08-20 15:39:02 +02:00
|
|
|
self.timeBorder = -10
|
2021-04-18 17:44:00 +02:00
|
|
|
|
|
|
|
self.messages = MessageQueue(self)
|
2021-03-20 21:08:54 +01:00
|
|
|
|
2021-04-03 10:52:00 +02:00
|
|
|
self.isPlaying = ""
|
|
|
|
|
2021-03-20 21:08:54 +01:00
|
|
|
self.events = EventManager(self)
|
2021-03-23 21:59:33 +01:00
|
|
|
end
|
2021-03-22 20:03:26 +01:00
|
|
|
|
2021-03-23 21:59:33 +01:00
|
|
|
function OverWorld:updateCurrentMap(map)
|
2021-04-02 22:46:37 +02:00
|
|
|
self:playMapMusic(map)
|
2021-03-23 21:59:33 +01:00
|
|
|
|
|
|
|
self:showMessage(map.name)
|
2021-04-05 09:33:52 +02:00
|
|
|
game.mapName = map.name
|
2021-04-02 22:46:37 +02:00
|
|
|
end
|
2021-03-23 21:59:33 +01:00
|
|
|
|
2021-04-02 22:46:37 +02:00
|
|
|
function OverWorld:playMapMusic(map)
|
2021-04-03 10:52:00 +02:00
|
|
|
local newMusic = map.music
|
|
|
|
if (newMusic ~= self.isPlaying) then
|
|
|
|
self.assets:setMusic("assets/music/" .. newMusic .. ".mp3")
|
|
|
|
self.assets:playMusic()
|
|
|
|
self.isPlaying = newMusic
|
|
|
|
end
|
2021-03-20 21:08:54 +01:00
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:startEvent()
|
2021-03-20 21:08:54 +01:00
|
|
|
self.world.isActive = false
|
2021-03-22 16:14:07 +01:00
|
|
|
self.canPause = false
|
2021-03-20 21:08:54 +01:00
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:endEvent()
|
2021-03-20 21:08:54 +01:00
|
|
|
self.world.isActive = true
|
2021-03-22 16:14:07 +01:00
|
|
|
self.canPause = true
|
2021-03-20 17:10:09 +01:00
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:showMessage(message)
|
2021-04-18 17:44:00 +02:00
|
|
|
self.messages:addMessage(message)
|
2020-08-20 15:39:02 +02:00
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:registerScreen(screen)
|
2020-08-20 15:39:02 +02:00
|
|
|
if (self.currentScreen ~= nil) then
|
|
|
|
self.currentScreen:quit()
|
|
|
|
end
|
|
|
|
self.currentScreen = screen
|
2019-04-01 09:08:53 +02:00
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:update(dt)
|
2020-08-20 15:39:02 +02:00
|
|
|
local keys = self:getKeys(1)
|
|
|
|
self.tweens:update(dt)
|
2021-03-20 21:08:54 +01:00
|
|
|
self.events:update(dt)
|
2021-04-18 17:44:00 +02:00
|
|
|
self.messages:update(dt)
|
2020-08-20 15:39:02 +02:00
|
|
|
|
|
|
|
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:pause()
|
|
|
|
else
|
|
|
|
self:unpause()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:pause()
|
2020-08-20 15:39:02 +02:00
|
|
|
self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad")
|
|
|
|
self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad")
|
2021-04-18 18:23:52 +02:00
|
|
|
self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad")
|
2020-08-20 15:39:02 +02:00
|
|
|
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
|
|
|
|
|
2021-04-19 18:04:29 +02:00
|
|
|
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
|
|
|
|
|
2021-04-02 22:46:37 +02:00
|
|
|
function OverWorld:restored()
|
|
|
|
self.world:restoreActions()
|
|
|
|
end
|
|
|
|
|
2021-03-22 16:43:34 +01:00
|
|
|
function OverWorld:timerResponse(timer)
|
|
|
|
if (timer == "unPause") then
|
|
|
|
self.isPaused = false
|
|
|
|
self.world.isActive = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:unpause()
|
2020-08-20 15:39:02 +02:00
|
|
|
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")
|
2021-03-22 16:43:34 +01:00
|
|
|
self.tweens:newTimer(0.2, "unPause")
|
2020-08-20 15:39:02 +02:00
|
|
|
|
|
|
|
if (self.currentScreen ~= nil) then
|
|
|
|
self.currentScreen:quit()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:quitScreen()
|
2020-08-20 15:39:02 +02:00
|
|
|
self.currentScreen = nil
|
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:getEmblemsPosition()
|
2020-08-20 15:39:02 +02:00
|
|
|
return self.emblemPosition
|
2019-04-01 09:08:53 +02:00
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
function OverWorld:draw()
|
2021-04-05 14:20:25 +02:00
|
|
|
self.events:draw()
|
|
|
|
|
2021-04-18 17:44:00 +02:00
|
|
|
self.messages:draw()
|
2021-04-05 14:20:25 +02:00
|
|
|
self:drawScreenBottomLayer()
|
|
|
|
end
|
|
|
|
|
|
|
|
function OverWorld:drawOverTransition()
|
|
|
|
self:drawScreenTopLayer()
|
|
|
|
end
|
|
|
|
|
|
|
|
function OverWorld:drawScreenBottomLayer()
|
2020-08-20 15:39:02 +02:00
|
|
|
love.graphics.setColor(0, 0, 0, self.backGroundOpacity)
|
|
|
|
love.graphics.rectangle("fill", 0, 0, 424, 240)
|
|
|
|
utils.graphics.resetColor()
|
|
|
|
|
2020-08-26 18:38:40 +02:00
|
|
|
if (self.currentScreen ~= nil) then
|
|
|
|
self.currentScreen:drawBackground()
|
2021-04-05 14:20:25 +02:00
|
|
|
self.currentScreen:drawForeground()
|
2020-08-26 18:38:40 +02:00
|
|
|
end
|
2021-04-05 14:20:25 +02:00
|
|
|
end
|
2020-08-26 18:38:40 +02:00
|
|
|
|
2021-04-05 14:20:25 +02:00
|
|
|
function OverWorld:drawScreenTopLayer()
|
2020-08-20 15:39:02 +02:00
|
|
|
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")
|
|
|
|
|
2019-04-01 09:08:53 +02:00
|
|
|
end
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
return OverWorld
|