Exemplo n.º 1
0
		protected void OnGamePadStickUpdate(CCGameStickStatus leftStick, CCGameStickStatus rightStick, PlayerIndex player)
		{
			if (player == PlayerIndex.One)
			{
				_StickPull = leftStick.Magnitude;
				_StickDir = leftStick.Direction;
				// Do the rubber band
				CCPoint pt = CCPoint.Zero;
				pt.X = slingShotCenterPosition.X + _StickDir.X * _StickPull * maxStretchOfSlingShot;
				pt.Y = slingShotCenterPosition.Y + _StickDir.Y * _StickPull * maxStretchOfSlingShot;
				if (CockTheSlingshot(pt))
				{
					_SlingshotIsCocked = true;
				}
				else
				{
					if (rightStick.Magnitude > 0f)
					{
						PanTheScreen((int)(rightStick.Magnitude * 25));
					}
				}
			}
			else
			{
				// base.OnGamePadStickUpdate(leftStick, rightStick, player);
			}
		}
Exemplo n.º 2
0
        private void MyOnGameStickUpdate(CCGameStickStatus left, CCGameStickStatus right, PlayerIndex player)
        {
            CCNode node = GetChildByTag(kTagTileMap);
            if (node != null)
            {
                CCParallaxNode map = (CCParallaxNode)node;
                if (left.Magnitude > 0f)
                {
                    // use the left stick to move the map
                    CCPoint diff = left.Direction.InvertY * left.Magnitude * 10f;
                    CCPoint currentPos = node.Position;
                    node.Position = currentPos + diff;
                }
                if (right.Magnitude > 0f)
                {
                    float scale = (1f - right.Direction.Y * right.Magnitude);
                    node.ScaleX += scale;
                    node.ScaleY += scale;
                    if (node.ScaleX < 1f)
                    {
                        node.ScaleX = 1f;
                    }

                    if (node.ScaleY < 1f) 
                    {
                        node.ScaleY = 1f;
                    }
                }
            }
        }
Exemplo n.º 3
0
        void ProcessGamePad(CCWindow window, GamePadState gps, PlayerIndex player)
        {
            var dispatcher = window.EventDispatcher;

            var lastState = new GamePadState();

            if (!priorGamePadState.ContainsKey(player) && gps.IsConnected)
            {
                gamePadConnection.IsConnected = true;
                gamePadConnection.Player = (CCPlayerIndex)player;
                dispatcher.DispatchEvent(gamePadConnection);

            }

            if (priorGamePadState.ContainsKey(player))
            {
                lastState = priorGamePadState[player];
                // Notify listeners when the gamepad is connected/disconnected.
                if ((lastState.IsConnected != gps.IsConnected))
                {
                    gamePadConnection.IsConnected = false;
                    gamePadConnection.Player = (CCPlayerIndex)player;
                    dispatcher.DispatchEvent(gamePadConnection);

                }
                // TODO: Check button pressed/released status for button tap events.
            }

            if (gps.IsConnected)
            {
                var caps = GamePad.GetCapabilities(player);

                if (caps.HasBackButton ||
                    caps.HasStartButton ||
                    caps.HasBigButton ||
                    caps.HasAButton ||
                    caps.HasBButton ||
                    caps.HasXButton ||
                    caps.HasYButton ||
                    caps.HasLeftShoulderButton ||
                    caps.HasRightShoulderButton)
                {
                    var back = CCGamePadButtonStatus.NotApplicable;
                    var start = CCGamePadButtonStatus.NotApplicable;
                    var system = CCGamePadButtonStatus.NotApplicable;
                    var a = CCGamePadButtonStatus.NotApplicable;
                    var b = CCGamePadButtonStatus.NotApplicable;
                    var x = CCGamePadButtonStatus.NotApplicable;
                    var y = CCGamePadButtonStatus.NotApplicable;
                    var leftShoulder = CCGamePadButtonStatus.NotApplicable;
                    var 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);
                    }

                    gamePadButton.Back = back;
                    gamePadButton.Start = start;
                    gamePadButton.System = system;
                    gamePadButton.A = a;
                    gamePadButton.B = b;
                    gamePadButton.X = x;
                    gamePadButton.Y = y;
                    gamePadButton.LeftShoulder = leftShoulder;
                    gamePadButton.RightShoulder = rightShoulder;
                    gamePadButton.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadButton);
                }


                // Process the game sticks
                if ((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;
                    }
                    var 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);
                    var 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);

                    gamePadStick.Left = left;
                    gamePadStick.Right = right;
                    gamePadStick.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadStick);

                }
                // Process the game triggers
                if (caps.HasLeftTrigger || caps.HasRightTrigger)
                {
                    //GamePadTriggerUpdate (caps.HasLeftTrigger ? gps.Triggers.Left : 0f, caps.HasRightTrigger ? gps.Triggers.Right : 0f, player);
                    gamePadTrigger.Left = caps.HasLeftTrigger ? gps.Triggers.Left : 0f;
                    gamePadTrigger.Right = caps.HasRightTrigger ? gps.Triggers.Right : 0f;
                    gamePadTrigger.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadTrigger);
                }

                // Process the D-Pad
                if (caps.HasDPadDownButton ||
                    caps.HasDPadUpButton ||
                    caps.HasDPadLeftButton ||
                    caps.HasDPadRightButton)
                {

                    var leftButton = CCGamePadButtonStatus.NotApplicable;
                    var rightButton = CCGamePadButtonStatus.NotApplicable;
                    var upButton = CCGamePadButtonStatus.NotApplicable;
                    var downButton = CCGamePadButtonStatus.NotApplicable;

                    if (caps.HasDPadDownButton)
                    {
                        downButton = (gps.DPad.Down == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadUpButton)
                    {
                        upButton = (gps.DPad.Up == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadLeftButton)
                    {
                        leftButton = (gps.DPad.Left == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadRightButton)
                    {
                        rightButton = (gps.DPad.Right == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }

                    gamePadDPad.Down = downButton;
                    gamePadDPad.Up = upButton;
                    gamePadDPad.Left = leftButton;
                    gamePadDPad.Right = rightButton;

                    gamePadDPad.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadDPad);
                }
            }
            priorGamePadState[player] = gps;
        }
Exemplo n.º 4
0
        void ProcessGamePad(CCWindow window, GamePadState gps, PlayerIndex player)
        {
            var dispatcher = window.EventDispatcher;

            var lastState = new GamePadState();

            if (!priorGamePadState.ContainsKey(player) && gps.IsConnected)
            {
                gamePadConnection.IsConnected = true;
                gamePadConnection.Player      = (CCPlayerIndex)player;
                dispatcher.DispatchEvent(gamePadConnection);
            }

            if (priorGamePadState.ContainsKey(player))
            {
                lastState = priorGamePadState[player];
                // Notify listeners when the gamepad is connected/disconnected.
                if ((lastState.IsConnected != gps.IsConnected))
                {
                    gamePadConnection.IsConnected = false;
                    gamePadConnection.Player      = (CCPlayerIndex)player;
                    dispatcher.DispatchEvent(gamePadConnection);
                }
                // TODO: Check button pressed/released status for button tap events.
            }

            if (gps.IsConnected)
            {
                var caps = GamePad.GetCapabilities(player);

                if (caps.HasBackButton ||
                    caps.HasStartButton ||
                    caps.HasBigButton ||
                    caps.HasAButton ||
                    caps.HasBButton ||
                    caps.HasXButton ||
                    caps.HasYButton ||
                    caps.HasLeftShoulderButton ||
                    caps.HasRightShoulderButton)
                {
                    var back          = CCGamePadButtonStatus.NotApplicable;
                    var start         = CCGamePadButtonStatus.NotApplicable;
                    var system        = CCGamePadButtonStatus.NotApplicable;
                    var a             = CCGamePadButtonStatus.NotApplicable;
                    var b             = CCGamePadButtonStatus.NotApplicable;
                    var x             = CCGamePadButtonStatus.NotApplicable;
                    var y             = CCGamePadButtonStatus.NotApplicable;
                    var leftShoulder  = CCGamePadButtonStatus.NotApplicable;
                    var 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);
                    }

                    gamePadButton.Back          = back;
                    gamePadButton.Start         = start;
                    gamePadButton.System        = system;
                    gamePadButton.A             = a;
                    gamePadButton.B             = b;
                    gamePadButton.X             = x;
                    gamePadButton.Y             = y;
                    gamePadButton.LeftShoulder  = leftShoulder;
                    gamePadButton.RightShoulder = rightShoulder;
                    gamePadButton.Player        = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadButton);
                }


                // Process the game sticks
                if ((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;
                    }
                    var 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);
                    var 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);

                    gamePadStick.Left   = left;
                    gamePadStick.Right  = right;
                    gamePadStick.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadStick);
                }
                // Process the game triggers
                if (caps.HasLeftTrigger || caps.HasRightTrigger)
                {
                    //GamePadTriggerUpdate (caps.HasLeftTrigger ? gps.Triggers.Left : 0f, caps.HasRightTrigger ? gps.Triggers.Right : 0f, player);
                    gamePadTrigger.Left   = caps.HasLeftTrigger ? gps.Triggers.Left : 0f;
                    gamePadTrigger.Right  = caps.HasRightTrigger ? gps.Triggers.Right : 0f;
                    gamePadTrigger.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadTrigger);
                }

                // Process the D-Pad
                if (caps.HasDPadDownButton ||
                    caps.HasDPadUpButton ||
                    caps.HasDPadLeftButton ||
                    caps.HasDPadRightButton)
                {
                    var leftButton  = CCGamePadButtonStatus.NotApplicable;
                    var rightButton = CCGamePadButtonStatus.NotApplicable;
                    var upButton    = CCGamePadButtonStatus.NotApplicable;
                    var downButton  = CCGamePadButtonStatus.NotApplicable;

                    if (caps.HasDPadDownButton)
                    {
                        downButton = (gps.DPad.Down == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadUpButton)
                    {
                        upButton = (gps.DPad.Up == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadLeftButton)
                    {
                        leftButton = (gps.DPad.Left == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }
                    if (caps.HasDPadRightButton)
                    {
                        rightButton = (gps.DPad.Right == ButtonState.Pressed ? CCGamePadButtonStatus.Pressed : CCGamePadButtonStatus.Released);
                    }

                    gamePadDPad.Down  = downButton;
                    gamePadDPad.Up    = upButton;
                    gamePadDPad.Left  = leftButton;
                    gamePadDPad.Right = rightButton;

                    gamePadDPad.Player = (CCPlayerIndex)player;

                    dispatcher.DispatchEvent(gamePadDPad);
                }
            }
            priorGamePadState[player] = gps;
        }