public TurretSpinningEvent(VTankBot _game, int id, double angle, VTankObject.Direction direction)
     : base(_game)
 {
     this.id = id;
     this.angle = angle;
     this.direction = direction;
 }
Exemplo n.º 2
0
 public PlayerRotateEvent(GamePlayState _game, int id, double angle, VTankObject.Direction direction)
     : base(_game)
 {
     this.id        = id;
     this.angle     = angle;
     this.direction = direction;
 }
Exemplo n.º 3
0
 public PlayerMoveEvent(GamePlayState _game, int id, VTankObject.Point point,
                        VTankObject.Direction direction) : base(_game)
 {
     this.id        = id;
     this.direction = direction;
     this.point     = point;
 }
Exemplo 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);
        }
Exemplo n.º 5
0
 public TurretSpinningEvent(VTankBot _game, int id, double angle, VTankObject.Direction direction)
     : base(_game)
 {
     this.id        = id;
     this.angle     = angle;
     this.direction = direction;
 }
Exemplo n.º 6
0
 public PlayerRotateEvent(GamePlayState _game, int id, double angle, VTankObject.Direction direction)
     : base(_game)
 {
     this.id = id;
     this.angle = angle;
     this.direction = direction;
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Helper method for changing the rotation of the user. Does nothing if the given
 /// direction is not actually a change.
 /// </summary>
 /// <param name="direction">Direction that the tank is rotating towards.</param>
 /// <param name="force">If true, forces the movement packet.</param>
 private void ChangeRotation(VTankObject.Direction direction, bool force)
 {
     if (localPlayer.DirectionRotation != direction || force)
     {
         localPlayer.DirectionRotation = direction;
         ServiceManager.Theater.Rotate(localPlayer.Angle, direction);
     }
 }
Exemplo n.º 9
0
 public PlayerMoveEvent(VTankBot _game, int id, VTankObject.Point point,
     VTankObject.Direction direction)
     : base(_game)
 {
     this.id = id;
     this.direction = direction;
     this.point = point;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Helper method for changing the movement of the user. Does nothing if the given
 /// direction is not actually a change.
 /// </summary>
 /// <param name="direction">Direction that the tank is moving towards.</param>
 /// <param name="force">If set to true, forces a re-sync packet.</param>
 private void ChangeMovement(VTankObject.Direction direction, bool force)
 {
     if (localPlayer.DirectionMovement != direction || force)
     {
         localPlayer.DirectionMovement = direction;
         ServiceManager.Theater.Move(localPlayer.Position.X, localPlayer.Position.Y,
                                     direction);
     }
 }
Exemplo n.º 11
0
        public override void TurretSpinning(int id, double angle, VTankObject.Direction direction, Ice.Current current__)
        {
            if (!ReceivingMessages())
            {
                return;
            }

            buffer.Enqueue(new TurretSpinningEvent(Game, id, angle, direction));
        }
Exemplo n.º 12
0
        public override void PlayerMove(int id, VTankObject.Point point,
                                        VTankObject.Direction direction, Ice.Current current__)
        {
            if (!ReceivingMessages())
            {
                return;
            }

            buffer.Enqueue(new PlayerMoveEvent(Game, id, point, direction));
        }
Exemplo n.º 13
0
        public void InvokeOnPlayerMove(int playerID, VTankObject.Point position,
                                       VTankObject.Direction direction)
        {
            Player player = Game.GetPlayerByID(playerID);

            if (player != null)
            {
                Game.SetPlayerMovement(player, position, direction);
            }
        }
Exemplo n.º 14
0
        public void InvokeOnPlayerRotate(int playerID, double angle,
                                         VTankObject.Direction direction)
        {
            Player player = Game.GetPlayerByID(playerID);

            if (player != null)
            {
                Game.SetPlayerRotation(player, angle, direction);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Send a rotation packet to the game server. You must already be connected and
        /// authenticated with Theater for this to do anything.
        /// </summary>
        /// <param name="angle">Current angle (for sync).</param>
        /// <param name="direction">New rotation direction.</param>
        /// <exception cref="Network.Exception.InvalidValueException">
        /// Thrown if an invalid direction is passed.</exception>
        /// <exception cref="System.NullPointerException">Thrown if the
        /// session was never connected.</exception>
        public void Rotate(double angle, VTankObject.Direction direction)
        {
            if (direction == VTankObject.Direction.FORWARD ||
                direction == VTankObject.Direction.REVERSE)
            {
                // Direction is invalid.
                throw new InvalidValueException(direction.ToString() +
                                                " is an invalid value for rotation!");
            }

            sessionOneway.Rotate_async(new Rotate_Callback(
                                           new ActionFinished <NoReturnValue>(
                                               CommonExceptionHandler <NoReturnValue>)),
                                       Network.Util.Clock.GetTimeMilliseconds(), angle, direction);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Send a movement packet to the game server. You must already be connected and
        /// authenticated with Theater for this to do anything.
        /// </summary>
        /// <param name="x">X-position of the player (for sync).</param>
        /// <param name="y">Y-position of the player (for sync).</param>
        /// <param name="direction">New direction to move towards. The only valid directions
        /// are: NONE, FORWARD, REVERSE.</param>
        /// <exception cref="Network.Exception.InvalidValueException">
        /// Thrown if an invalid direction is passed.</exception>
        /// <exception cref="System.NullPointerException">Thrown if the
        /// session was never connected.</exception>
        public void Move(double x, double y, VTankObject.Direction direction)
        {
            if (direction == VTankObject.Direction.LEFT ||
                direction == VTankObject.Direction.RIGHT)
            {
                // Direction is invalid.
                throw new InvalidValueException(direction.ToString() +
                                                " is an invalid value for movement!");
            }

            sessionOneway.Move_async(
                new Move_Callback(new ActionFinished <NoReturnValue>(
                                      CommonExceptionHandler <NoReturnValue>)),
                Network.Util.Clock.GetTimeMilliseconds(), new VTankObject.Point(x, y),
                direction);
        }
Exemplo n.º 17
0
 public override void PlayerMove(int id, VTankObject.Point point,
                                 VTankObject.Direction direction, Ice.Current current__)
 {
     buffer.Push(new PlayerMoveEvent(bot, id, point, direction));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Helper method for changing the rotation of the user. Does nothing if the given
 /// direction is not actually a change.
 /// </summary>
 /// <param name="direction">Direction that the tank is rotating towards.</param>
 private void ChangeRotation(VTankObject.Direction direction)
 {
     ChangeRotation(direction, false);
 }
Exemplo n.º 19
0
 /// <summary>
 /// Helper method for changing the movement of the user. Does nothing if the given
 /// direction is not actually a change.
 /// </summary>
 /// <param name="direction">Direction that the tank is moving towards.</param>
 private void ChangeMovement(VTankObject.Direction direction)
 {
     ChangeMovement(direction, false);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Set a player's rotation data (who isn't the bot itself). This is done in a
 /// thread-safe way.
 /// </summary>
 /// <param name="player"></param>
 /// <param name="angle"></param>
 /// <param name="direction"></param>
 public void SetPlayerRotation(Player player, double angle,
                               VTankObject.Direction direction)
 {
     player.Angle             = angle;
     player.RotationDirection = direction;
 }
Exemplo n.º 21
0
 public override void TurretSpinning(int id, double angle,
                                     VTankObject.Direction direction, Ice.Current current__)
 {
     buffer.Push(new TurretSpinningEvent(bot, id, angle, direction));
 }
Exemplo n.º 22
0
 public override void PlayerRotate(int id, double angle,
                                   VTankObject.Direction direction, Ice.Current current__)
 {
     buffer.Push(new PlayerRotateEvent(bot, id, angle, direction));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Set a player's movement data (who isn't the bot itself). This is done in a
 /// thread-safe way.
 /// </summary>
 /// <param name="player"></param>
 /// <param name="position"></param>
 /// <param name="direction"></param>
 public void SetPlayerMovement(Player player, VTankObject.Point position,
                               VTankObject.Direction direction)
 {
     player.SetPosition(position);
     player.MovementDirection = direction;
 }