Example #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);
            }
        }
Example #2
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;
                }
            }
        }
 public EvenMessage(EvenMessage msg)
 {
     this.gameIdA     = msg.gameIdA;
     this.gameIdB     = msg.gameIdB;
     this.CollisionPt = msg.CollisionPt;
 }
Example #4
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);
                }
            }
        }
Example #5
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);
            }
        }
Example #6
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);
        }