Add teleport border behavior

This commit is contained in:
Jaidyn Ann 2021-01-07 14:56:58 -06:00
parent 025acf5978
commit a3bf3c5927
3 changed files with 91 additions and 76 deletions

View File

@ -115,14 +115,6 @@ function mainmenu_update(dt)
elseif (num == 3) then
dirs['up'] = 1
end
-- teleport off-screen monkeys
for i=0,player.last do
local x,y = player.monks[i].body:getPosition()
if (y > 2000) then
player.monks[i].body:setPosition(200,0)
end
end
end
@ -519,7 +511,9 @@ function Map:initialize(filepath)
self.platforms = {}
self.tables = {}
self.objects = {}
self.outOfBounds = "teleport"
self.outOfBounds = "die"
self.spawn = {['x'] = 100, ['y'] = 100}
self.respawn = {['x'] = 100, ['y'] = 100}
local maptable = dofile(filepath)
self.width,self.height = maptable.width,maptable.height
@ -567,14 +561,18 @@ function Map:initialize(filepath)
or object.properties["count"] == nil) then
monkCount = object.properties["count"]
end
monkX,monkY = object.x,object.y
self.spawn['x'],self.spawn['y'] = object.x,object.y
elseif (object.shape == "point" and object.type == "respawn") then
self.respawn['x'],self.respawn['y'] = object.x,object.y
self.outOfBounds = "teleport"
elseif (object.shape == "point" and object.type == "banana") then
self.objects[object.id] = Banana:new(object.x, object.y)
end
end
end
player = Monk:new(monkX, monkY, monkCount)
player = Monk:new(self.spawn['x'], self.spawn['y'], monkCount)
end
@ -582,15 +580,16 @@ function Map:update(dt)
local heightMax = self.height * self.tileHeight + 100
local widthMax = self.width * self.tileWidth + 200
for i=player.current,player.last do
for i=0,player.last do
local x,y = player.monks[i].body:getPosition()
if (math.abs(x) > widthMax or y > heightMax
if ((math.abs(x) > widthMax or y > heightMax)
and self.outOfBounds == "die") then
player:freeze()
elseif (math.abs(x) > widthMax or y > heightMax
player:freeze(i)
elseif ((math.abs(x) > widthMax or y > heightMax)
and self.outOfBounds == "teleport") then
player.monks[i].body:setPosition(200,0)
player.monks[i].body:setPosition(
self.respawn['x'], self.respawn['y'])
end
end
end

View File

@ -9,7 +9,7 @@ return {
tilewidth = 16,
tileheight = 16,
nextlayerid = 4,
nextobjectid = 20,
nextobjectid = 33,
properties = {},
tilesets = {},
layers = {
@ -62,6 +62,63 @@ return {
rotation = 0,
visible = true,
properties = {}
},
{
id = 27,
name = "",
type = "",
shape = "polygon",
x = 800,
y = 530.242,
width = 0,
height = 0,
rotation = 0,
visible = true,
polygon = {
{ x = 0, y = 0 },
{ x = -360.606, y = 269.697 },
{ x = -6.06061, y = 266.667 }
},
properties = {}
},
{
id = 28,
name = "",
type = "",
shape = "rectangle",
x = 46.6665,
y = 791.333,
width = 66.6667,
height = 14.6667,
rotation = 0,
visible = true,
properties = {}
},
{
id = 29,
name = "",
type = "",
shape = "rectangle",
x = 177.333,
y = 790,
width = 105.333,
height = 16,
rotation = 0,
visible = true,
properties = {}
},
{
id = 30,
name = "",
type = "",
shape = "rectangle",
x = 346.667,
y = 788.667,
width = 54.6667,
height = 16,
rotation = 0,
visible = true,
properties = {}
}
}
},
@ -77,12 +134,12 @@ return {
properties = {},
objects = {
{
id = 9,
id = 31,
name = "",
type = "spawn",
shape = "point",
x = 378.031,
y = 420.905,
x = 321.333,
y = 484,
width = 0,
height = 0,
rotation = 0,
@ -92,60 +149,16 @@ return {
}
},
{
id = 16,
id = 32,
name = "",
type = "",
shape = "polygon",
x = 800,
y = 524.242,
type = "respawn",
shape = "point",
x = 330.667,
y = 2.66667,
width = 0,
height = 0,
rotation = 0,
visible = true,
polygon = {
{ x = 0, y = 0 },
{ x = -360.606, y = 269.697 },
{ x = -6.06061, y = 266.667 }
},
properties = {}
},
{
id = 17,
name = "",
type = "",
shape = "rectangle",
x = 46.6667,
y = 785.333,
width = 66.6667,
height = 14.6667,
rotation = 0,
visible = true,
properties = {}
},
{
id = 18,
name = "",
type = "",
shape = "rectangle",
x = 177.333,
y = 784,
width = 105.333,
height = 16,
rotation = 0,
visible = true,
properties = {}
},
{
id = 19,
name = "",
type = "",
shape = "rectangle",
x = 346.667,
y = 782.667,
width = 54.6667,
height = 16,
rotation = 0,
visible = true,
properties = {}
}
}

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="50" height="50" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="20">
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="50" height="50" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="33">
<editorsettings>
<export target="menu.lua" format="lua"/>
</editorsettings>
@ -7,19 +7,22 @@
<object id="2" x="38.932" y="306.814" width="14.6488" height="242.519"/>
<object id="4" x="55.2085" y="537.94" width="524.102" height="11.3935"/>
<object id="6" x="581.752" y="306" width="14.6488" height="242.52"/>
<object id="27" x="800" y="530.242">
<polygon points="0,0 -360.606,269.697 -6.06061,266.667"/>
</object>
<object id="28" x="46.6665" y="791.333" width="66.6667" height="14.6667"/>
<object id="29" x="177.333" y="790" width="105.333" height="16"/>
<object id="30" x="346.667" y="788.667" width="54.6667" height="16"/>
</objectgroup>
<objectgroup id="3" name="Object Layer 2">
<object id="9" type="spawn" x="378.031" y="420.905">
<object id="31" type="spawn" x="321.333" y="484">
<properties>
<property name="count" type="int" value="10"/>
</properties>
<point/>
</object>
<object id="16" x="800" y="524.242">
<polygon points="0,0 -360.606,269.697 -6.06061,266.667"/>
<object id="32" type="respawn" x="330.667" y="2.66667">
<point/>
</object>
<object id="17" x="46.6667" y="785.333" width="66.6667" height="14.6667"/>
<object id="18" x="177.333" y="784" width="105.333" height="16"/>
<object id="19" x="346.667" y="782.667" width="54.6667" height="16"/>
</objectgroup>
</map>