Hi all,
At the moment I have a tile based system and I want to move either North, East, South or West of a tile, depending on what tile the ‘player’ is in. Done this fine. However my problems comes because of walls in the tile system. I have programmed A* to take me round the map and avoid the walls. However if I click and the tile is against a wall, A* freaks out because the verification is before running A*.
Red = ‘Player’
Blue = ‘Enemy’
LightBlue = ‘CourserPos’
What i need is to analyse the tiles around. So if my test is the north tile, like north round to west clockwise, if my test is the east tile, look east round to north for all four cases.
I have been stuck on this one for a while now for a smart solution. I am able to code everything manually and this is loads of lines that must have smart solution, however I want a way that loops in some way.
var neibours = this.returnValidNeibours(this.Mapx, this.Mapy);
//[north,east,south,west] t or f
if (yTile < this.Mapy) { //north
//var neiboursSub = neibours.slice(0, 4); ???
var pos = createVector(this.Mapx, this.Mapy-1);
return pos
}
if (xTile > this.Mapx) { //east
var pos = createVector(this.Mapx+1, this.Mapy);
return pos
}
if (yTile > this.Mapy) {//south
var pos = createVector(this.Mapx, this.Mapy+1);
return pos
}
if (xTile < this.Mapx) { //west
var pos = createVector(this.Mapx-1, this.Mapy);
return pos
}
The above code is the section where it decides what case to try. x/yTile is the player, and this.Mapx/y is the ‘enemy’ Objects position. I need some sort of algorithm or method to test these effectively? I have thought about using arr.splice on an array that is longer eg repeats to get the 4 tests i need in the right place.
Cant figure a smart solution out on this one.
Thanks for advance for taking time to read this and offering any ideas!
EDIT: Im not looking for the code itself, just a idea or an example that I having thought of, or that I’ll just have to go long way around and there isn’t a way…
Peachman.