public virtual bool checkPushable(Direction direction, List <SuckerbanObject> alreadyPushedObjects) { // Check if pushable and calculate what objects should be pushed. // returns True if pushable // To circumvent recursions if (alreadyPushedObjects.Contains(this)) { return(true); } alreadyPushedObjects.Add(this); foreach (IntVector2 sub_position in positions) { IntVector2 positionInFront = sub_position + (IntVector2)direction.GetIntVector2(); SuckerbanObject objInFront = level.GetObjectInPosition(positionInFront); if (objInFront == null) { // There's nothing in front continue; } if (!objInFront.isPushable) { // Unpushable object is in front return(false); } if (objInFront == this) { // Ignore if it's me continue; } if (direction == Direction.Down && (this is Player) && (objInFront is Spike)) { // If facing spike can't push continue; } bool pushSuccess = objInFront.checkPushable(direction, alreadyPushedObjects); if (!pushSuccess) { return(false); // Propagate failness } } return(true); }
public void Explode() { BombFlame.Create(position, 0.5f); foreach (Direction direction in Enum.GetValues(typeof(Direction))) { for (int l = 1; l < bombLength + 1; l++) { IntVector2 positionToFlame = position + direction.GetIntVector2() * l; SuckerbanObject obj = level.GetObjectInPosition(positionToFlame); if (obj is SteelWall) { break; } if (obj is BrickWall) { ((BrickWall)obj).Destroy(); break; } BombFlame.Create(positionToFlame, 0.5f); } } Destroy(transform.gameObject); }
public bool RemoveFromGrid(SuckerbanObject obj) { return(allObjectsOnGrid.Remove(obj)); }
public void PlaceOnGrid(SuckerbanObject obj) { allObjectsOnGrid.Add(obj); }