Exemple #1
0
        /// <summary>
        /// Updates each of the game object's models with the time
        /// </summary>
        private void Update()
        {
            // Get the time since the last frame.
            float delta = FrameTimer.ElapsedMilliseconds;

            delta /= 1000.0f;
            delta  = Math.Max(.001f, delta);
            delta  = Math.Min(.01f, delta);
            // Iterate through all networked objects and update them.
            foreach (KeyValuePair <int, NetworkedGameObjectClient> kv in NetworkedGameObjects.AsEnumerable())
            {
                NetworkedGameObjectClient gameObject = kv.Value;

                // Update with delta in seconds
                gameObject.Update(delta);
            }

            // Iterate through all nonnetworked gameobjects and update them.
            foreach (GameObject obj in NonNetworkedGameObjects)
            {
                obj.Update(delta);
            }

            // Tint all of the leaves based on their sections.
            TintLeaves();
            CountLeaves();

            // Update all objects within the player's range with a tint.
            if (ActivePlayer != null)
            {
                ActivePlayer.TintObjectsInRange();
            }

            // Update the graphics manager.
            GraphicsManager.Update(delta);
            AudioManager.Update();
            AnimationManager.Update(delta);

            // Restart the frame ElapsedTime.
            FrameTimer.Restart();

            //AudioManager.UpdateSourceLocation(_audioChirping, Camera.CameraPosition);
        }
Exemple #2
0
        /// <summary>
        /// Loops through the hashtable of gameobjects and draws them
        /// </summary>
        private void Render()
        {
            // Iterate through all networked game objects and draw them.
            foreach (KeyValuePair <int, NetworkedGameObjectClient> kv in
                     NetworkedGameObjects.AsEnumerable())
            {
                NetworkedGameObjectClient gameObject = kv.Value;
                gameObject.Draw();
            }

            // iterate through all the non-networked objects and draw them.
            foreach (
                NonNetworkedGameObjectClient obj in NonNetworkedGameObjects
                )
            {
                obj.Draw();
            }

            GraphicsManager.Draw();
        }
Exemple #3
0
        /// <summary>
        /// Defines the different actions which the client will take upon recieving a packet, and defines
        /// them as a dictionary that hashes by packet type
        /// </summary>
        /// <param name="client">The game client to fire callbacks for</param>
        public ClientPacketHandler(GameClient client)
        {
            this.client = client;

            // What to do during an update
            void UpdateObjectAction(ObjectPacket p)
            {
                NetworkedGameObjectClient packetObject = client.GetObjectFromPacket(p);

                packetObject.UpdateFromPacket(p);
            }

            // what to do during an update to the playerpacket
            void UpdatePlayerAction(PlayerPacket p)
            {
                PlayerClient player = (PlayerClient)client.GetObjectFromPacket(p);

                if (client.GetActivePlayer() == player && p.Dead)
                {
                    client.DoPlayerDeath();
                }
                player.UpdateFromPacket(p);
            }

            // What to do during a destroy
            void DestroyAction(DestroyObjectPacket p)
            {
                NetworkedGameObjectClient packetObject = client.GetObjectFromPacket(p);

                packetObject.Die();
            }

            // What to do when creating an object
            GameObject CreateObjectAction(CreateObjectPacket p)
            {
                return(client.CreateObjectFromPacket(p));
            }

            // What to do when creating a player
            void CreatePlayerAction(CreatePlayerPacket p)
            {
                PlayerClient player = (PlayerClient)CreateObjectAction(p.createPacket);

                player.PlayerTeam = p.team;
            }

            // What to do on game finish
            void GameResultAction(GameResultPacket p)
            {
                client.ResetGameTimer();
                if (client.GetPlayerTeam() == p.winningTeam)
                {
                    GlobalUIManager.GameWinLossState.SetState(UI.UIGameWLState.WinLoseState.Win);
                }
                else
                {
                    GlobalUIManager.GameWinLossState.SetState(UI.UIGameWLState.WinLoseState.Lose);
                }

                // Save the player stats to file when the game ends.
                GameClient.instance.SaveStats(GraphicsManager.ActivePlayer.stats);

                client.WinningTeam         = p.winningTeam;
                client.PendingRematchState = true;
            }

            void GameStartAction(MatchStartPacket p)
            {
                client.StartMatchTimer(p.gameTime);
                GlobalUIManager.GameWinLossState.SetState(UI.UIGameWLState.WinLoseState.None);
                GlobalUIManager.GameWinLossState.SetStats(null);
                client.PendingRematchState = false;
                GlobalUIManager.Countdown.Start();
            }

            void SpectatorAction(SpectatorPacket p)
            {
                GraphicsManager.ActiveCamera.CameraPosition = new SlimDX.Vector3(0, 150, -1);
                GraphicsManager.ActiveCamera.CameraLookAt   = new SlimDX.Vector3(0, 0, 0);
                client.CreateMap();
            }

            void StatReceiveAction(StatResultPacket p)
            {
                if (p.PlayerID == GraphicsManager.ActivePlayer.Id)
                {
                    GraphicsManager.ActivePlayer.stats = p.stats;
                }
            }

            packetHandlers = new Dictionary <PacketType, Action <BasePacket> >()
            {
                { PacketType.CreatePlayerPacket, (p) => CreatePlayerAction((CreatePlayerPacket)p) },
                { PacketType.CreateObjectPacket, (p) => CreateObjectAction((CreateObjectPacket)p) },
                { PacketType.ObjectPacket, (p) => UpdateObjectAction((ObjectPacket)p) },
                { PacketType.PlayerPacket, (p) => UpdatePlayerAction((PlayerPacket)p) },
                { PacketType.DestroyObjectPacket, (p) => DestroyAction((DestroyObjectPacket)p) },
                { PacketType.GameResultPacket, (p) => GameResultAction((GameResultPacket)p) },
                { PacketType.MatchStartPacket, (p) => GameStartAction((MatchStartPacket)p) },
                { PacketType.SpectatorPacket, (p) => SpectatorAction((SpectatorPacket)p) },
                { PacketType.StatResultPacket, (p) => StatReceiveAction((StatResultPacket)p) },
            };
        }