Esempio n. 1
0
        public void Update(GameTime gt, Game1 Game)
        {
            if (!MatchController.MatchDone)
            {
                localTeam = localPlayer.Team;

                m_controller.ProcessInput(Game.KbState);
                m_sessionManager.GetGameUpdates(gt, gameWorld);


                for (int i = 0; i < gameWorld.PickupItems.Count; i++)
                {
                    Type itemType = gameWorld.PickupItems[i].GetType();
                    if ((itemType == typeof(Weapon)) || (itemType.BaseType == typeof(Weapon)))
                    {
                        Weapon gun = (Weapon)gameWorld.PickupItems[i];
                        gun.Update(gt, gameWorld);
                    }
                    else if (itemType == typeof(Flag))
                    {
                        Flag flag = (Flag)gameWorld.PickupItems[i];
                        flag.Update(gt, gameWorld);
                        flag.CheckCapState(gameWorld.RedBase);
                        flag.CheckCapState(gameWorld.BlueBase);
                    }

                    if (gameWorld.PickupItems[i].State == EntityState.Dead)
                    {
                        if (gameWorld.PickupItems[i].GetType().BaseType == typeof(Weapon))
                        {
                            if (gameWorld.PickupItems[i].SpawnPont != null)
                            {
                                ((Weapon)gameWorld.PickupItems[i]).SpawnPont.SpawnWeapon(gameWorld.PickupItems);
                            }
                            else
                            {
                                gameWorld.PickupItems[i].SpawnPont = getSpawn(gameWorld.PickupItems[i]);
                                ((Weapon)gameWorld.PickupItems[i]).SpawnPont.SpawnWeapon(gameWorld.PickupItems);
                            }
                            gameWorld.PickupItems.RemoveAt(i);
                        }
                        else if (gameWorld.PickupItems[i].GetType() == typeof(Flag))
                        {
                            if (((Flag)gameWorld.PickupItems[i]).Base == null)
                            {
                                if (((Flag)gameWorld.PickupItems[i]).Team == 1)
                                {
                                    ((Flag)gameWorld.PickupItems[i]).Base = gameWorld.BlueBase;
                                }
                                else if (((Flag)gameWorld.PickupItems[i]).Team == 2)
                                {
                                    ((Flag)gameWorld.PickupItems[i]).Base = gameWorld.RedBase;
                                }
                            }
                            else
                            {
                                ((Flag)gameWorld.PickupItems[i]).Base.SpawnFlag(gameWorld.PickupItems);
                                gameWorld.PickupItems.RemoveAt(i);
                            }
                        }
                    }
                }

                foreach (NetworkGamer player in m_sessionManager.NetSession.AllGamers)
                {
                    ((SpaceMarine)player.Tag).UpdateProjectiles(gt, m_sessionManager);
                }

                localPlayer.Update(gt, m_controller, gameWorld, m_crossHair);


                if (localPlayer != null)
                {
                    if (localPlayer.Rectangle.Intersects(gameWorld.WorldBoundary))
                    {
                        m_camera.updateMe(gt, Game.KbState, Game.MouseState);
                    }

                    if (localPlayer.isHit)
                    {
                        m_camera.doShake(1f, 3f, 1f);
                    }

                    m_crossHair.updateMe(Game.MouseState, m_camera, localPlayer);
                }

                m_matchController.updateMe(gameWorld);
                m_sessionManager.SendLocalUpdate(localPlayer);

                if (localPlayer.State != ActorState.Dying)
                {
                    m_camera.Follow(localPlayer, 0f);
                }

                if (m_matchController.Match != MatchType.DM)
                {
                    if (localPlayer.Team != 0)
                    {
                        if (localPlayer.State == ActorState.Dead)
                        {
                            m_spawnManager.RespawnPlayer(localPlayer, m_matchController);
                        }
                    }
                }
                else
                {
                    if (localPlayer.State == ActorState.Dead)
                    {
                        m_spawnManager.RespawnPlayer(localPlayer, m_matchController);
                    }
                }
            }

            if (m_sessionManager.gameEnded)
            {
                m_sessionManager.Dispose();
                Game.State = GameState.Menu;
                MessageBox.Show("Game Session has ended.");
            }
        }