From a3bf3c59272e667ab4dfe0bab63bd5f3dae13d09 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Thu, 7 Jan 2021 14:56:58 -0600 Subject: [PATCH] Add teleport border behavior --- main.lua | 31 +++++++------ maps/menu.lua | 119 ++++++++++++++++++++++++++++---------------------- maps/menu.tmx | 17 +++++--- 3 files changed, 91 insertions(+), 76 deletions(-) diff --git a/main.lua b/main.lua index c881dcb..d971d4e 100644 --- a/main.lua +++ b/main.lua @@ -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 diff --git a/maps/menu.lua b/maps/menu.lua index d017fdb..8773035 100644 --- a/maps/menu.lua +++ b/maps/menu.lua @@ -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 = {} } } diff --git a/maps/menu.tmx b/maps/menu.tmx index 0c0abe1..79c6724 100644 --- a/maps/menu.tmx +++ b/maps/menu.tmx @@ -1,5 +1,5 @@ - + @@ -7,19 +7,22 @@ + + + + + + - + - - + + - - -