I am currently trying to create a door entity. The goal is to have the door entity linked with another door entity and transport the player to the location of that entity on collision.
What would be a good way to implement this type of door system? My goal is for the Entity to be flexible enough to send the player to other levels as well.
Below is what I came up with and my thought process, however, it doesn’t work. The door entity constructor just takes a X and Y value for its position and an entity (the door that it will send the player to). So in most cases, it will be something like:
var door1 = new Door(x, y, door2);
var door2 = new Door(x, y, door1);
and this is the door class
public class Door extends Entity
{
public var portalX:int = 0;
public var portalY:int = 0;
public function Door(xPos:int, yPos:int, exit:Entity)
{
type = "door"
x = xPos;
y = yPos;
setHitbox(32, 26);
portalX = exit + 15;
portalY = exit + 27;
}
}
and the function in my Player class attempting to use the door
private function useDoor():void
{
if (collide("door", x, y))
{
x = collide("door", x, y).portalX;
y = collide("door", x, y).portalY;
}
}
but it returns this error
“Error: Access of possibly undefined property portalY through a reference with static type net.flashpunk:Entity. y = collide(“door”, x, y).portalY;”