From 8b427225208dc1d87e213721d051cfd2f298e632 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Dec 2019 21:51:41 +0100 Subject: [PATCH] feat: add a playstyle base scene --- .../game/modules/playstyle/assets.lua | 16 +++++ .../game/modules/playstyle/init.lua | 57 ++++++++++++++++ .../game/modules/playstyle/pause.lua | 67 +++++++++++++++++++ .../scenes/test_scene/assets.lua | 14 +--- .../scenes/test_scene/init.lua | 16 +++-- 5 files changed, 150 insertions(+), 20 deletions(-) create mode 100644 sonic-bluestreak.love/game/modules/playstyle/assets.lua create mode 100644 sonic-bluestreak.love/game/modules/playstyle/init.lua create mode 100644 sonic-bluestreak.love/game/modules/playstyle/pause.lua diff --git a/sonic-bluestreak.love/game/modules/playstyle/assets.lua b/sonic-bluestreak.love/game/modules/playstyle/assets.lua new file mode 100644 index 0000000..329e8ec --- /dev/null +++ b/sonic-bluestreak.love/game/modules/playstyle/assets.lua @@ -0,0 +1,16 @@ +return { + ["textures"] = { + {"shadow", "assets/sprites/shadow.png"} + }, + ["sprites"] = { + {"ring", "assets/sprites/items/ring"} + }, + ["imagefonts"] = { + {"menu", "assets/gui/fonts/SA2font"} + }, + ["sfx"] = { + {"navigate", "assets/sfx/menu/select.wav"}, + {"confirm", "assets/sfx/menu/validate.wav"}, + {"cancel", "assets/sfx/menu/cancel.wav"}, + } +} diff --git a/sonic-bluestreak.love/game/modules/playstyle/init.lua b/sonic-bluestreak.love/game/modules/playstyle/init.lua new file mode 100644 index 0000000..e699f86 --- /dev/null +++ b/sonic-bluestreak.love/game/modules/playstyle/init.lua @@ -0,0 +1,57 @@ +Scene = require("core.modules.scenes") +local PlayStyle = Scene:extend() + +local PauseMenu = require("game.modules.playstyle.pause") +local TestWorld = require("game.modules.world.parent") + + +function PlayStyle:new(playerNumber, cameraMode) + local playerNumber = playerNumber or 1 + local cameraMode = cameraMode or "split" + + PlayStyle.super.new(self) + self.timer = 0 + self.assets:batchImport("game.modules.playstyle.assets") + + PauseMenu(self) + + self:initWorld() +end + +function PlayStyle:initWorld() + TestWorld(self) +end + +function PlayStyle:update(dt) + PlayStyle.super.update(self, dt) + if self.menusystem.menus["pauseMenu"].isActive == false then + self.timer = self.timer + dt + end + + local keys = self:getKeys(1); + + if keys["start"].isPressed then + if not (self.menusystem.menus["pauseMenu"].isActive) then + self.menusystem.menus["pauseMenu"].isActive = true + self.menusystem.menus["pauseMenu"].isVisible = true + self.menusystem.menus["pauseMenu"]:getFocus() + self.assets.isActive = false + self.world.isActive = false + else + self.menusystem.menus["pauseMenu"].isActive = false + self.menusystem.menus["pauseMenu"].isVisible = false + self.assets.isActive = true + self.world.isActive = true + end + end +end + +function PlayStyle:restartLevel() + +end + +function PlayStyle:exitLevel() + scenes.title() +end + +return PlayStyle diff --git a/sonic-bluestreak.love/game/modules/playstyle/pause.lua b/sonic-bluestreak.love/game/modules/playstyle/pause.lua new file mode 100644 index 0000000..8237414 --- /dev/null +++ b/sonic-bluestreak.love/game/modules/playstyle/pause.lua @@ -0,0 +1,67 @@ +local ListBox = require "core.modules.menusystem.listbox" +local PauseMenu = ListBox:extend() + +local Widget = require "core.modules.menusystem.widgets" + +local ResumeWidget = Widget.Text:extend() +local RestartWidget = Widget.Text:extend() +local ExitWidget = Widget.Text:extend() + +function PauseMenu:new(playstyle) + local height, width, x, y + height = 72 + width = 128 + x = 424/2 - width/2 + y = 240/2 - height/2 + + PauseMenu.super.new(self, playstyle.menusystem, "pauseMenu", x, y, width, height, 3) + self.playstyle = playstyle + + self:setSound(self.playstyle.assets.sfx["navigate"]) + self.isActive = false + self.isVisible = false + + local font = self.playstyle.assets.fonts["menu"] + + ResumeWidget(self, font) + RestartWidget(self, font) + ExitWidget(self, font) +end + +function PauseMenu:draw() + PauseMenu.super.draw(self) +end + +--- MENU WIDGETS + +function ResumeWidget:new(menu, font) + ResumeWidget.super.new(self, menu, font, "resume") +end + +function ResumeWidget:action() + self.menu.isActive = false + self.menu.isVisible = false + self.menu.playstyle.world.isActive = true + self.menu.playstyle.assets.isActive = true + self.menu.playstyle:flushKeys() +end + +function RestartWidget:new(menu, font) + ResumeWidget.super.new(self, menu, font, "restart") +end + +function RestartWidget:action() + self.menu.playstyle:flushKeys() + self.menu.playstyle:restartLevel() +end + +function ExitWidget:new(menu, font) + ExitWidget.super.new(self, menu, font, "exit") +end + +function ExitWidget:action() + self.menu.playstyle:exitLevel() +end + + +return PauseMenu diff --git a/sonic-bluestreak.love/scenes/test_scene/assets.lua b/sonic-bluestreak.love/scenes/test_scene/assets.lua index 712c1c4..9394316 100644 --- a/sonic-bluestreak.love/scenes/test_scene/assets.lua +++ b/sonic-bluestreak.love/scenes/test_scene/assets.lua @@ -1,17 +1,5 @@ return { - ["textures"] = { - {"shadow", "assets/sprites/shadow.png"} - }, ["sprites"] = { - {"sonic", "assets/sprites/characters/sonic"}, - {"ring", "assets/sprites/items/ring"} - }, - ["imagefonts"] = { - --{"medium", "assets/fonts/medium"} - }, - ["sfx"] = { - --{"navigate", "assets/sfx/menu_move.mp3"}, - --{"confirm", "assets/sfx/menu_confirm.mp3"}, - --{"cancel", "assets/sfx/menu_error.mp3"}, + {"sonic", "assets/sprites/characters/sonic"} } } diff --git a/sonic-bluestreak.love/scenes/test_scene/init.lua b/sonic-bluestreak.love/scenes/test_scene/init.lua index 39c08b5..939aa55 100644 --- a/sonic-bluestreak.love/scenes/test_scene/init.lua +++ b/sonic-bluestreak.love/scenes/test_scene/init.lua @@ -21,8 +21,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] -local Scene = require "core.modules.scenes" -local MovePlayer = Scene:extend() +local PlayStyle = require "game.modules.playstyle" +local MovePlayer = PlayStyle:extend() local TestWorld = require "game.modules.world.parent" local ShootWorld = require "game.modules.world.shoot" @@ -32,17 +32,19 @@ function MovePlayer:new(playerNumber, cameraMode) local playerNumber = playerNumber or 1 local cameraMode = cameraMode or "split" - MovePlayer.super.new(self) + MovePlayer.super.new(self, playerNumber, cameraMode) self.assets:batchImport("scenes.test_scene.assets") - ShootWorld(self, "coast") - --BattleWorld(self, "ebeach") - --TestWorld(self) - self.world:setPlayerNumber(playerNumber) self.world.cameras:setMode(cameraMode) self.world:loadMap() end +function MovePlayer:initWorld() + --ShootWorld(self, "coast") + --BattleWorld(self, "ebeach") + TestWorld(self) +end + return MovePlayer