fd9
07-13-2004, 08:40 AM
In a simple grid-based puzzle game I'm making, I need a way to find out where the player is allowed to move (there are various "walls" set up around the board). I do this by looking at the four areas surrounding the player, and determining if each one has an empty space or not. A buddy of mine suggested a simple and effective way to accomplish this. In each wall MC I have the following code:
onClipEvent (load) {
this._name = "wall" + Math.floor(this._x) + "_" + Math.floor(this._y);
}
and in the player's MC, I have these lines of code:
//Round x and y coordinates
roundedx = Math.floor(this._x);
roundedy = Math.floor(this._y);
//Determine if there was a collision with a wall
Ecollision = (_root["wall" + (roundedx + 30) + "_" + (roundedy)]._x != undefined);
Wcollision = (_root["wall" + (roundedx - 30) + "_" + (roundedy)]._x != undefined);
Ncollision = (_root["wall" + (roundedx) + "_" + (roundedy - 30)]._x != undefined);
Scollision = (_root["wall" + (roundedx) + "_" + (roundedy + 30)]._x != undefined);
I use the same technique for not only walls, but other various objects in the game as well. The problem is, when I try to access something in the MC (such as a function or member variable), I can't because the _name keeps changing. For example, I can't do:
_root.Wall.SomeVariable
because in reality it would look like
_root.wall25_15.SomeVariable
Is there some other way I could use the same approach without changing _name, or is there another way I could access Wall's members?
Thanks in advance.
onClipEvent (load) {
this._name = "wall" + Math.floor(this._x) + "_" + Math.floor(this._y);
}
and in the player's MC, I have these lines of code:
//Round x and y coordinates
roundedx = Math.floor(this._x);
roundedy = Math.floor(this._y);
//Determine if there was a collision with a wall
Ecollision = (_root["wall" + (roundedx + 30) + "_" + (roundedy)]._x != undefined);
Wcollision = (_root["wall" + (roundedx - 30) + "_" + (roundedy)]._x != undefined);
Ncollision = (_root["wall" + (roundedx) + "_" + (roundedy - 30)]._x != undefined);
Scollision = (_root["wall" + (roundedx) + "_" + (roundedy + 30)]._x != undefined);
I use the same technique for not only walls, but other various objects in the game as well. The problem is, when I try to access something in the MC (such as a function or member variable), I can't because the _name keeps changing. For example, I can't do:
_root.Wall.SomeVariable
because in reality it would look like
_root.wall25_15.SomeVariable
Is there some other way I could use the same approach without changing _name, or is there another way I could access Wall's members?
Thanks in advance.