示例#1
0
        private static GamePadCapabilities PlatformGetCapabilities(int index)
        {
            GamePadCapabilities capabilities = new GamePadCapabilities();

            capabilities.IsConnected = (index == 0);
            capabilities.HasBackButton = true;

            return capabilities;
        }
		public void UpdateState()
		{
			this.caps = GamePad.GetCapabilities(this.deviceIndex);
			this.state = GamePad.GetState(this.deviceIndex);

			// If it's not a well-known gamepad, check the corresponding joystick whether there are any axes or buttons
			if (!this.caps.IsMapped)
			{
				JoystickCapabilities joystickCaps = Joystick.GetCapabilities(this.deviceIndex);
				this.hasAxesOrButtons = joystickCaps.AxisCount > 0 || joystickCaps.ButtonCount > 0 || joystickCaps.HatCount > 0;
			}
		}
示例#3
0
        public GamePadCapabilities GetCapabilities(int index)
        {
            JoystickCapabilities joy = Joystick.GetCapabilities(index);
            GamePadCapabilities pad;
            if (joy.IsConnected)
            {
                GamePadConfiguration configuration = GetConfiguration(Joystick.GetGuid(index));
                GamePadAxes mapped_axes = 0;
                Buttons mapped_buttons = 0;

                foreach (GamePadConfigurationItem map in configuration)
                {
                    switch (map.Target.Type)
                    {
                        case ConfigurationType.Axis:
                            mapped_axes |= map.Target.Axis;
                            break;

                        case ConfigurationType.Button:
                            mapped_buttons |= map.Target.Button;
                            break;
                    }
                }

                pad = new GamePadCapabilities(
                    GamePadType.GamePad, // Todo: detect different types
                    mapped_axes,
                    mapped_buttons,
                    joy.IsConnected,
                    configuration.Name != GamePadConfigurationDatabase.UnmappedName);
            }
            else
            {
                pad = new GamePadCapabilities();
            }
            return pad;
        }
 public void UpdateState()
 {
     this.caps = GamePad.GetCapabilities(this.deviceIndex);
     this.state = GamePad.GetState(this.deviceIndex);
 }
示例#5
0
 internal void Update()
 {
     PreviousState = State;
     State = OpenTK.Input.GamePad.GetState(DeviceID);
     Capabilities = OpenTK.Input.GamePad.GetCapabilities(DeviceID);
 }
