Ejemplo n.º 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;
                }
            }
        }
Ejemplo 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;
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
        }