Пример #1
0
        public void Move(Vector2 movement, Map map)
        {
            if (!map.IsOverMapEdge(Position + movement))
            {
                var targetTilePosition = map.GetTile(Position + movement);

                if (targetTilePosition.Object != null)
                {
                    //Something there already - attack
                    CombatManager.Attack(this, targetTilePosition.Object);
                }
                else
                {
                    //Move and update tile object
                    OldPosition = Position;
                    Position += movement;
                    map.SetTileObject(this);
                }
            }
        }
Пример #2
0
        public void Move(Vector2 playerPosition, List<Mob> mobs, Map map)
        {
            //If dead then stay still
            if (Health <= 0) return;

            var movement = selectTarget(playerPosition, mobs);

            //round the movements to integers as the tiles positions are currently point-based
            movement.X = (float)Math.Round(movement.X);
            movement.Y = (float)Math.Round(movement.Y);

            if (Math.Abs(movement.X) > Math.Abs(movement.Y))
            {
                movement.Y = 0;
            }
            else
            {
                movement.X = 0;
            }

            if (!map.IsOverMapEdge(Position + movement))
            {
                var targetTilePosition = map.GetTile(Position + movement);

                if (targetTilePosition.Object != null)
                {
                    //Something there already - attack!
                    CombatManager.Attack(this, targetTilePosition.Object);
                }
                else
                {
                    //Move and update tile object
                    OldPosition = Position;
                    Position += movement;
                    map.SetTileObject(this);
                }
            }
        }