From aa28f584e179e6a1d0125ecffb796d2cf90bd565 Mon Sep 17 00:00:00 2001 From: Lily-129 <68935009+Lily-129@users.noreply.github.com> Date: Fri, 28 Jan 2022 10:06:46 -0500 Subject: [PATCH] portal self-exclusion and more outOfBounds checks --- mods/portal.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/mods/portal.js b/mods/portal.js index 3c03dd1d..b4799186 100644 --- a/mods/portal.js +++ b/mods/portal.js @@ -31,17 +31,25 @@ elements.portal_in = { } if(pixel.portalArray.length > 0) { randomDestination = pixel.portalArray[Math.floor((Math.random() * pixel.portalArray.length))] - if(!isEmpty(pixel.x-1,pixel.y)) { - tryMove(pixelMap[pixel.x-1][pixel.y],(randomDestination[0] - 1),(randomDestination[1])) + if(!isEmpty(pixel.x-1,pixel.y) && !outOfBounds(pixel.x-1,pixel.y)) { + if(pixelMap[pixel.x-1][pixel.y].element != pixel.element) { + tryMove(pixelMap[pixel.x-1][pixel.y],(randomDestination[0] - 1),(randomDestination[1])) + } } - if(!isEmpty(pixel.x+1,pixel.y)) { - tryMove(pixelMap[pixel.x+1][pixel.y],(randomDestination[0] + 1),(randomDestination[1])) + if(!isEmpty(pixel.x+1,pixel.y) && !outOfBounds(pixel.x+1,pixel.y)) { + if(pixelMap[pixel.x+1][pixel.y].element != pixel.element) { + tryMove(pixelMap[pixel.x+1][pixel.y],(randomDestination[0] + 1),(randomDestination[1])) + } } - if(!isEmpty(pixel.x,pixel.y-1)) { - tryMove(pixelMap[pixel.x][pixel.y-1],(randomDestination[0]),(randomDestination[1] - 1)) + if(!isEmpty(pixel.x,pixel.y-1) && !outOfBounds(pixel.x,pixel.y-1)) { + if(pixelMap[pixel.x][pixel.y-1].element != pixel.element) { + tryMove(pixelMap[pixel.x][pixel.y-1],(randomDestination[0]),(randomDestination[1] - 1)) + } } - if(!isEmpty(pixel.x,pixel.y+1)) { - tryMove(pixelMap[pixel.x][pixel.y+1],(randomDestination[0]),(randomDestination[1] + 1)) + if(!isEmpty(pixel.x,pixel.y+1) && !outOfBounds(pixel.x,pixel.y+1)) { + if(pixelMap[pixel.x][pixel.y+1].element != pixel.element) { + tryMove(pixelMap[pixel.x][pixel.y+1],(randomDestination[0]),(randomDestination[1] + 1)) + } } } },