示例#1
0
        public void process()
        {
            int count = inpQ.Count;

            CollisionManager.GameObjManager pObj = CollisionManager.GameObjManager.Instance();

            for (int i = 0; i < count; i++)
            {
                qHeader pInstance = inpQ.Dequeue();

                switch (pInstance.type)
                {
                case QueueType.ship_impulse:
                    ship_impulse imp = (ship_impulse)pInstance.obj;
                    imp.execute();
                    break;

                case QueueType.ship_missile:
                    Ship_Create_Missile_Message smiss = (Ship_Create_Missile_Message)pInstance.obj;
                    CollisionManager.Player     p2    = PlayerManager.getPlayer(smiss.id);
                    p2.createMissile();
                    break;

                case QueueType.ship_rot_anti:
                    Ship_rot_message srmsg = (Ship_rot_message)pInstance.obj;
                    srmsg.rot = -0.1f;
                    srmsg.execute();
                    break;

                case QueueType.ship_bomb:
                    Ship_Create_Bomb_Message smsg = (Ship_Create_Bomb_Message)pInstance.obj;
                    CollisionManager.GameObjManager.Instance().createBomb(smsg.id);
                    break;


                case QueueType.EventMessage:
                    EvenMessage msg = (EvenMessage)pInstance.obj;
                    msg.execute();
                    break;

                case QueueType.ship_rot_clock:
                    Ship_rot_message p3 = (Ship_rot_message)pInstance.obj;
                    p3.rot = 0.1f;
                    p3.execute();
                    break;
                }
            }
        }
示例#2
0
        public static void Process3()
        {
            InputQueue pInputQueue = new InputQueue();
            int        count       = inQ.Count;

            for (int i = 0; i < count; i++)
            {
                //read header
                QueueHdr qH = inQ.Dequeue();

                Message msg = null;

                switch (qH.type)
                {
                case Queue_type.QUEUE_SHIP_BOMB:
                    msg = new Ship_Create_Bomb_Message((Ship_Create_Bomb_Message)qH.data);
                    break;

                case Queue_type.QUEUE_SHIP_MISSILE:
                    msg = new Ship_Create_Missile_Message((Ship_Create_Missile_Message)qH.data);
                    break;

                case Queue_type.QUEUE_SHIP_IMPULSE:
                    msg = new Ship_Impulse_Message((Ship_Impulse_Message)qH.data);
                    break;

                case Queue_type.QUEUE_SHIP_ROT:
                    msg = new Ship_Rot_Message((Ship_Rot_Message)qH.data);
                    break;

                case Queue_type.QUEUE_PHYSICS_BUFFER:
                    msg = new PhysicsBuffer_Message((PhysicsBuffer_Message)qH.data);
                    break;

                case Queue_type.QUEUE_EVENT:
                    msg = new Event_Message((Event_Message)qH.data);
                    break;
                }

                msg.execute();
            }
        }
示例#3
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;
        }
