Пример #1
0
 void ProcessPlayerInputMessage(PlayerInputMessage msg)
 {
     if (msg.playerID == 1)
     {
         player1.Rotate(msg.horzInput);
         player1.Move(msg.vertInput);
         if (msg.fireMissile)
         {
             GameManager.FireMissile(player1);
         }
         if (msg.layMine)
         {
             GameManager.LayMine(player1);
         }
         Vec2 t = player1.GetHeading();
         MissileMineMessage p1MissileUpdate = new MissileMineMessage(1, msg.fireMissile, msg.layMine, t.X, t.Y);
         InputQueue.AddToQueue(p1MissileUpdate);
     }
     else if (msg.playerID == 2)
     {
         player2.Rotate(msg.horzInput);
         player2.Move(msg.vertInput);
         if (msg.fireMissile)
         {
             GameManager.FireMissile(player2);
         }
         if (msg.layMine)
         {
             GameManager.LayMine(player2);
         }
         Vec2 t = player2.GetHeading();
         MissileMineMessage p2MissileUpdate = new MissileMineMessage(2, msg.fireMissile, msg.layMine, t.X, t.Y);
         InputQueue.AddToQueue(p2MissileUpdate);
     }
 }
Пример #2
0
        public static NetworkMessage Deserialize(byte[] bytes)
        {
            BinaryReader   reader = new BinaryReader(new MemoryStream(bytes));
            NetworkMessage output = new NetworkMessage();

            output.data_type = (DataMessage_Type)reader.ReadInt32();

            switch (output.data_type)
            {
            case DataMessage_Type.GAME_STATE:
                output.data = GameStateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.PLAYER_UPDATE:
                output.data = PlayerUpdateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.PLAYER_INPUT:
                output.data = PlayerInputMessage.Deserialize(ref reader);
                break;


            default:
                Debug.Assert(false, "INVALID DATA TYPE");
                break;
            }

            return(output);
        }
Пример #3
0
        public void SendMessageToServer(DataMessage msg)
        {
            if (pConnected)
            {
                NetworkMessage sm = new NetworkMessage();


                // Temporary
                switch (msg.type)
                {
                case DataMessage_Type.PLAYER_INPUT:
                    PlayerInputMessage playerMsg = msg as PlayerInputMessage;
                    sm.Set_Data(playerMsg);
                    break;
                }

                NetOutgoingMessage om = client.CreateMessage();

                om.Write(sm.Serialize());
                client.SendMessage(om, NetDeliveryMethod.ReliableOrdered);

                //client.RawSend()

                client.FlushSendQueue();
            }
        }
Пример #4
0
        public static PlayerInputMessage Deserialize(ref BinaryReader reader)
        {
            PlayerInputMessage output = new PlayerInputMessage();

            output.ID        = (PLAYER_ID)reader.ReadInt32();
            output.horzInput = reader.ReadInt32();
            output.vertInput = reader.ReadInt32();

            return(output);
        }
Пример #5
0
        public static void RecieveMessage(DataMessage msg)
        {
            if (instance.state == GAME_STATE.LOBBY)
            {
                switch (msg.type)
                {
                case DataMessage_Type.GAME_STATE:
                    instance.ProcessGameStateMessage(msg as GameStateMessage);
                    break;
                }
            }
            else if (instance.state == GAME_STATE.PLAY)
            {
                switch (msg.type)
                {
                case DataMessage_Type.PLAYER_INPUT:
                    PlayerInputMessage pMsg = msg as PlayerInputMessage;
                    instance.ProcessPlayerInputMessage(pMsg);
                    break;

                case DataMessage_Type.PLAYER_UPDATE:
                    PlayerUpdateMessage updateMsg = msg as PlayerUpdateMessage;
                    instance.ProcessPlayerUpdateMessage(updateMsg);
                    break;

                case DataMessage_Type.FENCE_HIT:
                    FenceHitMessage fenceMsg = msg as FenceHitMessage;
                    instance.ProcessFenceHitMessage(fenceMsg);
                    break;

                case DataMessage_Type.MISSLE_MINE:
                    MissileMineMessage MMMsg = msg as MissileMineMessage;
                    instance.ProcessMissileMineMessage(MMMsg);
                    break;

                case DataMessage_Type.ROTATION:
                    RotationMessage rMsg = msg as RotationMessage;
                    instance.ProcessRotationMessage(rMsg);
                    break;

                case DataMessage_Type.MISSILEUPDATE:
                    MissileUpdateMessage MMsg = msg as MissileUpdateMessage;
                    instance.ProcessMissileUpdateMessage(MMsg);
                    break;

                case DataMessage_Type.GAME_OVER:
                    GAMEOVERMESSAGE gomsg = msg as GAMEOVERMESSAGE;
                    instance.ProcessGameOverMessage(gomsg);
                    break;

                default:
                    break;
                }
            }
        }
