Beispiel #1
0
        /// <summary>
        /// Verifies that the entity is attempting to move into a valid tile
        /// </summary>
        /// <param name="map"></param>
        /// <param name="attemptedMovePosition"></param>
        /// <returns></returns>
        public bool CanMoveIntoTile(int level, Point attemptedMovePosition)
        {
            Terrain map = TerrainManager.GetCurrentMap(level);

            // Make sure we stay within the map boundaries
            if ((attemptedMovePosition.X >= map.MapSize.X || attemptedMovePosition.X < 0) ||
                (attemptedMovePosition.Y >= map.MapSize.Y || attemptedMovePosition.Y < 0))
            {
                return(false);
            }

            // Checks if the tile has a collider
            if (map.GetTileAtGridPosition(attemptedMovePosition).IsCollider)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public Player() : base(TerrainManager.CurrentLevel)
        {
            // Make sure we have a valid map to load into
            if (TerrainManager.MapList.Equals(null))
            {
                throw new Exception("Map passed to Player constructor is empty!");
            }

            this.CurrentLevel = TerrainManager.CurrentLevel;

            this.GridPosition      = new Point(0, 0);
            this.ObjectSize        = this.ScaleObjectToTileSize();
            this.DrawPosition      = this.UpdateDrawPosition();
            this.DrawOffset        = this.GenerateDrawOffset();
            this.DrawRectangle     = this.UpdateDrawRectangle(this.GridPosition, TerrainManager.GetCurrentMap(this.CurrentLevel).MapSize);
            this.IsCollider        = true;
            this.IsDormant         = false;
            this.currentExperience = 0;
            this.movementTimeLimit = 500;
            this.moveAllowed       = true;
        }
Beispiel #3
0
 public Point GetMapSize(int level)
 {
     return(TerrainManager.GetMapSize(level));
 }
        public static void ProcessPlayerMovement(GameTime gameTime)
        {
            if (gameTime.TotalGameTime.TotalMilliseconds - MainGame.GetPlayer.LastUpdate >= MainGame.GetPlayer.MovementTimeLimit && !MainGame.GetPlayer.MoveAllowed)
            {
                MainGame.GetPlayer.MoveAllowed = true;
            }

            if (!MainGame.GetPlayer.MoveAllowed)
            {
                return;
            }

            Point newGridPosition = MainGame.GetPlayer.GridPosition;

            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                newGridPosition.Y -= 1;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                newGridPosition.Y += 1;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                newGridPosition.X -= 1;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                newGridPosition.X += 1;
            }
            else
            {
                return;     // No movement input detected, exit early
            }
            if (newGridPosition != MainGame.GetPlayer.GridPosition)
            {
                // Movement has been detected, verify that we can actually move into this tile
                if (MainGame.GetPlayer.CanMoveIntoTile(MainGame.GetPlayer.CurrentLevel, newGridPosition))
                {
                    MainGame.GetPlayer.DrawRectangle = MainGame.GetPlayer.UpdateDrawRectangle(newGridPosition, TerrainManager.GetMapSize(MainGame.GetPlayer.CurrentLevel));
                    MainGame.GetPlayer.LastUpdate    = gameTime.TotalGameTime.TotalMilliseconds;
                    MainGame.GetPlayer.MoveAllowed   = false;
                }

                else
                {
                    return;     // Illegal move, exit
                }
            }
        }