So, I have some movable blocks in my game, with the parent entity “parGameOb”. Basically, when a big line of blocks is pushed, I want to find the last block on that line, and see whether the next space is empty or if there’s an unmovable wall there. If there’s an empty space, I want to tell each of those blocks to move one space.
Here’s the function my Player object calls when colliding with a movable block:
private function checkline(_dir:int):Boolean
{
var tempX:int = x;
var tempY:int = y;
var movX:int = 0;
var movY:int = 0;
var collideOK:Array = ["movable"]; //stuff that can be moved
var collideBAD:Array = ["solid"]; //stuff that will always stop things moving
if (_dir == 0) movY = -1; //up
if (_dir == 1) movY = 1; //down
if (_dir == 2) movX = -1; //left
if (_dir == 3) movX = 1; //right
var done:Boolean = false;
while (!done) {
var e:parGameOb = collideTypes(collideOK, tempX, tempY);
if (e != null) {
e.moveOneSpace(movX, movY);
}
if (collideTypes(collideBAD, tempX, tempY)) done = true;
else {
tempX += movX;
tempY += movY;
}
}
}
The problem is that the temp variable “e” is an instance of parGameOb, and I can’t call collideTypes on it, even though it extends Entity. I’m probably not understaind how inheritance works, but I want to be able to find collisions with a parGameOb, then call a fumnction to any instance of it that I find, What’s the best way to do that?