Exemplo n.º 1
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];

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

            EvenMessage e = new EvenMessage(A.gameId, B.gameId, ptA);


            if (A.type == GameObjType.p1Bomb || A.type == GameObjType.p1missiles || A.type == GameObjType.p1ship)
            {
                OutQueue.add(e, PlayerID.one);
            }
            else if (A.type == GameObjType.p2Bomb || A.type == GameObjType.p2missiles || A.type == GameObjType.p2ship)
            {
                OutQueue.add(e, PlayerID.two);
            }
            else if (B.type == GameObjType.p1Bomb || B.type == GameObjType.p1missiles || B.type == GameObjType.p1ship)
            {
                OutQueue.add(e, PlayerID.one);
            }
            else if (B.type == GameObjType.p2Bomb || B.type == GameObjType.p2missiles || B.type == GameObjType.p2ship)
            {
                OutQueue.add(e, PlayerID.two);
            }
            else
            {
                OutQueue.add(e, PlayerID.one);
            }
        }
Exemplo n.º 2
0
        private void checkInput()
        {
            newState      = Keyboard.GetState();
            P1newPadState = GamePad.GetState(PlayerIndex.One);
            P2newPadState = GamePad.GetState(PlayerIndex.Two);
            Player p;

            if (Host)
            {
                p = PlayerManager.getPlayer(PlayerID.one);
            }
            else
            {
                p = PlayerManager.getPlayer(PlayerID.two);
            }

            ////Player 1 controls
            if (oldState.IsKeyDown(Keys.D) || P1oldPadState.IsButtonDown(Buttons.DPadRight))
            {
                Ship_rot_message pShip = new Ship_rot_message(p, 0.1f);
                pShip.serverRotvalue = p.playerShip.rotation;
                pShip.x = p.playerShip.location.X;
                pShip.y = p.playerShip.location.Y;
                OutQueue.add(QueueType.ship_rot_clock, pShip, p.id);
            }

            if (oldState.IsKeyDown(Keys.A) || P1oldPadState.IsButtonDown(Buttons.DPadLeft))
            {
                Ship_rot_message pShip = new Ship_rot_message(p, -0.1f);
                pShip.serverRotvalue = p.playerShip.rotation;
                pShip.x = p.playerShip.location.X;
                pShip.y = p.playerShip.location.Y;
                OutQueue.add(QueueType.ship_rot_anti, pShip, p.id);
            }

            if (oldState.IsKeyDown(Keys.W) || P1oldPadState.IsButtonDown(Buttons.DPadUp))
            {
                Ship    Player1Ship = p.playerShip;
                Vector2 direction   = new Vector2((float)(Math.Cos(Player1Ship.physicsObj.body.GetAngle())), (float)(Math.Sin(Player1Ship.physicsObj.body.GetAngle())));
                direction.Normalize();
                direction *= shipSpeed;
                ship_impulse p1 = new ship_impulse(p, direction);
                p1.rot = p.playerShip.rotation;
                OutQueue.add(QueueType.ship_impulse, p1, p.id);
            }

            if ((oldState.IsKeyDown(Keys.X) && newState.IsKeyUp(Keys.X)) || (P1oldPadState.IsButtonDown(Buttons.A) && P1newPadState.IsButtonUp(Buttons.A)))
            {
                if (player1.state == PlayerState.alive && player1.missileAvailable())
                {
                    Ship_Create_Bomb_Message p1 = new Ship_Create_Bomb_Message(p);
                    p1.x   = p.playerShip.location.X;
                    p1.y   = p.playerShip.location.Y;
                    p1.rot = p.playerShip.rotation;
                    OutQueue.add(QueueType.ship_bomb, p1, p.id);
                }
            }

            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(p.id))
                {
                    Ship_Create_Missile_Message p1 = new Ship_Create_Missile_Message(p);
                    p1.x   = p.playerShip.location.X;
                    p1.y   = p.playerShip.location.Y;
                    p1.rot = p.playerShip.rotation;
                    OutQueue.add(QueueType.ship_missile, p1, p.id);
                }
            }

            P1oldPadState = P1newPadState;
            P2oldPadState = P2newPadState;
            oldState      = newState;
        }
