Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in getRandomFloorPosition for part 4. #1

Open
remcopeereboom opened this issue Aug 14, 2015 · 0 comments
Open

Bug in getRandomFloorPosition for part 4. #1

remcopeereboom opened this issue Aug 14, 2015 · 0 comments

Comments

@remcopeereboom
Copy link

Game.Map.prototype.getRandomFloorPosition = function() {
    // Randomly generate a tile which is a floor
    var x, y;
    do {
        x = Math.floor(Math.random() * this._width);
        y = Math.floor(Math.random() * this._width);
    } while(this.getTile(x, y) != Game.Tile.floorTile);
    return {x: x, y: y};
}

You should set the y-coordinate to a random times the map height, not its width.

This may not be the best algorithm for maps with a low ratio of floors, you might want to add a counter to just set a random tile as floor tile if after x tries you still haven't found a spot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant