From 3b28c5b776ba01baf7bd39065625190ec879afeb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 21 Apr 2021 19:06:38 +0200 Subject: [PATCH] feat: add teleportation from leaving the map --- .../datas/gamedata/maps/area/test/grotto.lua | 6 ++++++ .../datas/gamedata/maps/sti/plain/test.lua | 4 ++-- .../datas/gamedata/maps/sti/plain/test.tmx | 4 ++-- .../scenes/overworld/actors/player/init.lua | 1 + .../scenes/overworld/actors/player/map.lua | 11 +++++++++++ sonic-radiance.love/scenes/overworld/map.lua | 11 +++++++++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/sonic-radiance.love/datas/gamedata/maps/area/test/grotto.lua b/sonic-radiance.love/datas/gamedata/maps/area/test/grotto.lua index f2f8b6d..8960a84 100644 --- a/sonic-radiance.love/datas/gamedata/maps/area/test/grotto.lua +++ b/sonic-radiance.love/datas/gamedata/maps/area/test/grotto.lua @@ -11,5 +11,11 @@ return { x = 0, y = 0, } + }, + exitTo = { + area = "test.plain", + x = 21, + y = 7, + charDir = "down" } } \ No newline at end of file diff --git a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test.lua b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test.lua index 4225f40..40fb1b3 100644 --- a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test.lua +++ b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test.lua @@ -552,8 +552,8 @@ return { ["area"] = "test.grotto", ["isSolid"] = true, ["needButton"] = true, - ["x"] = 12, - ["y"] = 12 + ["x"] = 13.5, + ["y"] = 29 } } } diff --git a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test.tmx b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test.tmx index c9a5ef6..3f78ec4 100644 --- a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test.tmx +++ b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test.tmx @@ -98,8 +98,8 @@ - - + + diff --git a/sonic-radiance.love/scenes/overworld/actors/player/init.lua b/sonic-radiance.love/scenes/overworld/actors/player/init.lua index 7a702ce..485fada 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/init.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/init.lua @@ -54,6 +54,7 @@ function Player:updateStart(dt) self:updateInteraction() self:updateCurrentCharset() self:updateCurrentMap() + self:updateOutsideMap() end -- PHYSICS FUNCTIONS diff --git a/sonic-radiance.love/scenes/overworld/actors/player/map.lua b/sonic-radiance.love/scenes/overworld/actors/player/map.lua index a32ab47..aaac6e7 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/map.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/map.lua @@ -1,4 +1,5 @@ local PlayerMap = Object:extend() +local defTransitions = require "core.modules.transitions" function PlayerMap:initMap() self.previousMap = 0 @@ -14,4 +15,14 @@ function PlayerMap:updateCurrentMap() end end +function PlayerMap:updateOutsideMap() + if ((self.x > self.world.map.w + 8) or (self.x < -8) or (self.y > self.world.map.h + 16) or (self.y < -8)) + and (self.world.map.data.exitTo ~= nil) then + local arguments = self.world.map.data.exitTo + core.screen:startTransition(defTransitions.default, defTransitions.default, + function() self.world:teleport(arguments.area, arguments.x, arguments.y, arguments.charDir) end, + 0, 0) + end +end + return PlayerMap \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/map.lua b/sonic-radiance.love/scenes/overworld/map.lua index 6567707..d48e638 100644 --- a/sonic-radiance.love/scenes/overworld/map.lua +++ b/sonic-radiance.love/scenes/overworld/map.lua @@ -33,9 +33,20 @@ function TiledMultiMap:loadObjects() for i, wrapper in ipairs(self.wrappers) do wrapper:loadObjects() end + self:loadWalls() self:loadPlayer() end +function TiledMultiMap:loadWalls() + if (self.data.exitTo == nil) then + self.world.obj.collisions["wall"](self.world, -16, -16, self.w, 16) + self.world.obj.collisions["wall"](self.world, -16, -16, 16, self.h) + self.world.obj.collisions["wall"](self.world, self.w, -16, 16, self.h) + self.world.obj.collisions["wall"](self.world, -16, self.h, self.w, 16) + end + +end + function TiledMultiMap:loadPlayer() self.world:addPlayer(self.playerx, self.playery, 0, 1) end