示例#4
0
        void ClientReadGameStateFromServer(LocalNetworkGamer gamer)
        {
            // Keep reading as long as incoming packets are available.
            while (gamer.IsDataAvailable)
            {
                NetworkGamer sender;

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

                // This packet contains data about all the players in the session.
                // We keep reading from it until we have processed all the data.
                while (packetReader.Position < packetReader.Length)
                {
                    if (packetReader.Length <= 2)
                    {
                        break;
                    }
                    // Read the state of one tank from the network packet.
                    // byte gamerId = packetReader.ReadByte();
                    //Vector2 position = packetReader.ReadVector2();
                    //float tankRotation = packetReader.ReadSingle();
                    //float turretRotation = packetReader.ReadSingle();

                    QueueHdr qH;

                    qH.inSeqNum  = packetReader.ReadInt32();
                    qH.outSeqNum = packetReader.ReadInt32();
                    qH.type      = (Queue_type)packetReader.ReadInt32();

                    // int incomingCount = packetReader.ReadInt32();


                    //Debug.WriteLine("qH.inSeqNum  ServerRead = " + qH.inSeqNum);
                    //Debug.WriteLine("qH.outSeqNum ServerRead = " + qH.outSeqNum);
                    //Debug.WriteLine("qH.type ServerRead = " + qH.type);
                    //Debug.WriteLine("incomingCount ServerRead = " + incomingCount);


                    //////////////////////// send to input queue on client
                    //PhysicsBuffer[] physicsBuff2 = new PhysicsBuffer[incomingCount];


                    switch (qH.type)
                    {
                    case Queue_type.QUEUE_PHYSICS_BUFFER:
                        if (qH.type == Queue_type.QUEUE_PHYSICS_BUFFER)
                        {
                            int             incomingCount = packetReader.ReadInt32();
                            PhysicsBuffer[] physicsBuff2  = new PhysicsBuffer[incomingCount];

                            for (int y = 0; y < incomingCount; y++)
                            {
                                //PhysicsBuffer_Message localPhysicsBuffer_Message = new PhysicsBuffer_Message((PhysicsBuffer_Message)qH.data);
                                //PhysicsBuffer myPhysicsBuffer = new PhysicsBuffer();
                                //myPhysicsBuffer.id = packetReader.ReadInt32();
                                //myPhysicsBuffer.position = packetReader.ReadVector2();
                                //myPhysicsBuffer.rotation = (float)packetReader.ReadSingle();
                                //Push to buffer
                                physicsBuff2[y].id       = packetReader.ReadInt32();
                                physicsBuff2[y].position = packetReader.ReadVector2();
                                physicsBuff2[y].rotation = (float)packetReader.ReadSingle();
                            }

                            // send this msg to Input Queue inQ so client can read the messages
                            PhysicsBuffer_Message msg = new PhysicsBuffer_Message(ref physicsBuff2);
                            PhysicsBuffer_Message_inQueue.add(msg);
                        }
                        break;

                    case Queue_type.QUEUE_SHIP_MISSILE:
                        Ship_Create_Missile_Message msgMissile = new Ship_Create_Missile_Message(player2);
                        qH.data = msgMissile;
                        InputQueue.add(qH);
                        break;

                    case Queue_type.QUEUE_SHIP_BOMB:
                        Ship_Create_Bomb_Message msgBomb = new Ship_Create_Bomb_Message(player2);
                        qH.data = msgBomb;
                        InputQueue.add(qH);
                        break;

                    case Queue_type.QUEUE_SHIP_IMPULSE:
                        Vector2 impulse = packetReader.ReadVector2();
                        Ship_Impulse_Message msgImpulse = new Ship_Impulse_Message(player2, impulse);
                        qH.data = msgImpulse;
                        InputQueue.add(qH);
                        break;

                    case Queue_type.QUEUE_SHIP_ROT:
                        float            rotation    = packetReader.ReadSingle();
                        Ship_Rot_Message msgRotation = new Ship_Rot_Message(player2, rotation);
                        qH.data = msgRotation;
                        InputQueue.add(qH);
                        break;

                    case Queue_type.QUEUE_EVENT:
                        //msg = new Event_Message((Event_Message)qH.data);

                        int idA = packetReader.ReadInt32();
                        // Debug.WriteLine("idA =" + idA);
                        int idB = packetReader.ReadInt32();
                        // Debug.WriteLine("idA =" + idB);
                        Vector2 collisionPt = packetReader.ReadVector2();
                        // Debug.WriteLine("idA =" + collisionPt);

                        Event_Message eventMsg = new Event_Message(idA, idB, collisionPt);
                        qH.data = eventMsg;
                        InputQueue.add(qH);



                        break;
                    }
                }
            }
        }
示例#5
0
        void ServerReadInputFromClients(LocalNetworkGamer gamer)
        {
            // Keep reading as long as incoming packets are available.
            while (gamer.IsDataAvailable)
            {
                NetworkGamer sender;

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

                if (!sender.IsLocal)
                {
                    // Look up the tank associated with whoever sent this packet.
                    //Tank remoteTank = sender.Tag as Tank;
                    Ship remoteShip = sender.Tag as Ship;

                    // Read the latest inputs controlling this tank.
                    // remoteTank.TankInput = packetReader.ReadVector2();
                    // remoteTank.TurretInput = packetReader.ReadVector2();

                    QueueHdr qH;

                    qH.inSeqNum  = packetReader.ReadInt32();
                    qH.outSeqNum = packetReader.ReadInt32();
                    qH.type      = (Queue_type)packetReader.ReadInt32();
                    //qH.data = packetReader.ReadVector2();



                    switch (qH.type)
                    {
                    case Queue_type.QUEUE_SHIP_BOMB:
                        Ship_Create_Bomb_Message msg = new Ship_Create_Bomb_Message(player1);
                        qH.data = msg;
                        InputQueue.add(qH);
                        break;

                    case Queue_type.QUEUE_SHIP_MISSILE:
                        Ship_Create_Missile_Message msg2 = new Ship_Create_Missile_Message(player1);
                        qH.data = msg2;
                        InputQueue.add(qH);
                        break;

                    case Queue_type.QUEUE_SHIP_IMPULSE:
                        Ship_Impulse_Message sim = new Ship_Impulse_Message(player1, packetReader.ReadVector2());
                        // qH.data = packetReader.ReadVector2();
                        qH.data = sim;
                        //  Ship_Impulse_Message msg3 = new Ship_Impulse_Message((Ship_Impulse_Message)qH.data);
                        // msg = new Ship_Impulse_Message((Ship_Impulse_Message)qH.data);
                        // qH.data = msg3;
                        InputQueue.add(qH);

                        break;

                    case Queue_type.QUEUE_SHIP_ROT:
                        Ship_Rot_Message rotMessage = new Ship_Rot_Message(player1, packetReader.ReadSingle());    // float? ReadDouble()
                        // qH.data = packetReader.ReadVector2();
                        qH.data = rotMessage;
                        // Ship_Rot_Message msg4 = new Ship_Rot_Message((Ship_Rot_Message)qH.data);
                        // qH.data = msg4;
                        InputQueue.add(qH);
                        // msg = new Ship_Rot_Message((Ship_Rot_Message)qH.data);
                        break;

                    case Queue_type.QUEUE_EVENT:
                        break;
                    }
                }
            }
        }
