Example #1
0
        private void SetMoveState(MoveState state)
        {
            m_moveState = state;
            //Log.DebugFmt("{0} setting move state {1}", Parent.FullName, state);

            switch (m_moveState)
            {
            case MoveState.Stopped:
                m_messenger.QueueMessage(new MoveMessage(MoveCommand.AllStop));
                break;

            case MoveState.Forward:
            case MoveState.ForwardCollision:
                m_messenger.QueueMessage(new MoveMessage(MoveCommand.TurnStop));
                m_messenger.QueueMessage(
                    new MoveMessage(MoveCommand.SpeedForwardFull));
                break;

            case MoveState.TurnLeft:
            case MoveState.TurnLeftCollision:
                m_messenger.QueueMessage(new MoveMessage(MoveCommand.TurnLeftFull));
                m_messenger.QueueMessage(
                    new MoveMessage(MoveCommand.SpeedStop));
                break;

            case MoveState.TurnRight:
            case MoveState.TurnRightCollision:
                m_messenger.QueueMessage(new MoveMessage(MoveCommand.TurnRightFull));
                m_messenger.QueueMessage(
                    new MoveMessage(MoveCommand.SpeedStop));
                break;
            }
        }
Example #2
0
        private bool HandleSensorCollision(Fixture fixtureA, Fixture fixtureB,
                                           Contact contact)
        {
            if ((fixtureB.CollisionCategories & PhysicsManager.TankCategory) > 0)
            {
                var id = Convert.ToUInt32(fixtureB.UserData);
                if (id != Parent.Id && !m_contacts.Contains(id))
                {
                    m_contacts.Add(id);
                    m_messenger.QueueMessage(new SensorNewContactMessage(id));
                }
            }

            return(true);
        }
        private void HandleTankHit(Event e)
        {
            var evt = (TankHitEvent)e;

            if (evt.Target != Parent.Id)
            {
                return;
            }

            m_messenger.QueueMessage(new TankHitMessage(evt.Shooter, evt.Damage));
            m_health -= evt.Damage;
            m_health  = Math.Max(m_health, 0f);

            if (HealthPercent <= 0f)
            {
                m_messenger.QueueMessage(new TankKilledMessage(evt.Shooter));
                m_eventManager.QueueEvent(new TankKilledEvent(Parent.Id, evt.Shooter));
            }
        }
Example #4
0
        private void HandleUserMove(Event e)
        {
            var         evt         = (UserMoveEvent)e;
            MoveCommand moveCommand = MoveCommand.AllStop;

            switch (evt.Direction)
            {
            case MoveDirection.Forward:
                moveCommand = evt.State == MoveState.Begin
            ? MoveCommand.SpeedForwardFull
            : MoveCommand.SpeedStop;
                break;

            case MoveDirection.Back:
                moveCommand = evt.State == MoveState.Begin
            ? MoveCommand.SpeedReverseFull
            : MoveCommand.SpeedStop;
                break;

            case MoveDirection.Left:
                moveCommand = evt.State == MoveState.Begin
            ? MoveCommand.TurnLeftFull
            : MoveCommand.TurnStop;
                break;

            case MoveDirection.Right:
                moveCommand = evt.State == MoveState.Begin
            ? MoveCommand.TurnRightFull
            : MoveCommand.TurnStop;
                break;
            }

            if (moveCommand != MoveCommand.AllStop)
            {
                m_messenger.QueueMessage(new MoveMessage(moveCommand));
            }
        }
        private void UpdateFiring(float deltaTime)
        {
            if (m_reloading)
            {
                m_reloadTime -= deltaTime;
                m_reloading   = m_reloadTime > 0f;
            }

            if (m_reloading || !m_firing || !m_targetAligned)
            {
                return;
            }

            m_targetDirection.Normalize();
            // find the end of the barrel where the bullet will originate
            var totalBarrelLen = (m_state.TurretWidth / 2f) +
                                 m_state.BarrelDimensions.X;
            var position = Parent.Transform.Position +
                           (m_targetDirection * totalBarrelLen);
            var velocity = m_targetDirection * m_state.GunSpeed;

            var bullet = BulletFactory.CreateBullet(Parent.Id, m_state.GunDamage,
                                                    position, velocity, m_state.BarrelDimensions.Y * 0.9f);

            if (bullet == null)
            {
                Log.ErrorFmt("{0} tried to fire a shot but failed", Parent.FullName);
            }
            else
            {
                m_messenger.QueueMessage(new ShotFiredMessage(bullet.Id));
            }

            m_reloading  = true;
            m_reloadTime = m_state.ReloadTime;
        }