Hello Everyone!
I’ve been working on a OOP tile based game for the past few days and I’ve come across a problem, that has me stuck. The problem is this:
Using the ideas from http://www.tonypa.pri.ee I’ve created a function that checks where the corners of an object are, and whether they are over any tiles the are not walkable. This function sets the objects properties to true if the tile is walkable or false if not (this all seems to work fine). The moveChar() function then allows the character to move in the direction requested if two critera are true. See the code below for an example of moving to the left:
[FONT=Courier New]if (dirX == -1) {
trace(ob.downLeft +" and "+ob.upLeft);
if (ob.downLeft && ob.upLeft) {
trace(“Move Left”);
ob.setX(currentX += dirX * speed);
} else {
trace(“Stop Left”);
ob.setX(ob.xTile * tileWidth + ob.width);
}
}[/FONT]
The problem is even if one or both of ob.downLeft and ob.upLeft are false the code in the first section of the if statement runs. The code in the second section never seems to run (even when the first trace says “false and true” or “false and false”).
All of the required conditional properties are set to be the Boolean type, and the output of all traces seems to be ok.
I hope someone can point out what’s wrong!
Cheers
Tom