コード例 #1
0
ファイル: Game06.cs プロジェクト: fvertk/DuckSlaughterZ
        /*
         * Called when game should begin
         */
        void beginGame()
        {

            graphics.PreferredBackBufferHeight = 800;
            graphics.PreferredBackBufferWidth = 600;
            graphics.ApplyChanges();

            deterministicGame.Initialize();
            latency = 1;
            lrFrame = 1;
            previousLRF = 0;
            secondLRF = 0;
            frames = new Dictionary<int, frame>();

            frameNumber = 0;
            stallCounter = 0;
            gameStarted = true;
            if (isHost)
                networkSession.StartGame();

            players = networkSession.AllGamers;
            pid = new int[4];
            myIdentifier = getIdentifier(networkSession.LocalGamers[0].Id);

            others = new player[players.Count];

            for (int i = 0; i < players.Count; i++)
            {
                pid[i] = (int)players[i].Id;

                others[i] = new player(players[i], getIdentifier(players[i].Id), deterministicGame);
            }

            Array.Sort(pid);

            myPlayer = null;
            for (int i = 0; i < others.Length; i++)
            {
                if (others[i].me == myIdentifier)
                    myPlayer = others[i];
            }

        }
コード例 #2
0
ファイル: Game06.cs プロジェクト: fvertk/DuckSlaughterZ
        /**
         * Reads a game packet
         */
        void readGamePacket(object sender)
        {
            //Find the senders identifier
            player currentPlayer = null;

            for (int i = 0; i < others.Length; i++)
            {
                if (sender == others[i].me)
                {
                    currentPlayer = others[i];
                }
            }

            currentPlayer.numberOfFS = reader.ReadInt16();
            currentPlayer.avOWD      = reader.ReadInt16();

            int lastFrame = reader.ReadInt32();

            //Add new frames up to the last frame that we recieved
            if (sender != getIdentifier(networkSession.LocalGamers[0].Id))
            {
                for (int i = currentPlayer.lastFrameNumber + 1; i <= lastFrame; i++)
                {
                    if (!currentPlayer.framesOfPlayer.ContainsKey(i))
                    {
                        currentPlayer.framesOfPlayer.Add(i, new frame());
                    }
                }
            }



            byte events = reader.ReadByte();

            int eventFrameNumber;

            for (byte i = 0; i < events; i++)
            {
                byte eventID = reader.ReadByte();
                eventFrameNumber = reader.ReadInt32();


                //Pressed key event
                if (eventID == 1)
                {
                    int keyCode = reader.ReadInt32();
                    if (currentPlayer.lastFrameNumber < eventFrameNumber || (currentPlayer == myPlayer && currentPlayer.framesOfPlayer.ContainsKey(eventFrameNumber)))
                    {
                        currentPlayer.framesOfPlayer[eventFrameNumber].pressedKeys.Add((Keys)(keyCode));
                    }
                }
                //Released Key Event
                if (eventID == 2)
                {
                    int keyCode = reader.ReadInt32();
                    if (currentPlayer.lastFrameNumber < eventFrameNumber || (currentPlayer == myPlayer && currentPlayer.framesOfPlayer.ContainsKey(eventFrameNumber)))
                    {
                        currentPlayer.framesOfPlayer[eventFrameNumber].releasedKeys.Add((Keys)(keyCode));
                    }
                }
                //Mouse down event
                if (eventID == 3)
                {
                    if (currentPlayer.lastFrameNumber < eventFrameNumber || (currentPlayer == myPlayer && currentPlayer.framesOfPlayer.ContainsKey(eventFrameNumber)))
                    {
                        currentPlayer.framesOfPlayer[eventFrameNumber].mouseDown   = true;
                        currentPlayer.framesOfPlayer[eventFrameNumber].mouseChange = true;
                    }

                    reader.ReadByte();
                }
                //Mouse Up event
                if (eventID == 4)
                {
                    if (currentPlayer.lastFrameNumber < eventFrameNumber || (currentPlayer == myPlayer && currentPlayer.framesOfPlayer.ContainsKey(eventFrameNumber)))
                    {
                        currentPlayer.framesOfPlayer[eventFrameNumber].mouseDown   = false;
                        currentPlayer.framesOfPlayer[eventFrameNumber].mouseChange = true;
                    }

                    reader.ReadByte();
                }
                //Mouse location
                if (eventID == 5)
                {
                    if (currentPlayer.lastFrameNumber < eventFrameNumber || (currentPlayer == myPlayer && currentPlayer.framesOfPlayer.ContainsKey(eventFrameNumber)))
                    {
                        currentPlayer.framesOfPlayer[eventFrameNumber].mouseX = reader.ReadInt16();
                        currentPlayer.framesOfPlayer[eventFrameNumber].mouseY = reader.ReadInt16();
                    }
                    else
                    {
                        reader.ReadInt16();
                        reader.ReadInt16();
                    }
                }
            }
            //set new last frame number
            currentPlayer.lastFrameNumber = lastFrame;
        }