portal self-exclusion and more outOfBounds checks
This commit is contained in:
parent
d6705907fc
commit
aa28f584e1
|
|
@ -31,19 +31,27 @@ elements.portal_in = {
|
||||||
}
|
}
|
||||||
if(pixel.portalArray.length > 0) {
|
if(pixel.portalArray.length > 0) {
|
||||||
randomDestination = pixel.portalArray[Math.floor((Math.random() * pixel.portalArray.length))]
|
randomDestination = pixel.portalArray[Math.floor((Math.random() * pixel.portalArray.length))]
|
||||||
if(!isEmpty(pixel.x-1,pixel.y)) {
|
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]))
|
tryMove(pixelMap[pixel.x-1][pixel.y],(randomDestination[0] - 1),(randomDestination[1]))
|
||||||
}
|
}
|
||||||
if(!isEmpty(pixel.x+1,pixel.y)) {
|
}
|
||||||
|
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]))
|
tryMove(pixelMap[pixel.x+1][pixel.y],(randomDestination[0] + 1),(randomDestination[1]))
|
||||||
}
|
}
|
||||||
if(!isEmpty(pixel.x,pixel.y-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))
|
tryMove(pixelMap[pixel.x][pixel.y-1],(randomDestination[0]),(randomDestination[1] - 1))
|
||||||
}
|
}
|
||||||
if(!isEmpty(pixel.x,pixel.y+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))
|
tryMove(pixelMap[pixel.x][pixel.y+1],(randomDestination[0]),(randomDestination[1] + 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
category: "machines",
|
category: "machines",
|
||||||
state: "solid",
|
state: "solid",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue