Пример #1
0
        private void checkInput()
        {
            newState      = Keyboard.GetState();
            P1newPadState = GamePad.GetState(PlayerIndex.One);
            P2newPadState = GamePad.GetState(PlayerIndex.Two);

            if (oldState.IsKeyDown(Keys.D) || P1oldPadState.IsButtonDown(Buttons.DPadRight))
            {
                player1.playerShip.physicsObj.body.Rotation += 0.1f;
                Ship_Rot_Message msg = new Ship_Rot_Message(player1, 0.1f);
                Debug.WriteLine("D player1.playerShip.physicsObj.body.Rotation = " + player1.playerShip.physicsObj.body.Rotation);
                OutputQueue.add(msg);
            }

            if (oldState.IsKeyDown(Keys.A) || P1oldPadState.IsButtonDown(Buttons.DPadLeft))
            {
                player1.playerShip.physicsObj.body.Rotation -= 0.1f;
                Ship_Rot_Message msg = new Ship_Rot_Message(player1, -0.1f);
                Debug.WriteLine("A player1.playerShip.physicsObj.body.Rotation = " + player1.playerShip.physicsObj.body.Rotation);
                OutputQueue.add(msg);
            }

            if (oldState.IsKeyDown(Keys.W) || P1oldPadState.IsButtonDown(Buttons.DPadUp))
            {
                Ship Player1Ship = player1.playerShip;

                Vector2 direction = new Vector2((float)(Math.Cos(Player1Ship.physicsObj.body.GetAngle())), (float)(Math.Sin(Player1Ship.physicsObj.body.GetAngle())));
                Debug.WriteLine("direction - W - = " + direction);
                //Vector2 direction = new Vector2(.6f, .5f);
                direction.Normalize();
                float x = (float)(Math.Cos(Player1Ship.physicsObj.body.GetAngle()));
                float y = (float)(Math.Sin(Player1Ship.physicsObj.body.GetAngle()));
                Debug.WriteLine("x = " + x);
                Debug.WriteLine("y = " + y);
                direction *= shipSpeed;
                Debug.WriteLine("direction - W - afterNormal = " + direction);


                // No action, send a message thru queue
                //Player1Ship.physicsObj.body.ApplyLinearImpulse(direction, Player1Ship.physicsObj.body.GetWorldCenter());

                Ship_Impulse_Message msg = new Ship_Impulse_Message(player1, direction);
                OutputQueue.add(msg);
            }

            if ((oldState.IsKeyDown(Keys.X) && newState.IsKeyUp(Keys.X)) || (P1oldPadState.IsButtonDown(Buttons.A) && P1newPadState.IsButtonUp(Buttons.A)))
            {
                if (player1.state == PlayerState.alive && player1.missileAvailable())
                {
                    // player1.createMissile();

                    Ship_Create_Missile_Message msg = new Ship_Create_Missile_Message(player1);
                    OutputQueue.add(msg);
                }
            }

            if (oldState.IsKeyDown(Keys.C) && newState.IsKeyUp(Keys.C) || (P1oldPadState.IsButtonDown(Buttons.B) && P1newPadState.IsButtonUp(Buttons.B)))
            {
                if (player1.state == PlayerState.alive && BombManager.Instance().bombAvailable(PlayerID.one))
                {
                    // GameObjManager.Instance().createBomb(PlayerID.one);

                    Ship_Create_Bomb_Message msg = new Ship_Create_Bomb_Message(player1);
                    OutputQueue.add(msg);
                }
            }

            if (oldState.IsKeyDown(Keys.Right) || P2oldPadState.IsButtonDown(Buttons.DPadRight))
            {
                // player2.playerShip.physicsObj.body.Rotation += 0.1f;
                Ship_Rot_Message msg = new Ship_Rot_Message(player2, 0.1f);
                Debug.WriteLine("Right player2.playerShip.physicsObj.body.Rotation = " + player2.playerShip.physicsObj.body.Rotation);
                OutputQueue.add(msg);
            }

            if (oldState.IsKeyDown(Keys.Left) || P2oldPadState.IsButtonDown(Buttons.DPadLeft))
            {
                //player2.playerShip.physicsObj.body.Rotation -= 0.1f;
                Ship_Rot_Message msg = new Ship_Rot_Message(player2, -0.1f);
                Debug.WriteLine("Left player1.playerShip.physicsObj.body.Rotation = " + player2.playerShip.physicsObj.body.Rotation);
                OutputQueue.add(msg);
            }


            if (oldState.IsKeyDown(Keys.Up) || P2oldPadState.IsButtonDown(Buttons.DPadUp))
            {
                Ship Player2Ship = player2.playerShip;

                Vector2 direction = new Vector2((float)(Math.Cos(Player2Ship.physicsObj.body.GetAngle())), (float)(Math.Sin(Player2Ship.physicsObj.body.GetAngle())));
                //Vector2 direction = new Vector2(-.5f, .5f);
                Debug.WriteLine("direction - up - = " + direction);
                float x = (float)(Math.Cos(Player2Ship.physicsObj.body.GetAngle()));
                float y = (float)(Math.Sin(Player2Ship.physicsObj.body.GetAngle()));
                Debug.WriteLine("x = " + x);
                Debug.WriteLine("y = " + y);
                direction.Normalize();

                direction *= shipSpeed;

                // Player2Ship.physicsObj.body.ApplyLinearImpulse(direction, Player2Ship.physicsObj.body.GetWorldCenter());

                // No action, send a message thru queue
                //Player1Ship.physicsObj.body.ApplyLinearImpulse(direction, Player1Ship.physicsObj.body.GetWorldCenter());

                Ship_Impulse_Message msg = new Ship_Impulse_Message(player2, direction);
                OutputQueue.add(msg);
            }

            if ((oldState.IsKeyDown(Keys.OemQuestion) && newState.IsKeyUp(Keys.OemQuestion)) || (P2oldPadState.IsButtonDown(Buttons.A) && P2newPadState.IsButtonUp(Buttons.A)))
            {
                if (player2.state == PlayerState.alive && player2.missileAvailable())
                {
                    // player2.createMissile();
                    Ship_Create_Missile_Message msg = new Ship_Create_Missile_Message(player2);
                    OutputQueue.add(msg);
                }
            }

            if (oldState.IsKeyDown(Keys.OemPeriod) && newState.IsKeyUp(Keys.OemPeriod) || (P2oldPadState.IsButtonDown(Buttons.B) && P2newPadState.IsButtonUp(Buttons.B)))
            {
                if (player2.state == PlayerState.alive && BombManager.Instance().bombAvailable(PlayerID.two))
                {
                    // GameObjManager.Instance().createBomb(PlayerID.two);

                    Ship_Create_Bomb_Message msg = new Ship_Create_Bomb_Message(player2);
                    OutputQueue.add(msg);
                }
            }


            else
            {
            }



            P1oldPadState = P1newPadState;
            P2oldPadState = P2newPadState;
            oldState      = newState;
        }
Пример #2
0
        public void BeginContact(Contact contact)
        {
            GameObject A = (GameObject)contact.GetFixtureA().GetUserData();
            GameObject B = (GameObject)contact.GetFixtureB().GetUserData();

            Manifold  manifold;
            Transform xfA;
            Transform xfB;
            float     radiusA;
            float     radiusB;

            contact.GetFixtureA().GetBody().GetTransform(out xfA);
            contact.GetFixtureB().GetBody().GetTransform(out xfB);
            radiusA = contact.GetFixtureA().GetShape()._radius;
            radiusB = contact.GetFixtureB().GetShape()._radius;

            contact.GetManifold(out manifold);

            WorldManifold worldManifold = new WorldManifold(ref manifold, ref xfA, radiusA, ref xfB, radiusB);

            Vector2 ptA = worldManifold._points[0];
            Vector2 ptB = worldManifold._points[1];

            // adding this for networking
            if (A.GameID == 1)
            {
                int x = 0;
            }

            System.Console.Write("v--> sending mc point A:{0} B:{1} {2} {3}\n", A.GameID, B.GameID, ptA, ptB);

            Debug.Assert(A != null);
            Debug.Assert(B != null);

            Event_Message msg = new Event_Message(A.GameID, B.GameID, ptA);

            OutputQueue.add(msg);

            //System.Console.Write(" point {0} {1}\n", ptA, ptB);

            // if (A.CollideAvailable == true && B.CollideAvailable == true)
            {/*
              * if (A.type < B.type)
              * {
              *     A.Accept(B, ptA);
              * }
              * else
              * {
              *     B.Accept(A, ptA);
              * }*/
            }

            //if (A.type == GameObjType.p1missiles || A.type == GameObjType.p2missiles)
            //{
            //    A.CollideAvailable = false;
            //}

            //if (B.type == GameObjType.p1missiles || B.type == GameObjType.p2missiles)
            //{
            //    B.CollideAvailable = false;
            //}
        }