Exemplo n.º 3
0
        void ReadInputFromClients(LocalNetworkGamer gamer)
        {
            while (gamer.IsDataAvailable)
            {
                NetworkGamer sender;

                // Read a single packet from the network.
                gamer.ReceiveData(Reader, out sender);

                if (sender.IsLocal)
                {
                    continue;
                }

                qHeader qH;
                Ship    Player2Ship;
                Player  player;

                qH.type        = (QueueType)Reader.ReadInt32();
                qH.packetOwner = (PlayerID)Reader.ReadInt32();
                qH.inseq       = Reader.ReadInt32();
                qH.outseq      = Reader.ReadInt32();
                qH.obj         = null;

                if (qH.packetOwner == PlayerID.one)
                {
                    Player2Ship = player1.playerShip;
                    player      = player1;
                }
                else
                {
                    Player2Ship = player2.playerShip;
                    player      = player2;
                }


                switch (qH.type)
                {
                case QueueType.ship_impulse:
                    float x = Reader.ReadInt32();
                    float y = Reader.ReadInt32();

                    float   m         = Reader.ReadInt32();
                    float   n         = Reader.ReadInt32();
                    float   r         = Reader.ReadInt32();
                    Vector2 direction = new Vector2((float)(Math.Cos(Player2Ship.physicsObj.body.GetAngle())), (float)(Math.Sin(Player2Ship.physicsObj.body.GetAngle())));
                    direction.Normalize();
                    direction *= shipSpeed;
                    ship_impulse p = new ship_impulse(player, direction);

                    //update server values
                    p.rot = player.playerShip.rotation;
                    p.x   = player.playerShip.location.X;
                    p.y   = player.playerShip.location.Y;

                    p.impulse.X = x;
                    p.impulse.Y = y;
                    qH.obj      = p;
                    break;

                case QueueType.ship_rot_anti:
                    float            x1    = (int)Reader.ReadInt32();
                    Ship_rot_message pShip = new Ship_rot_message(player, x1);
                    pShip.rot = x1;

                    //server values
                    pShip.x = player.playerShip.location.X;
                    pShip.y = player.playerShip.location.Y;
                    pShip.serverRotvalue = player.playerShip.rotation;

                    qH.obj = pShip;
                    break;

                case QueueType.ship_rot_clock:
                    float            x2     = (int)Reader.ReadInt32();
                    Ship_rot_message pShip1 = new Ship_rot_message(player, x2);
                    pShip1.rot = x2;

                    //server values
                    pShip1.x = player.playerShip.location.X;
                    pShip1.y = player.playerShip.location.Y;
                    pShip1.serverRotvalue = player.playerShip.rotation;

                    qH.obj = pShip1;
                    break;

                case QueueType.ship_bomb:
                    Ship_Create_Bomb_Message p2 = new Ship_Create_Bomb_Message(player);
                    //server values
                    p2.x   = player.playerShip.location.X;
                    p2.y   = player.playerShip.location.Y;
                    p2.rot = player.playerShip.rotation;
                    qH.obj = p2;
                    break;

                case QueueType.ship_missile:
                    Ship_Create_Missile_Message p3 = new Ship_Create_Missile_Message(player);
                    //server values
                    p3.x   = player.playerShip.location.X;
                    p3.y   = player.playerShip.location.Y;
                    p3.rot = player.playerShip.rotation;
                    qH.obj = p3;
                    break;

                case QueueType.physicsBuffer:
                    //physics_buffer_message p4 = new physics_buffer_message();
                    //qH.ob = p3;
                    break;

                case QueueType.EventMessage:
                    int         a  = (int)Reader.ReadInt32();
                    int         b  = (int)Reader.ReadInt32();
                    Vector2     pt = (Vector2)Reader.ReadVector2();
                    EvenMessage e  = new EvenMessage(a, b, pt);
                    qH.obj = e;
                    break;
                }
                inQueue.add(qH.obj, qH.type, qH.outseq, qH.packetOwner);
                OutQueue.add(qH.type, qH.obj, qH.packetOwner);
            }
        }