public void HandleCollision(IPlayer link, ISprite border, Direction side, Game1 game) { if (!link.IsJumping()) { if (border is ShutDoor shutDoor) { bool openedByBlock = false; shutDoor.OpenDoor(openedByBlock); } else if (border is LockedDoor lockedDoor) { if (link.HasKey() || link.HasItem(PlayerItems.MagicalKey)) { lockedDoor.OpenDoor(); link.DecrementKey(); foreach (ISprite sprite in game.Rooms[game.levelMachine.GetAdjacentRoom(game.RoomIndex, side)].LoadLevel.RoomSprite.RoomSprites) { if (sprite is LockedDoor door && door.Side == DirectionExtension.OppositeDirection(side)) { door.OpenDoor(); } } } } } }
/// <summary> /// Moves an robot in an straight line. Applies collisions /// </summary> /// <param name="robotId">the id of the robot to move</param> /// <param name="amount">the number of fields to move</param> /// <param name="forward">the relative direction to move to</param> /// <returns>the new position of the robot after the movement executed</returns> /// <exception cref="ArgumentOutOfRangeException">If the robot is not fetchable</exception> public Position Move(int robotId, int amount, RelativeDirection forward) { #if DEBUG Console.Out.WriteLine("Robot : " + robotId + " moves " + amount + " fields " + forward); #endif if (_game.Entitys[robotId] is RobotInfo { } robotInfo) { Direction resultDirection = DirectionExtension.ResolveDirection(forward, robotInfo.Direction); return(Move(robotInfo, amount, resultDirection)); }