Esempio n. 1
0
        public RobotCore(string name, int squadNumber, int team)
        {
            robotHostMessageExchange = new MessageExchangeFromRobotEventArgs();

            this.name        = name;
            this.SquadNumber = squadNumber;
            this.Team        = team;
        }
Esempio n. 2
0
        public object Clone()
        {
            MessageExchangeFromRobotEventArgs exchange = new MessageExchangeFromRobotEventArgs();

            exchange.FireProjectile = FireProjectile;
            exchange.PrintMessage   = PrintMessage;
            exchange.DebugMessage   = DebugMessage;
            exchange.TeamMessage    = TeamMessage;
            return(exchange);
        }
Esempio n. 3
0
        public MessageExchangeFromRobotEventArgs Update(double deltaTime)
        {
            // Normalize rotations
            while (Rotation > Math.PI)
            {
                Rotation -= TwoPI;
            }
            while (Rotation < -Math.PI)
            {
                Rotation += TwoPI;
            }
            while (RotationGun > Math.PI)
            {
                RotationGun -= TwoPI;
            }
            while (RotationGun < -Math.PI)
            {
                RotationGun += TwoPI;
            }
            while (RotationRadar > Math.PI)
            {
                RotationRadar -= TwoPI;
            }
            while (RotationRadar < -Math.PI)
            {
                RotationRadar += TwoPI;
            }

            // Rotate body
            double rotationdeg = robotRotateSpeed * deltaTime;

            if (RemainingRotation < 0)
            {
                rotationdeg *= -1.0f;                 // Rotate right
            }
            if (Math.Abs(RemainingRotation) - rotationdeg <= 0)
            {
                rotationdeg = RemainingRotation;
            }
            Rotation          += rotationdeg;
            RemainingRotation -= rotationdeg;

            // Rotate gun
            double rotationdegGun = robotRotateGunSpeed * deltaTime;

            if (RemainingRotationGun < 0)
            {
                rotationdegGun *= -1.0f;                 // Rotate right
            }
            if (Math.Abs(RemainingRotationGun) - rotationdegGun <= 0)
            {
                rotationdegGun = RemainingRotationGun;
            }
            RotationGun          += rotationdegGun;
            RemainingRotationGun -= rotationdegGun;

            // Rotate radar
            double rotationdegRadar = robotRotateRadarSpeed * deltaTime;

            if (RemainingRotationRadar < 0)
            {
                rotationdegRadar *= -1.0f;                 // Rotate right
            }
            if (Math.Abs(RemainingRotationRadar) - rotationdegRadar <= 0)
            {
                rotationdegRadar = RemainingRotationRadar;
            }
            RotationRadar          += rotationdegRadar;
            RemainingRotationRadar -= rotationdegRadar;

            // Store last position
            lastPositionX = PositionX;
            lastPositionY = PositionY;
            // Move robot
            double movedistance = robotMoveSpeed * deltaTime;

            if (RemainingDistance < 0)
            {
                movedistance *= -1.0f;                 // Move Backwards
            }
            if (Math.Abs(RemainingDistance) - movedistance <= 0)
            {
                movedistance = RemainingDistance;
            }
            PositionX         += movedistance * Math.Cos(Rotation);
            PositionY         += movedistance * Math.Sin(Rotation);
            RemainingDistance -= movedistance;

            // Cool down gun
            if ((DateTime.Now - coolDownTimer).TotalSeconds > 1)
            {
                Heat--;
                if (Heat < 0)
                {
                    Heat = 0;
                }
                coolDownTimer = DateTime.Now;
            }

            // Notify host about changes
            MessageExchangeFromRobotEventArgs retval = (MessageExchangeFromRobotEventArgs)robotHostMessageExchange.Clone();

            robotHostMessageExchange = new MessageExchangeFromRobotEventArgs();
            return(retval);
        }