Walls and other solid objects
This will be pretty easy to do and apart from a few extra condition checks in your movement code everything else is really just a case of duplicating.
Obviously to begin with we are going to need a wall tile, for this tutorial I decided to go with the orange wall of blockade. Took a while to plan out and design before creating such a tile but here it is if you wish to use it, carefully.

The wall as usual is a .png. The .png canvas height is made to be 50 pixels, double the ground tile height. This means our object can be any height between 0 and 50 pixels and by halving the height attribute of the object we can always line it up with ground tile it is on top of.
For speed and ease I’ll be going back to the original source of tutorial 02 where the map is just directly in the array rather than loaded as XML from a database. Ralph, our playable character has also been added in. It shouldn’t be hard at all though to use a later code version as I said it really is just a case of repeating some steps.
Current source of all the isometric tutorials minus the loading/saving can be seen here:
http://glacialflame.com/tutorials/tiles/06/source.html
Step One – loading our isometric objects
Adding objects is simple. Duplicate the ground tile code and then draw it on top once our ground layer has been drawn. Using a second array for objects means for simplicity all we have to do is look up the array coordinates relating to the players desired position, if there is an entry then that coordinate is impassable.
So duplicate the map array and imagine for just now zero is passable and one is a wall.
var objectMap = Array([0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,1,1,0,0],[0,1,1,0,0,1],[1,0,1,1,0,1],[0,0,0,0,0,0],[1,0,1,0,1,0],[1,1,1,0,0,0]);
Also similar to when you added your playable character, duplicate the image arrays and update the loader. Around the same area as your tileDict and tileImg add:
var objectDict = Array("wall.png");
var objectImg = new Array();
In your loadImg() function add:
for(var i=0;i<objectDict.length;i++){
objectImg[i] = new Image();
objectImg[i].src = objectDict[i];
objectImg[i].onload = function(){
loaded++;
}
}
in your loadAll() function update your loaded condition to check if all object images have been loaded like so:
if(loaded == tileDict.length + charDict.length + objectDict.length){
All done!
Step Two – Let the user personally reflect over our wall object
In order to draw the objects into our map go the function drawMap() and within the loops add the following, underneath var drawTile = ma… is just fine:
var drawObj = objectMap[i][j];
Now we want objects to be drawn on top of our ground so under our ctx.drawImage(tileImg[drawTile],xpos,ypos) and before our character drawing add the following:
if(drawObj){
ctx.drawImage(objectImg[drawObj-1],xpos,ypos-(objectImg[drawObj-1].height/2));
}
This should explain itself, if drawObj (which is equal to the current drawing coordinate in our array ) is anything above zero then… well… draw it. The reason for drawObj-1 is because our object images start at zero however in our object array we start at 1. Otherwise every 0 in our array would represent a wall.
You should now be able to run Ralph around the map behind and in front of walls.
Step Three – HALT! You can’t walk there Ralph
Finally we update our movement code to check if there is an object or not.
Within our checkKeycode(event) function we can throw in the following around our current movement code:
if(!objectMap[playerX-1][playerY]){
playerX--;
}
The if check makes sure that the desired players coordinates within the objectMap array is false allowing the player to move that direction. This is done for each direction like so:
case 38:
if(!objectMap[playerX-1][playerY]){
playerX--;
}
break;
case 40:
if(!objectMap[playerX+1][playerY]){
playerX++;
}
break;
case 39:
if(!objectMap[playerX][playerY-1]){
playerY--;
}
break;
case 37:
if(!objectMap[playerX][playerY+1]){
playerY++;
}
break;
And that’s it. Ralph can now run about our fields with only the orange walls of blockade preventing his fun.
Full source can be found here:
http://glacialflame.com/tutorials/tiles/06/
As always let me know how you get on!
All the best.