Пример #1
0
        public static RotationMessage Deserialize(ref BinaryReader reader)
        {
            RotationMessage output = new RotationMessage();

            output.playerID  = reader.ReadInt32();
            output.input_Ang = reader.ReadSingle();
            return(output);
        }
Пример #2
0
        public void SendMessageToClient(DataMessage msg)
        {
            if (server.ConnectionsCount > 0)
            {
                NetworkMessage sm = new NetworkMessage();


                // Temporary
                switch (msg.type)
                {
                case DataMessage_Type.GAME_STATE:
                    GameStateMessage gameStateMsg = msg as GameStateMessage;
                    sm.Set_Data(gameStateMsg);
                    break;

                case DataMessage_Type.PLAYER_UPDATE:
                    PlayerUpdateMessage playerMsg = msg as PlayerUpdateMessage;
                    sm.Set_Data(playerMsg);
                    break;

                case DataMessage_Type.FENCE_HIT:
                    FenceHitMessage fMsg = msg as FenceHitMessage;
                    sm.Set_Data(fMsg);
                    break;

                case DataMessage_Type.MISSLE_MINE:
                    MissileMineMessage MMMsg = msg as MissileMineMessage;
                    sm.Set_Data(msg);
                    break;

                case DataMessage_Type.ROTATION:
                    RotationMessage rMsg = msg as RotationMessage;
                    sm.Set_Data(msg);
                    break;

                case DataMessage_Type.MISSILEUPDATE:
                    MissileUpdateMessage tmsg = msg as MissileUpdateMessage;
                    sm.Set_Data(msg);
                    break;

                case DataMessage_Type.GAME_OVER:
                    GAMEOVERMESSAGE gomsg = msg as GAMEOVERMESSAGE;
                    sm.Set_Data(msg);
                    break;

                default:
                    break;
                }

                NetOutgoingMessage om = server.CreateMessage();

                om.Write(sm.Serialize());
                server.SendMessage(om, server.Connections, NetDeliveryMethod.ReliableOrdered, 4);

                server.FlushSendQueue();
            }
        }
Пример #3
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;
                }
            }
        }
Пример #4
0
 void ProcessRotationMessage(RotationMessage msg)
 {
     if (msg.playerID == 1)
     {
         player1.SetAng(msg.input_Ang);
     }
     else if (msg.playerID == 2)
     {
         player2.SetAng(msg.input_Ang);
     }
 }
Пример #5
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.MISSLE_MINE:
                output.data = MissileMineMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.ROTATION:
                output.data = RotationMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.FENCE_HIT:
                output.data = FenceHitMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.MISSILEUPDATE:
                output.data = MissileUpdateMessage.Deserialize(ref reader);
                break;

            case DataMessage_Type.GAME_OVER:
                output.data = GAMEOVERMESSAGE.Deserialize(ref reader);
                break;

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

            return(output);
        }
Пример #6
0
        private void PlayScreenUpdate()
        {
            //if (InputManager.GetButtonDown(INPUTBUTTON.JUMP))
            //{
            //    state = GAME_STATE.GAME_OVER;
            //    DestroyAll();
            //    GAMEOVERMESSAGE go = new GAMEOVERMESSAGE(1);
            //    InputQueue.AddToQueue(go);
            //}

            for (int i = gameObjList.Count - 1; i >= 0; i--)
            {
                gameObjList[i].Update();
                // if(gameObjList[i] is Missile)
                // {
                //    Missile mis = gameObjList[i] as Missile;
                //    MissileUpdateMessage m = new MissileUpdateMessage(mis.MissileID, mis.GetPixelPosition().X, mis.GetPixelPosition().Y);
                //    InputQueue.AddToQueue(m);
                //}
            }


            // Network Stuff
            Vec2  p1Pos              = player1.GetPixelPosition();
            float p1Ang              = player1.GetAngle_Rad();
            PlayerUpdateMessage msg  = new PlayerUpdateMessage(1, p1Pos.X, p1Pos.Y);
            RotationMessage     rmsg = new RotationMessage(1, p1Ang);

            Vec2  p2Pos = player2.GetPixelPosition();
            float p2Ang = player2.GetAngle_Rad();
            PlayerUpdateMessage msg2  = new PlayerUpdateMessage(2, p2Pos.X, p2Pos.Y);
            RotationMessage     rmsg2 = new RotationMessage(2, p2Ang);

            InputQueue.AddToQueue(msg);
            InputQueue.AddToQueue(rmsg);
            InputQueue.AddToQueue(msg2);
            InputQueue.AddToQueue(rmsg2);
        }