mardi 15 novembre 2016

AS3 Array TileMap Checking?

I am creating a Indie City Building Game and I am trying to code a system to check if a Water Supply has been constructed within 4X4 of the set tile.

public function checkWater(mY, mX): void {
        // LEFT
        if (blankMap[mY][mX - 1] == 8) {
            trace("resource found left");
        }
        if (blankMap[mY][mX - 2] == 8) {
            trace("resource found left");
        }
        if (blankMap[mY][mX - 3] == 8) {
            trace("resource found left");
        }
        if (blankMap[mY][mX - 4] == 8) {
            trace("resource found left");
        }
}

// RIGHT
if (blankMap[mY][mX + 1] == 8) {
            trace("resource found right");
        }
        if (blankMap[mY][mX + 2] == 8) {
            trace("resource found right");
        }
        if (blankMap[mY][mX + 3] == 8) {
            trace("resource found right");
        }
        if (blankMap[mY][mX + 4] == 8) {
            trace("resource found right");
        }

This system works, but only for east, south, west and north. Is there an easier way to do this? It will only check to see if the tiles 1, 2, 3 and 4 spaces away contain a water supply.... Which is the number 8 on the tile map.

Any advice would be brilliant. I basically need to be able to check the tile area/tile map (a 4X4 maximum distance) for the NUMBER 8 instead of 0 which would mean the tile is grass. It sounds so easy and I am sure it is, I just can't get my head around this math. Thank you.

Aucun commentaire:

Enregistrer un commentaire