Ejemplo n.º 1
0
        /// <summary>
        /// Rotate a player.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="deltaTimeSeconds"></param>
        private void RotatePlayer(MetaPlayer player, double deltaTimeSeconds)
        {
            Player info = player.Player;

            if (info.RotationDirection != VTankObject.Direction.NONE)
            {
                double speed = (ANGULAR_VELOCITY * info.SpeedFactor) * deltaTimeSeconds;
                if (info.RotationDirection == VTankObject.Direction.RIGHT)
                {
                    speed = -speed;
                }

                double angle = (info.Angle * speed) % (Math.PI * 2);
                info.Angle = angle;

                if (player.Player == LocalPlayer)
                {
                    player.SecondsUntilAngle -= deltaTimeSeconds;
                    if (player.SecondsUntilAngle <= 0)
                    {
                        info.Angle             = player.GoalAngle;
                        player.GoalAngle       = 0;
                        player.HasGoal         = false;
                        info.RotationDirection = VTankObject.Direction.NONE;
                        bot.GameServer.Rotate(info.Angle, VTankObject.Direction.NONE);
                        bot.InvokeOnCompletedRotation();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start moving forward.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="pos"></param>
        private void StartMovingForward(MetaPlayer player, VTankObject.Point pos)
        {
            player.Player.MovementDirection = VTankObject.Direction.FORWARD;
            player.Player.Position          = pos;

            bot.GameServer.Move(pos.x, pos.y, VTankObject.Direction.FORWARD);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adjust a player's position according to his movement/rotation.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="deltaTimeSeconds"></param>
        private void MovePlayer(MetaPlayer player, double deltaTimeSeconds)
        {
            Player info = player.Player;

            if (info.MovementDirection != VTankObject.Direction.NONE)
            {
                double speed = (VELOCITY * info.SpeedFactor) * deltaTimeSeconds;
                if (info.MovementDirection == VTankObject.Direction.REVERSE)
                {
                    speed = -speed;
                }

                VTankObject.Point newPosition = new VTankObject.Point(
                    info.Position.x + Math.Cos(info.Angle) * speed,
                    info.Position.y + Math.Sin(info.Angle) * speed
                    );

                if (!CheckCollision(newPosition))
                {
                    info.SetPosition(newPosition);
                }
                else
                {
                    info.MovementDirection = VTankObject.Direction.NONE;
                    if (info == LocalPlayer)
                    {
                        bot.GameServer.Move(info.Position.x, info.Position.y, VTankObject.Direction.NONE);
                        bot.InvokeOnHitWall();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Rotate [player] until he is facing [angleInRadians].
        /// </summary>
        /// <param name="player">Player to rotate.</param>
        /// <param name="angleInRadians">Angle to rotate to. This is not a theta value.</param>
        public void RotateTo(Player player, double angleInRadians)
        {
            MetaPlayer currentPlayer = players[player.ID];

            currentPlayer.GoalAngle = (angleInRadians) % (Math.PI * 2.0f);

            double currentAngle = player.Angle;

            double distance = 0;

            VTankObject.Direction result = ShortestDistance(currentAngle, angleInRadians, out distance);
            if (result == VTankObject.Direction.RIGHT)
            {
                player.RotationDirection = VTankObject.Direction.RIGHT;
            }
            else
            {
                player.RotationDirection = VTankObject.Direction.LEFT;
            }

            // Time = distance/velocity
            double timeInSeconds = Math.Abs(
                distance / (ANGULAR_VELOCITY * player.SpeedFactor));

            currentPlayer.SecondsUntilAngle = timeInSeconds;

            bot.GameServer.Rotate(currentAngle, player.RotationDirection);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Ask the game tracker to move a player to a certain position.
        /// </summary>
        /// <param name="player">Player to move.</param>
        /// <param name="x">X-position to move to.</param>
        /// <param name="y">Y-position to move to.</param>
        public void StartMoving(VTankObject.Direction direction)
        {
            MetaPlayer movingPlayer = players[LocalPlayer.ID];

            SetPlayerMovement(LocalPlayer, LocalPlayer.Position, direction);
            bot.GameServer.Move(movingPlayer.Player.Position.x, movingPlayer.Player.Position.y,
                                direction);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Check if the bot is finished moving.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="deltaTimeInSeconds"></param>
        /// <returns></returns>
        private static bool DoneMoving(MetaPlayer player, double deltaTimeInSeconds)
        {
            player.SecondsUntilGoal -= deltaTimeInSeconds;
            if (player.SecondsUntilGoal <= 0)
            {
                player.SecondsUntilGoal = 0;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get the next position.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="currentNode"></param>
        /// <returns></returns>
        private VTankObject.Point SetPosition(MetaPlayer player, Node currentNode)
        {
            double halfTile = Tile.TILE_SIZE_IN_PIXELS / 2;

            VTankObject.Point newPosition = new VTankObject.Point(
                (currentNode.X * Tile.TILE_SIZE_IN_PIXELS) + halfTile,
                -((currentNode.Y * Tile.TILE_SIZE_IN_PIXELS + halfTile)));
            player.Player.Position = newPosition;

            return(newPosition);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Stop moving forward.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="pos"></param>
        private void StopMovingForward(MetaPlayer player, VTankObject.Point pos)
        {
            player.Player.Position = pos;

            //if (player.Player.MovementDirection != VTankObject.Direction.NONE)
            //{
            player.Player.MovementDirection = VTankObject.Direction.NONE;

            bot.GameServer.Move(pos.x, pos.y, VTankObject.Direction.NONE);
            //}
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Test if two angles are approximately equal.
        /// </summary>
        /// <param name="a1">Angle 1.</param>
        /// <param name="a2">Angle 2.</param>
        /// <returns>True if the two angles are approximately equal.</returns>
        private static bool DoneRotating(MetaPlayer player, double deltaTimeInSeconds)
        {
            player.SecondsUntilAngle -= deltaTimeInSeconds;
            if (player.SecondsUntilAngle <= 0)
            {
                player.SecondsUntilAngle = 0;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Interrupt a movement, if one is in progress.
        /// </summary>
        public void StopMoving()
        {
            if (LocalPlayer == null)
            {
                return;
            }

            MetaPlayer player = players[LocalPlayer.ID];

            player.UnsetGoalTile();

            player.SecondsUntilAngle        = 0;
            player.CurrentNode              = null;
            player.Paused                   = false;
            player.Player.MovementDirection = VTankObject.Direction.NONE;
            player.Player.RotationDirection = VTankObject.Direction.NONE;

            bot.GameServer.Move(player.Player.Position.x, player.Player.Position.y, VTankObject.Direction.NONE);
            bot.GameServer.Rotate(player.Player.Angle, VTankObject.Direction.NONE);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Get the next position.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="currentNode"></param>
        /// <returns></returns>
        private VTankObject.Point SetPosition(MetaPlayer player, Node currentNode)
        {
            double halfTile = Tile.TILE_SIZE_IN_PIXELS / 2;
            VTankObject.Point newPosition = new VTankObject.Point(
                (currentNode.X * Tile.TILE_SIZE_IN_PIXELS) + halfTile,
                -((currentNode.Y * Tile.TILE_SIZE_IN_PIXELS + halfTile)));
            player.Player.Position = newPosition;

            return newPosition;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Rotate a player.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="deltaTimeSeconds"></param>
        private void RotatePlayer(MetaPlayer player, double deltaTimeSeconds)
        {
            Player info = player.Player;
            if (info.RotationDirection != VTankObject.Direction.NONE)
            {
                double speed = (ANGULAR_VELOCITY * info.SpeedFactor) * deltaTimeSeconds;
                if (info.RotationDirection == VTankObject.Direction.RIGHT)
                {
                    speed = -speed;
                }

                double angle = (info.Angle * speed) % (Math.PI * 2);
                info.Angle = angle;

                if (player.Player == LocalPlayer)
                {
                    player.SecondsUntilAngle -= deltaTimeSeconds;
                    if (player.SecondsUntilAngle <= 0)
                    {
                        info.Angle = player.GoalAngle;
                        player.GoalAngle = 0;
                        player.HasGoal = false;
                        info.RotationDirection = VTankObject.Direction.NONE;
                        bot.GameServer.Rotate(info.Angle, VTankObject.Direction.NONE);
                        bot.InvokeOnCompletedRotation();
                    }
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Adjust a player's position according to his movement/rotation.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="deltaTimeSeconds"></param>
        private void MovePlayer(MetaPlayer player, double deltaTimeSeconds)
        {
            Player info = player.Player;
            if (info.MovementDirection != VTankObject.Direction.NONE)
            {
                double speed = (VELOCITY * info.SpeedFactor) * deltaTimeSeconds;
                if (info.MovementDirection == VTankObject.Direction.REVERSE)
                {
                    speed = -speed;
                }

                VTankObject.Point newPosition = new VTankObject.Point(
                    info.Position.x + Math.Cos(info.Angle) * speed,
                    info.Position.y + Math.Sin(info.Angle) * speed
                );

                if (!CheckCollision(newPosition))
                {
                    info.SetPosition(newPosition);
                }
                else
                {
                    info.MovementDirection = VTankObject.Direction.NONE;
                    if (info == LocalPlayer)
                    {
                        bot.GameServer.Move(info.Position.x, info.Position.y, VTankObject.Direction.NONE);
                        bot.InvokeOnHitWall();
                    }
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Test if two angles are approximately equal.
        /// </summary>
        /// <param name="a1">Angle 1.</param>
        /// <param name="a2">Angle 2.</param>
        /// <returns>True if the two angles are approximately equal.</returns>
        private static bool DoneRotating(MetaPlayer player, double deltaTimeInSeconds)
        {
            player.SecondsUntilAngle -= deltaTimeInSeconds;
            if (player.SecondsUntilAngle <= 0)
            {
                player.SecondsUntilAngle = 0;
                return true;
            }

            return false;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Check if the bot is finished moving.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="deltaTimeInSeconds"></param>
        /// <returns></returns>
        private static bool DoneMoving(MetaPlayer player, double deltaTimeInSeconds)
        {
            player.SecondsUntilGoal -= deltaTimeInSeconds;
            if (player.SecondsUntilGoal <= 0)
            {
                player.SecondsUntilGoal = 0;
                return true;
            }

            return false;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Start moving forward.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="pos"></param>
        private void StartMovingForward(MetaPlayer player, VTankObject.Point pos)
        {
            player.Player.MovementDirection = VTankObject.Direction.FORWARD;
            player.Player.Position = pos;

            bot.GameServer.Move(pos.x, pos.y, VTankObject.Direction.FORWARD);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Stop moving forward.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="pos"></param>
        private void StopMovingForward(MetaPlayer player, VTankObject.Point pos)
        {
            player.Player.Position = pos;

            //if (player.Player.MovementDirection != VTankObject.Direction.NONE)
            //{
                player.Player.MovementDirection = VTankObject.Direction.NONE;

                bot.GameServer.Move(pos.x, pos.y, VTankObject.Direction.NONE);
            //}
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Check if a player is in range of another player.
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public bool IsInRange(Player player)
        {
            MetaPlayer testPlayer = players[player.ID];

            return(testPlayer.Player.IsInRangeOf(player));
        }