Пример #6
0
        public static PlayerInputMessage Deserialize(ref BinaryReader reader)
        {
            PlayerInputMessage output = new PlayerInputMessage();

            output.playerID    = reader.ReadInt32();
            output.horzInput   = reader.ReadInt32();
            output.vertInput   = reader.ReadInt32();
            output.fireMissile = reader.ReadBoolean();
            output.layMine     = reader.ReadBoolean();
            return(output);
        }
Пример #7
0
        public static void RecieveMessage(DataMessage msg)
        {
            if (instance.state == GAME_STATE.LOBBY)
            {
                switch (msg.type)
                {
                case DataMessage_Type.GAME_STATE:
                    instance.ProcessGameStateMessage(msg as GameStateMessage);
                    break;
                }
            }
            else if (instance.state == GAME_STATE.PLAY)
            {
                if (msg.sendType == SEND_TYPE.NETWORKED)
                {
                    if (msg.type == DataMessage_Type.PLAYER_INPUT)
                    {
                        PlayerInputMessage pMsg = msg as PlayerInputMessage;
                        // Only recieve 2nd Player input
                        if (pMsg.playerID == 2)
                        {
                            instance.ProcessPlayerInputMessage(pMsg);
                        }
                    }
                }
                else
                {
                    switch (msg.type)
                    {
                    case DataMessage_Type.PLAYER_INPUT:
                        PlayerInputMessage pMsg = msg as PlayerInputMessage;
                        instance.ProcessPlayerInputMessage(pMsg);
                        break;

                    case DataMessage_Type.PLAYER_UPDATE:
                        PlayerUpdateMessage updateMsg = msg as PlayerUpdateMessage;
                        instance.ProcessPlayerUpdateMessage(updateMsg);
                        break;

                    default:
                        Debug.Assert(false, "Not Processing Anything");
                        break;
                    }
                }
            }
        }
Пример #8
0
 void ProcessPlayerInputMessage(PlayerInputMessage msg)
 {
     if (msg.playerID == 1)
     {
         player1.Rotate(msg.horzInput);
         player1.Move(msg.vertInput);
         if (msg.fireMissile)
         {
             GameManager.FireMissile(player1);
         }
     }
     else if (msg.playerID == 2)
     {
         player2.Rotate(msg.horzInput);
         player2.Move(msg.vertInput);
         if (msg.fireMissile)
         {
             GameManager.FireMissile(player2);
         }
     }
 }
Пример #9
0
        void CheckForInput()
        {
            int  p1_H       = InputManager.GetAxis(INPUTAXIS.HORIZONTAL_P1);
            int  p1_V       = InputManager.GetAxis(INPUTAXIS.VERTICAL_P1);
            bool p1_Missile = InputManager.GetButtonDown(INPUTBUTTON.P1_FIRE);
            bool p1_Mine    = InputManager.GetButtonDown(INPUTBUTTON.P1_FIRE2);

            PlayerInputMessage p1msg = new PlayerInputMessage(SEND_TYPE.LOCAL, 1, p1_H, p1_V, p1_Missile, p1_Mine);

            InputQueue.AddToQueue(p1msg);



            int  p2_H       = InputManager.GetAxis(INPUTAXIS.HORIZONTAL_P2);
            int  p2_V       = InputManager.GetAxis(INPUTAXIS.VERTICAL_P2);
            bool p2_Missile = InputManager.GetButtonDown(INPUTBUTTON.P2_FIRE);

            // PlayerInputMessage p2msg = new PlayerInputMessage(2, p2_H, p2_V, p2_Missile);

            //  InputQueue.AddToQueue(p2msg);
        }
Пример #10
0
        void CheckForInput()
        {
            if (GameManager.GetGameState() == GAME_STATE.PLAY)
            {
                int  p1_H       = InputManager.GetAxis(INPUTAXIS.HORIZONTAL_P1);
                int  p1_V       = InputManager.GetAxis(INPUTAXIS.VERTICAL_P1);
                bool p1_Missile = InputManager.GetButtonDown(INPUTBUTTON.P1_FIRE);


                //PlayerInputMessage p1msg = new PlayerInputMessage(SEND_TYPE.NETWORKED, 1, p1_H, p1_V, p1_Missile);

                //InputQueue.AddToQueue(p1msg);

                int  p2_H       = InputManager.GetAxis(INPUTAXIS.HORIZONTAL_P2);
                int  p2_V       = InputManager.GetAxis(INPUTAXIS.VERTICAL_P2);
                bool p2_Missile = InputManager.GetButtonDown(INPUTBUTTON.P2_FIRE);
                bool p2_Mine    = InputManager.GetButtonDown(INPUTBUTTON.P2_FIRE2);

                PlayerInputMessage p2msg = new PlayerInputMessage(SEND_TYPE.NETWORKED, 2, p2_H, p2_V, p2_Missile, p2_Mine);

                InputQueue.AddToQueue(p2msg);
            }
        }