Esempio n. 1
0
        public override void UpdateGraphicsToMatchSurroundings()
        {
            int       useHorizontal = 0;
            int       x             = Location.X;
            int       y             = Location.Y;
            TileField tileField     = Parent as TileField;

            if (tileField.GetTile(x, y - 1) is WallTile)
            {
                useHorizontal -= 1;
            }
            if (tileField.GetTile(x + 1, y) is WallTile)
            {
                useHorizontal += 1;
            }
            if (tileField.GetTile(x, y + 1) is WallTile)
            {
                useHorizontal -= 1;
            }
            if (tileField.GetTile(x - 1, y) is WallTile)
            {
                useHorizontal += 1;
            }
            if (useHorizontal <= -1)
            {
                sprite          = new SpriteSheet("VerticalDoor");
                secondarySprite = new SpriteSheet("VerticalDoorOverlay");
                isHorizontal    = false;
            }
            else
            {
                sprite          = new SpriteSheet("HorizontalDoor");
                secondarySprite = new SpriteSheet("HorizontalDoorOverlay");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new player for a specific level
        /// </summary>
        /// <param name="level">The Level that the player should play in</param>
        /// <param name="location">The starting location of the player</param>
        /// <param name="score">The initial score of the player. Default is 0.</param>
        public PlayerGameObject(Level level, Point location, int score = 0) : base(level.Tiles, level.TimeBetweenActions, "player@4x4", 0, "")
        {
            player = new DummyPlayer(level.Tiles, location, score);
            Level  = level;
            Teleport(location);
            TileField.RevealArea(location);
            soundFootsteps = GameEnvironment.AssetManager.Content.Load <SoundEffect>("footsteps").CreateInstance();

            player.OnPlayerAction += delegate(DummyPlayer player) { OnPlayerAction?.Invoke(this); };
            player.OnPlayerWin    += delegate(DummyPlayer player) { OnPlayerWin?.Invoke(this); };
            player.OnPlayerLose   += delegate(DummyPlayer player)
            {
                OnPlayerLose?.Invoke(this);
                GameEnvironment.AssetManager.PlaySound("scream");
            };
            player.OnMoveSmoothly += delegate(DummyPlayer player, Direction direction)
            {
                MoveSmoothly(direction);
                soundFootsteps.Play();
            };
            player.OnTeleport += delegate(DummyPlayer player)
            {
                Teleport(player.Location);
                GameEnvironment.AssetManager.PlaySound("climbing_sound");
            };
            StoppedMoving += delegate(GameObject obj)
            {
                player.EndMoveSmoothly();
                soundFootsteps.Stop();
            };
        }
Esempio n. 3
0
 public DummyPlayer(TileField tileField, Point location, int score = 0)
 {
     TileField     = tileField;
     this.location = location;
     Score         = score;
     Inventory     = new Inventory();
 }
Esempio n. 4
0
        public override bool IsActionForbiddenFromHere(ITileFieldPlayer player, PlayerAction action)
        {
            if (!TileField.GetTile(Location + lastDirection.ToPoint()).StopsSliding)
            {
                return(false);
            }

            return(base.IsActionForbiddenFromHere(player, action));
        }
Esempio n. 5
0
        /// <summary>
        /// Shows a file dialog to choose a file to which the tileField will be saved.
        /// </summary>
        /// <param name="tileField"> The level being saved. </param>
        public static void Save(TileField tileField)
        {
            string fileName = ShowSaveFileDialog();

            if (fileName != null)
            {
                Save(tileField, fileName);
            }
        }
Esempio n. 6
0
 public override void PerformAction(ITileFieldPlayer player, PlayerAction action)
 {
     if (!TileField.GetTile(Location + lastDirection.ToPoint()).StopsSliding)
     {
         player.MoveSmoothly(lastDirection);
     }
     else
     {
         base.PerformAction(player, action);
     }
 }
Esempio n. 7
0
        private void InitLevel(TileField tf = null)
        {
            if (tf == null)
            {
                tf = CreateTileField();
            }

            //Resize and reposition the level to prevent it from overlapping with the controls
            level                = new EditorLevel(tf, 0, VisibleLevelArea);
            level.Position      += new Vector2(TILES_LIST_WIDTH, 0);
            level.Player.OnMove += PlayerMoved;
        }
Esempio n. 8
0
        public EditorLevel(TileField tileField, int levelindex = 0, Point?screenSize = null)
        {
            start      = new Point(1, 1);
            numRows    = tileField.Rows;
            numColumns = tileField.Columns;
            Tiles      = tileField;
            Tiles.UpdateGraphicsToMatchSurroundings();
            Tiles.FogOfWar = false;
            usePlayer(new EditorPlayer(this, start));

            Camera.SetScreenSize(screenSize);
        }
Esempio n. 9
0
 /// <summary>
 /// Saves the level to a file with the specified name.
 /// </summary>
 /// <param name="tileField">The level being saved.</param>
 /// <param name="fileName">The file to save to.</param>
 public static void Save(TileField tileField, string fileName)
 {
     try
     {
         using (Stream stream = new FileStream(fileName, FileMode.Create))
             using (XmlWriter writer = XmlWriter.Create(stream))
                 new XmlSerializer(typeof(LevelData)).Serialize(writer, new LevelData(tileField));
     }
     catch (IOException e)
     {
         MessageBox.Show(Strings.save_file_error_with_comment + e.Message);
     }
 }
Esempio n. 10
0
        private TileField CreateTileField()
        {
            TileField tf;

            if (newLevelBox == null)
            {
                tf = new TileField(Level.DEFAULT_NUM_ROWS, Level.DEFAULT_NUM_COLS);
            }
            else
            {
                tf = new TileField(newLevelBox.Rows, newLevelBox.Columns);
            }
            EditorLevel.FillWithEmptyTiles(tf);
            return(tf);
        }
Esempio n. 11
0
        /// <summary>
        /// Centers the camera above the object it follows
        /// </summary>
        public void UpdateCamera()
        {
            if (objectToFollow == null)
            {
                position = Vector2.Zero;
                return;
            }
            Rectangle rect       = objectToFollow.BoundingBox;
            float     preferredX = rect.Center.X - ScreenSize.X / 2;
            float     preferredY = rect.Center.Y - ScreenSize.Y / 2;
            TileField tiles      = (TileField)Find("tiles");

            position.X = -MathHelper.Clamp(preferredX, 0, tiles.CellWidth * tiles.Columns - ScreenSize.X);
            position.Y = -MathHelper.Clamp(preferredY, 0, tiles.CellHeight * tiles.Rows - ScreenSize.Y);
        }
Esempio n. 12
0
        /// <summary>
        /// Performs the specified action
        /// </summary>
        /// <param name="action">The PlayerAction to perform</param>
        protected void PerformAction(PlayerAction action)
        {
            if (!player.CanPerformAction(action))
            {
                throw new PlayerActionNotAllowedException();
            }

            LastAction = action;
            if (action.IsDirection())
            {
                Direction = action.ToDirection();
            }

            player.PerformAction(action);

            TileField.Visit(Location);
        }
Esempio n. 13
0
        public static void FillWithEmptyTiles(TileField tf)
        {
            for (int x = 0; x < tf.Columns; x++)
            {
                for (int y = 0; y < tf.Rows; y++)
                {
                    if (tf.OnEdgeOfTileField(x, y))
                    {
                        tf.Add(new WallTile(), x, y);
                    }
                    else
                    {
                        tf.Add(new FloorTile(), x, y);
                    }
                }
            }

            tf.UpdateGraphicsToMatchSurroundings();
        }
Esempio n. 14
0
        public PlayingLevel(TileField tileField, int levelindex = 0, int playerIndex = 0, int playerDifficulty = 0)
        {
            start      = tileField.Start;
            numRows    = tileField.Rows;
            numColumns = tileField.Columns;
            Tiles      = tileField;
            Tiles.UpdateGraphicsToMatchSurroundings();
            Tiles.UpdatePortals();
            switch (playerIndex)
            {
            case 0:
                UseHumanPlayer();
                break;

            case 1:
                UseRandomWalkingAIPlayer();
                break;

            case 2:
                try
                {
                    UseAStarAIPlayer();
                }
                catch (Exception e)
                {
                    goto default;
                }
                break;

            case 3:
                UseMonteCarloAIPlayer();
                break;

            case 4:
                UseFloodFillAIPlayer();
                break;

            default:
                UseHumanPlayer();
                break;
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Checks if this tile prevents a player who is currently at this Tile from performing the specified action
 /// </summary>
 /// <param name="player">The player at this Tile that wants to perform the action</param>
 /// <param name="action">The action to check</param>
 /// <returns>true if the action is forbidden by this Tile. false otherwise.</returns>
 public virtual bool IsActionForbiddenFromHere(ITileFieldPlayer player, PlayerAction action)
 {
     return(action == PlayerAction.SPECIAL || !TileField.GetTile(GetLocationAfterAction(action)).CanPlayerMoveHere(player));
 }
Esempio n. 16
0
 public Level(bool fogOfWar = true)
 {
     Tiles = new TileField(numRows, numColumns, fogOfWar, 0, "tiles");
 }
Esempio n. 17
0
 public UntimedPlayer(TileField tileField, Point location, int score = 0) : base(tileField, location, score)
 {
     OnMoveSmoothly += delegate(DummyPlayer player, Direction direction) { EndMoveSmoothly(); };
 }