feat: add teleportation between maps

This commit is contained in:
Kazhnuz 2021-04-03 00:04:22 +02:00
parent fbbe20e225
commit 63922790e0
12 changed files with 314 additions and 11 deletions

View file

@ -0,0 +1,15 @@
return {
areaName = "testmap2",
canSave = true,
color = {0.3, 0.3, 0.3},
maps = {
{
name = "Not Hidden Grotto",
music = "testmap",
folder = "test",
map = "map",
x = 0,
y = 0,
}
}
}

View file

@ -302,6 +302,98 @@ return {
{
id = 102,
type = "solid"
},
{
id = 108,
type = "solid"
},
{
id = 109,
type = "solid"
},
{
id = 110,
type = "solid"
},
{
id = 116,
type = "solid"
},
{
id = 117,
type = "solid"
},
{
id = 118,
type = "solid"
},
{
id = 124,
type = "solid"
},
{
id = 125,
type = "solid"
},
{
id = 126,
type = "solid"
},
{
id = 129,
type = "solid"
},
{
id = 130,
type = "solid"
},
{
id = 132,
type = "solid"
},
{
id = 133,
type = "solid"
},
{
id = 134,
type = "solid"
},
{
id = 140,
type = "solid"
},
{
id = 141,
type = "solid"
},
{
id = 142,
type = "solid"
},
{
id = 148,
type = "solid"
},
{
id = 149,
type = "solid"
},
{
id = 150,
type = "solid"
},
{
id = 156,
type = "solid"
},
{
id = 157,
type = "solid"
},
{
id = 158,
type = "solid"
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View file

@ -71,6 +71,27 @@
<tile id="98" type="solid"/>
<tile id="101" type="solid"/>
<tile id="102" type="solid"/>
<tile id="108" type="solid"/>
<tile id="109" type="solid"/>
<tile id="110" type="solid"/>
<tile id="116" type="solid"/>
<tile id="117" type="solid"/>
<tile id="118" type="solid"/>
<tile id="124" type="solid"/>
<tile id="125" type="solid"/>
<tile id="126" type="solid"/>
<tile id="129" type="solid"/>
<tile id="130" type="solid"/>
<tile id="132" type="solid"/>
<tile id="133" type="solid"/>
<tile id="134" type="solid"/>
<tile id="140" type="solid"/>
<tile id="141" type="solid"/>
<tile id="142" type="solid"/>
<tile id="148" type="solid"/>
<tile id="149" type="solid"/>
<tile id="150" type="solid"/>
<tile id="156" type="solid"/>
<tile id="157" type="solid"/>
<tile id="158" type="solid"/>
</tileset>

View file

@ -8,8 +8,8 @@ return {
height = 40,
tilewidth = 16,
tileheight = 16,
nextlayerid = 10,
nextobjectid = 25,
nextlayerid = 11,
nextobjectid = 26,
properties = {},
tilesets = {
{
@ -316,6 +316,42 @@ return {
id = 102,
type = "solid"
},
{
id = 108,
type = "solid"
},
{
id = 109,
type = "solid"
},
{
id = 110,
type = "solid"
},
{
id = 116,
type = "solid"
},
{
id = 117,
type = "solid"
},
{
id = 118,
type = "solid"
},
{
id = 124,
type = "solid"
},
{
id = 125,
type = "solid"
},
{
id = 126,
type = "solid"
},
{
id = 129,
type = "solid"
@ -323,6 +359,54 @@ return {
{
id = 130,
type = "solid"
},
{
id = 132,
type = "solid"
},
{
id = 133,
type = "solid"
},
{
id = 134,
type = "solid"
},
{
id = 140,
type = "solid"
},
{
id = 141,
type = "solid"
},
{
id = 142,
type = "solid"
},
{
id = 148,
type = "solid"
},
{
id = 149,
type = "solid"
},
{
id = 150,
type = "solid"
},
{
id = 156,
type = "solid"
},
{
id = 157,
type = "solid"
},
{
id = 158,
type = "solid"
}
}
}
@ -404,9 +488,9 @@ 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,
58, 58, 58, 58, 58, 58, 58, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
66, 66, 66, 66, 66, 66, 66, 63, 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, 49, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
0, 0, 0, 0, 0, 0, 0, 57, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
0, 0, 0, 0, 0, 0, 0, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
0, 0, 0, 0, 0, 0, 0, 49, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 109, 110, 111, 50, 50, 50, 50, 50, 50, 50,
0, 0, 0, 0, 0, 0, 0, 57, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 117, 118, 119, 58, 58, 58, 58, 58, 58, 58,
0, 0, 0, 0, 0, 0, 0, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 125, 126, 127, 66, 66, 66, 66, 66, 66, 66,
39, 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, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 129, 130, 131, 132,
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,
@ -442,6 +526,38 @@ return {
39, 0, 0, 0, 0, 39, 0, 0, 0, 0, 23, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39
}
},
{
type = "objectgroup",
draworder = "topdown",
id = 10,
name = "teleporter",
visible = true,
opacity = 1,
offsetx = 0,
offsety = 0,
properties = {},
objects = {
{
id = 25,
name = "",
type = "",
shape = "rectangle",
x = 336,
y = 96,
width = 16,
height = 16,
rotation = 0,
visible = true,
properties = {
["area"] = "test.grotto",
["isSolid"] = true,
["needButton"] = true,
["x"] = 12,
["y"] = 12
}
}
}
},
{
type = "objectgroup",
draworder = "topdown",

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="30" height="40" tilewidth="16" tileheight="16" infinite="0" nextlayerid="10" nextobjectid="25">
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="30" height="40" tilewidth="16" tileheight="16" infinite="0" nextlayerid="11" nextobjectid="26">
<editorsettings>
<export target="test.lua" format="lua"/>
</editorsettings>
@ -54,9 +54,9 @@
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,
58,58,58,58,58,58,58,55,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
66,66,66,66,66,66,66,63,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,49,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,
0,0,0,0,0,0,0,57,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,
0,0,0,0,0,0,0,65,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
0,0,0,0,0,0,0,49,50,50,50,50,50,50,50,50,50,50,50,50,109,110,111,50,50,50,50,50,50,50,
0,0,0,0,0,0,0,57,58,58,58,58,58,58,58,58,58,58,58,58,117,118,119,58,58,58,58,58,58,58,
0,0,0,0,0,0,0,65,66,66,66,66,66,66,66,66,66,66,66,66,125,126,127,66,66,66,66,66,66,66,
39,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,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,129,130,131,132,
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,
@ -92,6 +92,17 @@
39,0,0,0,0,39,0,0,0,0,23,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39
</data>
</layer>
<objectgroup id="10" name="teleporter">
<object id="25" x="336" y="96" width="16" height="16">
<properties>
<property name="area" value="test.grotto"/>
<property name="isSolid" type="bool" value="true"/>
<property name="needButton" type="bool" value="true"/>
<property name="x" type="int" value="12"/>
<property name="y" type="int" value="12"/>
</properties>
</object>
</objectgroup>
<objectgroup id="7" name="ring">
<object id="13" x="112" y="144" width="16" height="16"/>
<object id="14" x="112" y="176" width="16" height="16"/>

View file

@ -5,7 +5,8 @@ return {
["optionBox"] = {"message", "title", "avatar", "option1", "option2", "option3", "flag"},
["playSFX"] = {"sfx"},
["getRings"] = {"number"},
["getItems"] = {"type", "item", "number"}
["getItems"] = {"type", "item", "number"},
["teleport"] = {"area", "x", "y"}
--[name] = {args...},
}

View file

@ -5,5 +5,6 @@ return {
["optionBox"] = require("game.events.event.dialogbox"),
["playSFX"] = require("game.events.event.playSFX"),
["getRings"] = require("game.events.event.getRings"),
["getItems"] = require("game.events.event.getItems")
["getItems"] = require("game.events.event.getItems"),
["teleport"] = require("game.events.event.teleport")
}

View file

@ -0,0 +1,19 @@
local StepParent = require "game.events.event.parent"
local SimpleMessageStep = StepParent:extend()
local defTransitions = require "core.modules.transitions"
function SimpleMessageStep:new(controller, args)
SimpleMessageStep.super.new(self, controller, args)
end
function SimpleMessageStep:start()
core.screen:startTransition(defTransitions.default, defTransitions.default,
function() self.events.scene.world:teleport(self.arguments.area, self.arguments.x, self.arguments.y) end,
0, 0)
end
function SimpleMessageStep:update(dt)
self:finish()
end
return SimpleMessageStep;

View file

@ -8,6 +8,7 @@ Obj.Ring = require(cwd .. "ring")
Obj.ItemBox = require(cwd .. "itembox")
Obj.RingBox = require(cwd .. "ringbox")
Obj.Encounter = require(cwd .. "encounter")
Obj.Teleporter = require(cwd .. "teleport")
Obj.index = {}
Obj.index["player"] = Obj.Player
@ -16,6 +17,7 @@ Obj.index["ring"] = Obj.Ring
Obj.index["itembox"] = Obj.ItemBox
Obj.index["ringbox"] = Obj.RingBox
Obj.index["encounter"] = Obj.Encounter
Obj.index["teleporter"] = Obj.Teleporter
Obj.collisions = {}
Obj.collisions["wall"] = require(cwd .. "wall")

View file

@ -0,0 +1,16 @@
local cwd = (...):gsub('%.teleport$', '') .. "."
local Gizmo = require(cwd .. "gizmo")
local Teleporter = Gizmo:extend()
function Teleporter:new(world, x, y, w, h)
Teleporter.super.new(self, world, x, y, w, h, nil)
end
function Teleporter:applyProperties()
Teleporter.super.applyProperties(self)
self.event = {
{"teleport", "", self.properties.area, self.properties.x, self.properties.y},
}
end
return Teleporter

View file

@ -21,6 +21,15 @@ function RPGWorld:savePosition()
game.position.area = self.area
end
function RPGWorld:teleport(area, x, y)
if (area == self.area) then
self.players[1].actor.x = x * 16
self.players[1].actor.y = y * 16
else
scenes.overworld(area, x, y)
end
end
function RPGWorld:restoreActions()
self.encounter:destroy()
local currentMap = self.map:getMapAtPoint(self.players[1].actor.x, self.players[1].actor.y)