示例#6
0
        // data-------------

        public Ship_Create_Missile_Message(Ship_Create_Missile_Message msg)
            : base(msg.id)
        {
        }
示例#7
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;
        }
示例#8
0
        void ReadFromServer(LocalNetworkGamer gamer)
        {
            // Keep reading as long as incoming packets are available.
            while (gamer.IsDataAvailable)
            {
                NetworkGamer sender;
                gamer.ReceiveData(Reader, out sender);
                Player p = gamer.Tag as Player;

                // This packet contains data about all the players in the session.
                // We keep reading from it until we have processed all the data.
                while (Reader.Position < Reader.Length)
                {
                    qHeader qH;
                    Player  player;
                    Ship    Player2Ship;

                    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();

                        player.playerShip.location.X = Reader.ReadInt32();
                        player.playerShip.location.Y = Reader.ReadInt32();
                        player.playerShip.rotation   = 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 p1 = new ship_impulse(player, direction);
                        p1.impulse.X = x;
                        p1.impulse.Y = y;
                        qH.obj       = p1;
                        break;

                    case QueueType.ship_rot_anti:
                        float x1 = (int)Reader.ReadInt32();
                        player.playerShip.location.X = Reader.ReadInt32();
                        player.playerShip.location.Y = Reader.ReadInt32();
                        player.playerShip.rotation   = Reader.ReadInt32();
                        Ship_rot_message pShip = new Ship_rot_message(player, x1);
                        pShip.rot = x1;
                        qH.obj    = pShip;
                        break;

                    case QueueType.ship_rot_clock:
                        float x2 = (int)Reader.ReadInt32();
                        player.playerShip.location.X = Reader.ReadInt32();
                        player.playerShip.location.Y = Reader.ReadInt32();
                        player.playerShip.rotation   = Reader.ReadInt32();
                        Ship_rot_message pShip1 = new Ship_rot_message(player, x2);
                        pShip1.rot = x2;
                        qH.obj     = pShip1;
                        break;

                    case QueueType.ship_bomb:
                        player.playerShip.location.X = Reader.ReadInt32();
                        player.playerShip.location.Y = Reader.ReadInt32();
                        player.playerShip.rotation   = Reader.ReadInt32();
                        Ship_Create_Bomb_Message p2 = new Ship_Create_Bomb_Message(player);
                        qH.obj = p2;
                        break;

                    case QueueType.ship_missile:
                        player.playerShip.location.X = Reader.ReadInt32();
                        player.playerShip.location.Y = Reader.ReadInt32();
                        player.playerShip.rotation   = Reader.ReadInt32();
                        Ship_Create_Missile_Message p3 = new Ship_Create_Missile_Message(player);
                        qH.obj = 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);
                }
            }
        }
示例#9
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);
            }
        }
示例#10
0
        public void Send(LocalNetworkGamer local, qHeader pHeader)
        {
            PacketWriter pWrite = new PacketWriter();

            pWrite.Write((int)pHeader.type);
            pWrite.Write((int)pHeader.packetOwner);
            pWrite.Write(pHeader.inseq);
            pWrite.Write(pHeader.outseq);


            switch (pHeader.type)
            {
            case QueueType.ship_rot_clock:
                Ship_rot_message p1 = (Ship_rot_message)pHeader.obj;
                pWrite.Write((int)p1.rot);
                pWrite.Write((int)p1.x);
                pWrite.Write((int)p1.y);
                pWrite.Write((int)p1.serverRotvalue);
                break;

            case QueueType.ship_rot_anti:
                Ship_rot_message p4 = (Ship_rot_message)pHeader.obj;
                pWrite.Write((int)p4.rot);
                pWrite.Write((int)p4.x);
                pWrite.Write((int)p4.y);
                pWrite.Write((int)p4.serverRotvalue);
                break;

            case QueueType.ship_missile:
                Ship_Create_Missile_Message missile = (Ship_Create_Missile_Message)pHeader.obj;
                pWrite.Write((int)missile.x);
                pWrite.Write((int)missile.y);
                pWrite.Write((int)missile.rot);
                break;

            case QueueType.ship_impulse:
                ship_impulse p = (ship_impulse)pHeader.obj;
                pWrite.Write((int)p.impulse.X);
                pWrite.Write((int)p.impulse.Y);
                pWrite.Write((int)p.x);
                pWrite.Write((int)p.y);
                pWrite.Write((int)p.rot);
                break;

            case QueueType.ship_bomb:
                Ship_Create_Bomb_Message bomb = (Ship_Create_Bomb_Message)pHeader.obj;
                pWrite.Write((int)bomb.x);
                pWrite.Write((int)bomb.y);
                pWrite.Write((int)bomb.rot);
                break;

            case QueueType.EventMessage:
                EvenMessage e = new EvenMessage((EvenMessage)pHeader.obj);
                pWrite.Write(e.gameIdA);
                pWrite.Write(e.gameIdB);
                pWrite.Write(e.CollisionPt);
                break;
            }

            local.SendData(pWrite, SendDataOptions.InOrder);
        }