From 001ae44eece66bff02895c14925ca69ae12b0517 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 2 Apr 2021 22:46:37 +0200 Subject: [PATCH] feat(overworld): add transition to the cbs --- .../datas/gamedata/maps/sti/plain/test2.lua | 43 ++++++++++++++++++- .../datas/gamedata/maps/sti/plain/test2.tmx | 6 ++- .../scenes/overworld/actors/encounter.lua | 36 ++++++++++++++++ .../scenes/overworld/actors/init.lua | 2 + .../scenes/overworld/assets.lua | 1 + sonic-radiance.love/scenes/overworld/init.lua | 11 ++++- .../scenes/overworld/world.lua | 8 ++++ 7 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 sonic-radiance.love/scenes/overworld/actors/encounter.lua diff --git a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.lua b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.lua index d17ee5b..9c649f4 100644 --- a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.lua +++ b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.lua @@ -8,8 +8,8 @@ return { height = 40, tilewidth = 16, tileheight = 16, - nextlayerid = 6, - nextobjectid = 17, + nextlayerid = 7, + nextobjectid = 19, properties = {}, tilesets = { { @@ -442,6 +442,45 @@ return { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { + type = "objectgroup", + draworder = "topdown", + id = 6, + name = "encounter", + visible = true, + opacity = 1, + offsetx = 0, + offsety = 0, + properties = {}, + objects = { + { + id = 17, + name = "", + type = "", + shape = "rectangle", + x = 192, + y = 240, + width = 16, + height = 16, + rotation = 0, + visible = true, + properties = {} + }, + { + id = 18, + name = "", + type = "", + shape = "rectangle", + x = 336, + y = 240, + width = 16, + height = 16, + rotation = 0, + visible = true, + properties = {} + } + } + }, { type = "objectgroup", draworder = "topdown", diff --git a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.tmx b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.tmx index 89f4c0a..0f95342 100644 --- a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.tmx +++ b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.tmx @@ -1,5 +1,5 @@ - + @@ -92,6 +92,10 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + diff --git a/sonic-radiance.love/scenes/overworld/actors/encounter.lua b/sonic-radiance.love/scenes/overworld/actors/encounter.lua new file mode 100644 index 0000000..7ba8d29 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/actors/encounter.lua @@ -0,0 +1,36 @@ +local cwd = (...):gsub('%.encounter$', '') .. "." +local Gizmo = require(cwd .. "gizmo") +local Encounter = Gizmo:extend() + +local overrides = { + ["isSolid"] = false, + ["charset"] = "item1", + ["charId"] = 2, + ["destroy"] = "none", + ["needButton"] = false, + ["isTurning"] = true, +} + +function Encounter:new(world, x, y) + Encounter.super.new(self, world, x, y, 16, 16, overrides) +end + +function Encounter:action() + core.scenemanager:storeCurrentScene("afterBattle") + local ox, oy = self.world.cameras:getViewCoordinate(1) + game.cbs:startBattle("test", "testBattle", self.x - ox, self.y - oy) + self.world.encounter = self +end + +function Encounter:drawCharset(charset, charId) + local x, y = utils.math.floorCoord(self.x, self.y) + y = y - 2 + + love.graphics.setColor(1,1,1,0.5) + self.assets.images["shadow"]:draw(x, y + 11) + utils.graphics.resetColor() + + self.assets.sprites["encounter"]:drawAnimation(x - 1, y + 10) + end + +return Encounter \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/actors/init.lua b/sonic-radiance.love/scenes/overworld/actors/init.lua index 3ffe511..723206d 100644 --- a/sonic-radiance.love/scenes/overworld/actors/init.lua +++ b/sonic-radiance.love/scenes/overworld/actors/init.lua @@ -7,6 +7,7 @@ Obj.Gizmo = require(cwd .. "gizmo") Obj.Ring = require(cwd .. "ring") Obj.ItemBox = require(cwd .. "itembox") Obj.RingBox = require(cwd .. "ringbox") +Obj.Encounter = require(cwd .. "encounter") Obj.index = {} Obj.index["player"] = Obj.Player @@ -14,6 +15,7 @@ Obj.index["gizmo"] = Obj.Gizmo Obj.index["ring"] = Obj.Ring Obj.index["itembox"] = Obj.ItemBox Obj.index["ringbox"] = Obj.RingBox +Obj.index["encounter"] = Obj.Encounter Obj.collisions = {} Obj.collisions["wall"] = require(cwd .. "wall") diff --git a/sonic-radiance.love/scenes/overworld/assets.lua b/sonic-radiance.love/scenes/overworld/assets.lua index ad5a54c..0b1c176 100644 --- a/sonic-radiance.love/scenes/overworld/assets.lua +++ b/sonic-radiance.love/scenes/overworld/assets.lua @@ -8,6 +8,7 @@ return { ["sprites"] = { {"cursorground", "assets/gui/cursor/ground"}, {"hitGFX", "assets/sprites/gfx/hit"}, + {"encounter", "assets/sprites/encounter"}, }, ["textures"] = { {"menucursor", "assets/gui/cursor-menulist.png"}, diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index 7d4fee1..cf57e0a 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -67,11 +67,14 @@ function OverWorld:new() end function OverWorld:updateCurrentMap(map) - self.assets:setMusic("assets/music/" .. map.music .. ".mp3") - self.assets:playMusic() + self:playMapMusic(map) self:showMessage(map.name) +end +function OverWorld:playMapMusic(map) + self.assets:setMusic("assets/music/" .. map.music .. ".mp3") + self.assets:playMusic() end function OverWorld:startEvent() @@ -131,6 +134,10 @@ function OverWorld:pause() screens.mainmenu.pause(self) end +function OverWorld:restored() + self.world:restoreActions() +end + function OverWorld:timerResponse(timer) if (timer == "unPause") then self.isPaused = false diff --git a/sonic-radiance.love/scenes/overworld/world.lua b/sonic-radiance.love/scenes/overworld/world.lua index 8e4f4c1..2dff5b8 100644 --- a/sonic-radiance.love/scenes/overworld/world.lua +++ b/sonic-radiance.love/scenes/overworld/world.lua @@ -16,4 +16,12 @@ function RPGWorld:createMapController() RPGMap(self, self.folder, self.area) end +function RPGWorld:restoreActions() + self.encounter:destroy() + local currentMap = self.map:getMapAtPoint(self.players[1].actor.x, self.players[1].actor.y) + self.players[1].actor.xsp = 0 + self.players[1].actor.ysp = 0 + self.scene:playMapMusic(currentMap) +end + return RPGWorld