示例#6
0
        private void ProcessGamePad(GamePadState gps, PlayerIndex player)
        {
            GamePadState lastState = new GamePadState();

            if (m_PriorGamePadState.ContainsKey(player))
            {
                lastState = m_PriorGamePadState[player];
                // Notify listeners when the gamepad is connected.
                if ((lastState.IsConnected != gps.IsConnected) && GamePadConnectionUpdate != null)
                {
                    GamePadConnectionUpdate(player, false);
                }
                // TODO: Check button pressed/released status for button tap events.
            }
            if (gps.IsConnected)
            {
                GamePadCapabilities caps = GamePad.GetCapabilities(player);
                if (GamePadButtonUpdate != null)
                {
                    CCGamePadButtonStatus back          = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus start         = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus system        = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus a             = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus b             = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus x             = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus y             = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus leftShoulder  = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus rightShoulder = CCGamePadButtonStatus.NotApplicable;
                    if (caps.HasBackButton)
                    {
                        back = (gps.Buttons.Back == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasStartButton)
                    {
                        start = (gps.Buttons.Start == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasBigButton)
                    {
                        system = (gps.Buttons.BigButton == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasAButton)
                    {
                        a = (gps.Buttons.A == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasBButton)
                    {
                        b = (gps.Buttons.B == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasXButton)
                    {
                        x = (gps.Buttons.X == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasYButton)
                    {
                        y = (gps.Buttons.Y == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasLeftShoulderButton)
                    {
                        leftShoulder = (gps.Buttons.LeftShoulder == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasRightShoulderButton)
                    {
                        rightShoulder = (gps.Buttons.RightShoulder == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    GamePadButtonUpdate(back, start, system, a, b, x, y, leftShoulder, rightShoulder, player);
                }
                // Process the game sticks
                if (GamePadStickUpdate != null && (caps.HasLeftXThumbStick || caps.HasLeftYThumbStick || caps.HasRightXThumbStick || caps.HasRightYThumbStick || caps.HasLeftStickButton || caps.HasRightStickButton))
                {
                    CCPoint vecLeft;
                    if (caps.HasLeftXThumbStick || caps.HasLeftYThumbStick)
                    {
                        vecLeft = new CCPoint(gps.ThumbSticks.Left);
                        vecLeft.Normalize();
                    }
                    else
                    {
                        vecLeft = CCPoint.Zero;
                    }
                    CCPoint vecRight;
                    if (caps.HasRightXThumbStick || caps.HasRightYThumbStick)
                    {
                        vecRight = new CCPoint(gps.ThumbSticks.Right);
                        vecRight.Normalize();
                    }
                    else
                    {
                        vecRight = CCPoint.Zero;
                    }
                    CCGameStickStatus left = new CCGameStickStatus();
                    left.Direction = vecLeft;
                    left.Magnitude = ((caps.HasLeftXThumbStick || caps.HasLeftYThumbStick) ? gps.ThumbSticks.Left.Length() : 0f);
                    left.IsDown    = ((caps.HasLeftStickButton) ? gps.IsButtonDown(Buttons.LeftStick) : false);
                    CCGameStickStatus right = new CCGameStickStatus();
                    right.Direction = vecRight;
                    right.Magnitude = ((caps.HasRightXThumbStick || caps.HasRightYThumbStick) ? gps.ThumbSticks.Right.Length() : 0f);
                    right.IsDown    = ((caps.HasLeftStickButton) ? gps.IsButtonDown(Buttons.RightStick) : false);
                    GamePadStickUpdate(left, right, player);
                }
                // Process the game triggers
                if (GamePadTriggerUpdate != null && (caps.HasLeftTrigger || caps.HasRightTrigger))
                {
                    GamePadTriggerUpdate(caps.HasLeftTrigger ? gps.Triggers.Left : 0f, caps.HasRightTrigger ? gps.Triggers.Right : 0f, player);
                }
                // Process the D-Pad
                if (GamePadDPadUpdate != null)
                {
                    CCGamePadButtonStatus left  = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus right = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus up    = CCGamePadButtonStatus.NotApplicable;
                    CCGamePadButtonStatus down  = CCGamePadButtonStatus.NotApplicable;
                    if (caps.HasDPadDownButton)
                    {
                        down = (gps.DPad.Down == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadUpButton)
                    {
                        up = (gps.DPad.Up == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadLeftButton)
                    {
                        left = (gps.DPad.Left == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadRightButton)
                    {
                        right = (gps.DPad.Right == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    GamePadDPadUpdate(left, up, right, down, player);
                }
            }
            m_PriorGamePadState[player] = gps;
        }
示例#7
0
        protected ActionSet GetActions()
        {
            InputState inputs = new InputState();

            // Mouse
            if (Mouse.GetState() != null)
            {
                inputs.axisInputs.Add(new Tuple <InputState.AxisInputs, Vector2>(
                                          InputState.AxisInputs.Mouse,
                                          new Vector2(Mouse.GetState().X, Mouse.GetState().Y)));
            }

            // Keyboard
            if (Keyboard.GetState() != null)
            {
                KeyboardState state = Keyboard.GetState();

                inputs.KeyboardKeys.AddRange(state.GetPressedKeys());
            }

            // Gamepad
            GamePadCapabilities gCap = GamePad.GetCapabilities(playerIndex);

            if (gCap.IsConnected)
            {
                GamePadState state = GamePad.GetState(playerIndex);

                // Thumbsticks
                if (gCap.HasLeftXThumbStick && gCap.HasLeftYThumbStick)
                {
                    inputs.axisInputs.Add(new Tuple <InputState.AxisInputs, Vector2>(
                                              InputState.AxisInputs.ThumbstickLeft,
                                              new Vector2(state.ThumbSticks.Left.X, state.ThumbSticks.Left.Y)));
                }

                if (gCap.HasRightXThumbStick && gCap.HasRightYThumbStick)
                {
                    inputs.axisInputs.Add(new Tuple <InputState.AxisInputs, Vector2>(
                                              InputState.AxisInputs.ThumbstickRight,
                                              new Vector2(state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y)));
                }

                // Buttons
                if (gCap.HasAButton)
                {
                    if (state.IsButtonDown(Buttons.A))
                    {
                        inputs.ButtonsDown.Add(Buttons.A);
                    }
                }

                if (gCap.HasBButton)
                {
                    if (state.IsButtonDown(Buttons.B) && oldGamePadState.IsButtonUp(Buttons.B))
                    {
                        inputs.ButtonsDown.Add(Buttons.B);
                    }
                }

                if (gCap.HasXButton)
                {
                    if (state.IsButtonDown(Buttons.X) && oldGamePadState.IsButtonUp(Buttons.X))
                    {
                        inputs.ButtonsDown.Add(Buttons.X);
                    }
                }

                if (gCap.HasYButton)
                {
                    if (state.IsButtonDown(Buttons.Y))
                    {
                        inputs.ButtonsDown.Add(Buttons.Y);
                    }
                }

                if (gCap.HasLeftShoulderButton)
                {
                    if (state.IsButtonDown(Buttons.LeftShoulder))
                    {
                        inputs.ButtonsDown.Add(Buttons.LeftShoulder);
                    }
                }

                if (gCap.HasRightShoulderButton)
                {
                    if (state.IsButtonDown(Buttons.RightShoulder))
                    {
                        inputs.ButtonsDown.Add(Buttons.RightShoulder);
                    }
                }

                if (gCap.HasLeftTrigger)
                {
                    if (state.IsButtonDown(Buttons.LeftTrigger))
                    {
                        inputs.ButtonsDown.Add(Buttons.LeftTrigger);
                    }
                }

                if (gCap.HasRightTrigger)
                {
                    if (state.IsButtonDown(Buttons.RightTrigger))
                    {
                        inputs.ButtonsDown.Add(Buttons.RightTrigger);
                    }
                }

                // Menu Buttons
                if (gCap.HasStartButton)
                {
                    if (state.IsButtonDown(Buttons.Start) && oldGamePadState.IsButtonUp(Buttons.Start))
                    {
                        inputs.ButtonsDown.Add(Buttons.Start);
                    }
                }

                if (gCap.HasBackButton)
                {
                    if (state.IsButtonDown(Buttons.Back))
                    {
                        inputs.ButtonsDown.Add(Buttons.Back);
                    }
                }

                if (gCap.HasBigButton)
                {
                    if (state.IsButtonDown(Buttons.BigButton))
                    {
                        inputs.ButtonsDown.Add(Buttons.BigButton);
                    }
                }

                oldGamePadState = state;
            }

            CurrentActions = inputMapper.MapInputs(inputs);
            return(new ActionSet(CurrentActions));
        }
示例#8
0
        public Tank(Game1 game, Model m, Vector3 position, Keys[] Controls, int id, Model Shot, bool ai, PlayerIndex pad, float initialYaw)
        {
            this.game      = game;
            myModel        = m;
            this.shotModel = Shot;
            this.id        = id;
            world          = Matrix.Identity;

            this.Controls = Controls;
            this.pad      = pad;

            dirDefault       = new Vector3(0f, 0f, -1f); //default direction
            yaw              = initialYaw;
            rotation         = Matrix.CreateFromYawPitchRoll(yaw, 0f, 0f);
            defaultDirection = Vector3.Transform(dirDefault, rotation);
            direction        = Vector3.Transform(dirDefault, rotation);
            this.position    = position;

            terrainNormal = game.map.getNormal(position.X, position.Z); //current position's terrain normal
            right         = Vector3.Cross(direction, terrainNormal);    //tank's Right
            trueDirection = Vector3.Cross(right, terrainNormal);        //Direction which the tank faces when he is in the terrain
            trueDirection.Normalize();

            scale             = 0.005f; //Model's SCalling
            speed             = 5f;     //Tank's default Speed
            velocity          = Vector3.Zero;
            blockingDirection = Vector3.Zero;

            moving = false;

            #region Bones Creation
            //Bones Variables Creation
            turretBone     = myModel.Bones["turret_geo"];
            cannonBone     = myModel.Bones["canon_geo"];
            rightWheel     = myModel.Bones["r_front_wheel_geo"];
            leftWheel      = myModel.Bones["l_front_wheel_geo"];
            rightBackWheel = myModel.Bones["r_back_wheel_geo"];
            leftBackWheel  = myModel.Bones["l_back_wheel_geo"];
            hatch          = myModel.Bones["hatch_geo"];
            #endregion

            #region Bones Transforms
            //bones Transforms
            turretTransform         = turretBone.Transform;
            cannonTransform         = cannonBone.Transform;
            rightWheelTransform     = rightWheel.Transform;
            leftWheelTransform      = leftWheel.Transform;
            rightBackWheelTransform = rightBackWheel.Transform;
            leftBackWheelTransform  = leftBackWheel.Transform;
            hatchTransform          = hatch.Transform;
            #endregion

            boneTransform = new Matrix[myModel.Bones.Count];
            rotacao       = Matrix.Identity;

            #region bone Angles
            //Bone Angles
            turretAngle         = 0f;
            cannonAngle         = 0f;
            rightWheelAngle     = 0f;
            leftWheelAngle      = 0f;
            rightBackWheelAngle = 0f;
            leftBackWheelAngle  = 0f;
            hatchAngle          = 0f;
            #endregion

            turretRotation  = Matrix.CreateFromYawPitchRoll(turretAngle, 0f, 0f); //turret's rotation matrix
            turretDirection = Vector3.Transform(dirDefault, turretRotation);      //turret's direction for third person camera purposes

            //COLISION
            collider = new Sphere(position, 2f);   //Radius is fine tuned
            game.colliders.Add(this as ICollider); //add the tank to the collider list
            Tankcoliding = false;
            Hit          = false;
            hittime      = 0;

            reloading   = false;
            reloadTimer = 0;

            capabilities     = GamePad.GetCapabilities(pad); //controller capabilities check
            gamepad          = GamePad.GetState(pad);        //controller
            kbPreviousState  = Keyboard.GetState();          //THIS SAVES THE PREVIOUS KEYBOARD STATE SO THAT SINGLE BUTTON PRESSES ARE POSSIBLE
            padPreviousState = gamepad;                      //THIS SAVES THE PREVIOUS GAMEPAD STATE SO THAT SINGLE BUTTON PRESSES ARE POSSIBLE
            keyboard         = true;

            dustEmitters = new DustLineEmitter[4];
            Color dustColor = Color.SandyBrown;
            dustEmitters[0] = new DustLineEmitter(game, boneTransform[rightWheel.Index].Translation, rotation.Left, 0.8f, Vector3.Forward, 10, dustColor, Vector3.Cross(rotation.Backward, rotation.Up));
            dustEmitters[1] = new DustLineEmitter(game, boneTransform[leftWheel.Index].Translation, rotation.Right, 0.8f, Vector3.Forward, 10, dustColor, Vector3.Cross(rotation.Backward, rotation.Up));
            dustEmitters[2] = new DustLineEmitter(game, boneTransform[rightBackWheel.Index].Translation, rotation.Right, 1f, Vector3.Forward, 10, dustColor, Vector3.Cross(rotation.Backward, rotation.Up));
            dustEmitters[3] = new DustLineEmitter(game, boneTransform[leftBackWheel.Index].Translation, rotation.Left, 1f, Vector3.Forward, 10, dustColor, Vector3.Cross(rotation.Backward, rotation.Up));

            AIControlled   = ai;
            idleTimer      = 0;
            radar          = new BoidRadar(game, this);
            IdealDirection = direction;
            aiMode         = AImode.WANDER;

            Health = 100;
            alive  = true;

            //Lights
            #region Lighting
            foreach (ModelMesh mesh in myModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.LightingEnabled           = true;
                    effect.DirectionalLight0.Enabled = true;
                    effect.DiffuseColor      = game.LightManager.diffuseColor;                                //kd
                    effect.SpecularColor     = game.LightManager.specularColor;                               //Specular Light  //ks
                    effect.SpecularPower     = game.LightManager.specularPower;                               //Power of Specular Light //s
                    effect.AmbientLightColor = game.LightManager.ambientLightColor;                           //Ia
                    effect.DirectionalLight0.DiffuseColor  = game.LightManager.directionalLightDiffuseColor;  //Directional Light's Color //Id
                    effect.DirectionalLight0.Direction     = game.LightManager.directionalLightDirection;     //Directional light's Direction
                    effect.DirectionalLight0.SpecularColor = game.LightManager.directionalLightSpecularColor; //Is
                }
            }
            #endregion
        }
示例#9
0
        public void Update(GameTime gt, KeyboardState kb, MouseState ms)
        {
            if (!AIControlled)
            {
                idleTimer += (float)gt.ElapsedGameTime.TotalSeconds;
                if (idleTimer > 30)
                {
                    AIControlled = true;
                }
            }
            else
            {
                idleTimer = 0f;
            }
            velocity = Vector3.Zero;

            capabilities = GamePad.GetCapabilities(pad); //controller capabilities check
            gamepad      = GamePad.GetState(pad);        //controller

            //---------------------------------------------Player Controlled Movement-----------------------------//

            //KEYBOARD
            #region KeyBoard Controls
            #region Tank Rotation
            if (kb.IsKeyDown(Controls[2])) //Rotate Left
            {
                yaw += MathHelper.ToRadians(2);
                Animate_Wheels_Left(gt);
                AIControlOff();
                keyboard = true;
            }
            if (kb.IsKeyDown(Controls[3])) //Rotate Right
            {
                yaw -= MathHelper.ToRadians(2);
                Animate_Wheels_Right(gt);
                AIControlOff();
                keyboard = true;
            }

            #endregion

            #region Movement Forward and Backwards
            //Move Forward
            if (kb.IsKeyDown(Controls[0]))
            {
                velocity -= (((direction - blockingDirection) * speed) * (float)gt.ElapsedGameTime.TotalSeconds);

                moving = true;
                Animate_Wheels_ForWard(gt);
                AIControlOff();
                keyboard = true;
            }
            //move BackWards
            else if (kb.IsKeyDown(Controls[1]))
            {
                velocity += (((direction + blockingDirection) * speed) * (float)gt.ElapsedGameTime.TotalSeconds);

                moving = true;
                Animate_Wheels_BackWards(gt);
                AIControlOff();
                keyboard = true;
            }
            #endregion

            #region turret Movement
            //Turret Movement
            if (kb.IsKeyDown(Controls[6])) //Move turret Right
            {
                turretAngle += 1f * (float)gt.ElapsedGameTime.TotalSeconds;
                AIControlOff();
                keyboard = true;
            }
            if (kb.IsKeyDown(Controls[7])) //more turret Left
            {
                turretAngle -= 1f * (float)gt.ElapsedGameTime.TotalSeconds;
                AIControlOff();
                keyboard = true;
            }
            if (kb.IsKeyDown(Controls[4]) && cannonAngle > -0.75f) //Move cannon Up
            {
                cannonAngle -= 1f * (float)gt.ElapsedGameTime.TotalSeconds;
                AIControlOff();
                keyboard = true;
            }
            if (kb.IsKeyDown(Controls[5]) && cannonAngle < 0.3f) //move cannon Down
            {
                cannonAngle += 1f * (float)gt.ElapsedGameTime.TotalSeconds;
                AIControlOff();
                keyboard = true;
            }
            #endregion

            #endregion
            ///KEYBOARD

            //XBOX CONTROLLER
            #region controllerControls
            if (capabilities.GamePadType == GamePadType.GamePad)
            {
                #region tank rotation
                if (!keyboard && gamepad.ThumbSticks.Left.X < -0.5f) //Rotate Left
                {
                    yaw += MathHelper.ToRadians(2);
                    Animate_Wheels_Left(gt);
                    AIControlOff();
                }
                if (!keyboard && gamepad.ThumbSticks.Left.X > 0.5f) //Rotate Right
                {
                    yaw -= MathHelper.ToRadians(2);
                    Animate_Wheels_Right(gt);
                    AIControlOff();
                }


                #endregion

                #region Movement Forward and Backwards
                //Move Forward
                if (!keyboard && gamepad.ThumbSticks.Left.Y > 0.5f)
                {
                    velocity -= (((direction - blockingDirection) * speed) * (float)gt.ElapsedGameTime.TotalSeconds);

                    moving = true;
                    Animate_Wheels_ForWard(gt);
                    AIControlOff();
                }
                //move BackWards
                else if (!keyboard && gamepad.ThumbSticks.Left.Y < -0.5f)
                {
                    velocity += (((direction + blockingDirection) * speed) * (float)gt.ElapsedGameTime.TotalSeconds);

                    moving = true;
                    Animate_Wheels_BackWards(gt);
                    AIControlOff();
                }
                #endregion

                #region turret Movement
                //Turret Movement
                if (!keyboard && gamepad.ThumbSticks.Right.X < -0.5f) //Move turret Right
                {
                    turretAngle += 1f * (float)gt.ElapsedGameTime.TotalSeconds;
                    AIControlOff();
                }
                if (!keyboard && gamepad.ThumbSticks.Right.X > 0.5f) //more turret Left
                {
                    turretAngle -= 1f * (float)gt.ElapsedGameTime.TotalSeconds;
                    AIControlOff();
                }
                if (!keyboard && gamepad.ThumbSticks.Right.Y > 0.5f && cannonAngle > -0.75f) //Move cannon Up
                {
                    cannonAngle -= 1f * (float)gt.ElapsedGameTime.TotalSeconds;
                    AIControlOff();
                }
                if (!keyboard && gamepad.ThumbSticks.Right.Y < -0.5f && cannonAngle < 0.3f) //move cannon Down
                {
                    cannonAngle += 1f * (float)gt.ElapsedGameTime.TotalSeconds;
                    AIControlOff();
                }
                #endregion
            }
            #endregion
            ///XBOX CONTROLLER

            if (!AIControlled)
            {
                rotation  = Matrix.CreateFromYawPitchRoll(yaw, 0f, 0f);
                direction = Vector3.Transform(dirDefault, rotation); //tank's 2d Direction
                direction.Normalize();
            }

            //---------------------------------------------END PLAYER CONTROLLED MOMENT--------------------------//

            //-------------------------------------------AI Controlled Movement--------------------------------// (float)Math.Cos(angleDiference)
            #region AI
            if (AIControlled)
            {
                switch (aiMode)
                {
                case AImode.WANDER:
                    float angleDiference = Vector3.Dot(direction, radar.newDirection);                              //Angle Dirference between the old direction and the new

                    yaw += (float)Math.Cos(angleDiference) * radar.newDir * (float)gt.ElapsedGameTime.TotalSeconds; //adds the new direciton to the old

                    rotation  = Matrix.CreateFromYawPitchRoll(yaw, 0f, 0f);
                    direction = Vector3.Transform(dirDefault, rotation);     //tank's 2d Direction
                    direction.Normalize();

                    Vector3 AIdirection = direction - blockingDirection;

                    velocity -= ((AIdirection * speed) * (float)gt.ElapsedGameTime.TotalSeconds);
                    moving    = true;

                    Animate_Wheels_ForWard(gt);
                    break;

                case AImode.PERSUIT:


                    break;
                }
            }


            #endregion
            //-----------------------------------END AI CONTROLED MOVEMENT------------------------------------------//

            Vector3 nextPos = position + velocity;  //Position in which the tank might be next frame if the player moves it
            //velocity += blockingDirection * (float)gt.ElapsedGameTime.TotalSeconds; //this makes the tanks push each others
            if (nextPos.X < game.map.size.X - 1 && nextPos.X - 1 > 0 && nextPos.Z < game.map.size.Y - 1 && nextPos.Z - 1 > 0)
            {
                position += velocity;
            }
            collider.Center = position; //Colider Update

            radar.update(gt);

            terrainNormal = game.map.getNormal(position.X, position.Z); //Current position's terrain normal

            if (!AIControlled)
            {
                formatDirection(direction, terrainNormal); //tank's rotation function
            }
            else
            {
                formatDirection(direction, terrainNormal); //tank's rotation function
            }

            position.Y = game.map.getHeight(position.X, position.Z); //tank's Height

            Matrix translacao = Matrix.CreateTranslation(position);
            Matrix escala     = Matrix.CreateScale(scale);
            myModel.Root.Transform = escala * rotacao * translacao;



            //TURRET DIRECTION FOR CAMERA PUPOSES
            turretRotation  = Matrix.CreateFromYawPitchRoll(turretAngle, 0f, 0f);
            turretDirection = Vector3.Transform(direction, turretRotation);
            turretDirection.Normalize();

            #region BONE TRANSFORMS
            //BONE TRANSFORMS
            turretBone.Transform     = Matrix.CreateRotationY(turretAngle) * turretTransform;
            cannonBone.Transform     = Matrix.CreateRotationX(cannonAngle) * cannonTransform;
            rightWheel.Transform     = Matrix.CreateRotationX(rightWheelAngle) * rightWheelTransform;
            leftWheel.Transform      = Matrix.CreateRotationX(leftWheelAngle) * leftWheelTransform;
            rightBackWheel.Transform = Matrix.CreateRotationX(rightBackWheelAngle) * rightBackWheelTransform;
            leftBackWheel.Transform  = Matrix.CreateRotationX(leftBackWheelAngle) * leftBackWheelTransform;
            hatch.Transform          = Matrix.CreateRotationX(hatchAngle) * hatchTransform;

            myModel.CopyAbsoluteBoneTransformsTo(boneTransform);
            #endregion

            //GUN DIRECTION FOR SHOOTING PURPOSES
            GunDirection = boneTransform[cannonBone.Index].Forward;
            GunDirection.Normalize();



            //-----------------------------------SHOOTING LOGIC-----------------------------//
            if (reloading)
            {
                reloadTimer += (float)gt.ElapsedGameTime.TotalSeconds;
                if (reloadTimer >= 1f)
                {
                    reloading = false; reloadTimer = 0;
                }
            }

            //-------------------------------------------------KEYBOARD CONTROLS-----------------------------//
            if (!reloading && !kbPreviousState.IsKeyDown(Controls[8]) && kb.IsKeyDown(Controls[8])) //SHOOTING CONTROLS
            {
                Shoot();
                AIControlOff();
                keyboard = true;
            }
            ///---------------------------------------------END KEYBOARD CONTROLS----------------------------//

            //-----------------------------------------XBOX PAD CONTROLS----------------------------------//
            if (!keyboard && capabilities.GamePadType == GamePadType.GamePad)
            {
                if (!reloading && !padPreviousState.IsButtonDown(Buttons.RightTrigger) && gamepad.IsButtonDown(Buttons.RightTrigger))
                {
                    Shoot();
                    AIControlOff();
                }
            }
            ///---------------------------------------END XBOX PAD CONTROLS-----------------------------------//

            if (hatchAngle < 0) //close Hatch
            {
                hatchAngle += 1f * (float)gt.ElapsedGameTime.TotalSeconds;
            }

            if (Hit)
            {
                hittime += (float)gt.ElapsedGameTime.TotalSeconds;
            }
            if (hittime > 0.3f)
            {
                hittime = 0; Hit = false;
            }
            ///-------------------------------------END SHOOOTING---------------------------//

            //DUST EMMITER
            dustEmitters[0].Update(gt, boneTransform[rightWheel.Index].Translation, rotation.Left, Vector3.Cross(direction, rotation.Up), rotation.Down * 0.25f, moving);
            dustEmitters[1].Update(gt, boneTransform[leftWheel.Index].Translation, rotation.Right, Vector3.Cross(direction, rotation.Up), rotation.Down * 0.25f, moving);
            dustEmitters[2].Update(gt, boneTransform[rightBackWheel.Index].Translation, rotation.Right, Vector3.Cross(direction, rotation.Up), rotation.Down * 0.45f, moving);
            dustEmitters[3].Update(gt, boneTransform[leftBackWheel.Index].Translation, rotation.Left, Vector3.Cross(direction, rotation.Up), rotation.Down * 0.45f, moving);
            ///DUST EMMITERS

            Tankcoliding = false;
            moving       = false;

            blockingDirection = Vector3.Zero;

            kbPreviousState  = kb;      //Keyboard state This frame
            padPreviousState = gamepad; //padState this frame
            keyboard         = false;

            if (!alive)
            {
                Respawn();
            }
        }
示例#10
0
 internal void Update()
 {
     PreviousState = State;
     State         = OpenTK.Input.GamePad.GetState(DeviceID);
     Capabilities  = OpenTK.Input.GamePad.GetCapabilities(DeviceID);
 }
示例#11
0
 public PadKeys()
 {
     c = G.c;
     s = G.pad;
 }
示例#12
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // TODO: Add your update logic here
            capabilities = GamePad.GetCapabilities(PlayerIndex.One);
            cap          = capabilities.IsConnected;



            GamePadState s = GamePad.GetState(PlayerIndex.One);

            if ((Keyboard.GetState().IsKeyDown(Keys.P) || s.Buttons.Start == ButtonState.Pressed) && pausetimer == 0)
            {
                paused     = !paused;
                pausetimer = 20;
            }
            if (pausetimer > 0)
            {
                pausetimer--;
            }
            if (paused)
            {
                if (cap)
                {
                    screen = controller;
                }
                else
                {
                    screen = keyboard;
                }
            }
            else
            {
                if (state == 0)
                {
                    screen = start;
                    if (Keyboard.GetState().IsKeyDown(Keys.Space) || s.Buttons.A == ButtonState.Pressed)
                    {
                        state            = 1;
                        cube.bullettimer = 15;
                        startmusic.Stop();
                        select.Play();
                    }
                }

                else if (state == 1)
                {
                    if (select.State == SoundState.Stopped && world.State == SoundState.Stopped)
                    {
                        world.Play();
                    }
                    List <Enemy> enemies = levelenemies.ElementAt <List <Enemy> >(level);
                    cube.update(Content, cap);

                    if (cube.health == 0)
                    {
                        state  = 3;
                        screen = lose;
                    }
                    if (cube.position.X < -47)
                    {
                        cube.position.X = -47;
                        cube.speed      = Vector3.Zero;
                    }
                    if (cube.position.X > 47)
                    {
                        cube.position.X = 47;
                        cube.speed      = Vector3.Zero;
                    }
                    if (cube.position.Z < -47)
                    {
                        cube.position.Z = -47;
                        cube.speed      = Vector3.Zero;
                    }
                    if (cube.position.Z > 47)
                    {
                        cube.position.Z = 47;
                        cube.speed      = Vector3.Zero;
                    }

                    for (int i = 0; i < enemies.Count; i++)
                    {
                        Enemy e = enemies.ElementAt <Enemy>(i);
                        e.update();
                        if (e.health == 0)
                        {
                            enemies.Remove(e);
                        }
                        if (Math.Sqrt(Math.Pow(e.position.X - cube.position.X, 2) + Math.Pow(e.position.Z - cube.position.Z, 2)) <= enemyrange)
                        {
                            e.Shoot(cube.position, Content);
                        }
                    }
                    for (int i = 0; i < enemies.Count; i++)
                    {
                        Enemy e = enemies.ElementAt <Enemy>(i);
                        for (int j = 0; j < e.bullets.Count; j++)
                        {
                            Bullet b = e.bullets.ElementAt <Bullet>(j);
                            if (b.boundingsphere.Intersects(cube.boundingbox))
                            {
                                cube.health--;
                                e.bullets.Remove(b);
                            }
                        }
                    }
                    floor.update();
                    if (cube.bullets.Count > 0)
                    {
                        for (int i = 0; i < cube.bullets.Count; i++)
                        {
                            Bullet b = cube.bullets.ElementAt <Bullet>(i);
                            for (int j = 0; j < enemies.Count; j++)
                            {
                                Enemy e = enemies.ElementAt <Enemy>(j);
                                if (b.boundingsphere.Intersects(e.boundingbox))
                                {
                                    e.health -= 1;
                                    cube.bullets.Remove(b);
                                }
                            }
                        }
                        for (int i = 0; i < cube.bullets.Count; i++)
                        {
                            Bullet b = cube.bullets.ElementAt <Bullet>(i);

                            if ((b.position.X < -48 || b.position.X > 48) && b.ricochet > 0)
                            {
                                b.speed.X = -b.speed.X;
                                b.ricochet--;
                            }
                            else if (b.position.X < -48 || b.position.X > 48)
                            {
                                cube.bullets.Remove(b);
                            }
                            if ((b.position.Z < -48 || b.position.Z > 48) && b.ricochet > 0)
                            {
                                b.speed.Z = -b.speed.Z;
                                b.ricochet--;
                            }
                            else if (b.position.Z < -48 || b.position.Z > 48)
                            {
                                cube.bullets.Remove(b);
                            }
                        }
                    }
                    if (enemies.Count == 0)
                    {
                        if (level < 2)
                        {
                            level++;
                            cube.position  = originalcubepos;
                            cube.direction = Vector3.Forward;
                            cube.initialize(GraphicsDevice);
                            cube.update();

                            state  = 4f;
                            screen = nextlevel;
                            //levelseconds = 3;
                            world.Pause();
                        }
                        else
                        {
                            state  = 2;
                            screen = win;
                            world.Stop();
                        }
                    }
                    leveltimer++;
                }



                else if (state == 4)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Space) || s.Buttons.A == ButtonState.Pressed)
                    {
                        state            = 1;
                        cube.bullettimer = 15;
                        world.Resume();
                    }
                }
                else if (state == 2 || state == 3)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.E) || s.Buttons.A == ButtonState.Pressed)
                    {
                        this.Exit();
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.R))
                    {
                        screen = start;
                        //state = 0;
                        this.Initialize();
                        startmusic.Play();
                        //cube.position = originalcubepos;
                        //cube.update();
                        //m.position = Vector3.Zero;
                        //m.update();
                    }
                }
            }
            if (Keyboard.GetState().IsKeyDown(Keys.E) || s.Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            base.Update(gameTime);
        }
示例#13
0
 protected override void OnUpdate(GameTime gameTime)
 {
     _gamePadCapabilities = GamePad.GetCapabilities(PlayerIndex);
 }