Exemplo n.º 1
0
        public RaceMap(Race race)
        {
            _race = race;
            PixFile pix = new PixFile(race.ConfigFile.MapTexture);
            if (pix.Exists)
                _mapTexture = pix.PixMaps[0].Texture;
            _player = Engine.ContentManager.Load<Texture2D>("content/map-icon-player");
            _opponent = Engine.ContentManager.Load<Texture2D>("content/map-icon-opponent");
            _deadOpponent = Engine.ContentManager.Load<Texture2D>("content/map-icon-opponent-dead");

            _mapRect = new Rectangle(0, 60, Engine.Window.Width, Engine.Window.Height - 90);
        }
Exemplo n.º 2
0
        public PlayGameScreen(IGameScreen parent)
        {
            Parent = parent;
            GC.Collect();

            _race = new Race(GameVars.BasePath + "races\\" + GameVars.SelectedRaceInfo.RaceFilename, GameVars.SelectedCarFileName);

            _modes.Add(new StandardGameMode());
            _modes.Add(new FlyMode());
            _modes.Add(new OpponentEditMode());
            _modes.Add(new PedEditMode());
            GameMode.Current = _modes[_currentEditMode];
        }
Exemplo n.º 3
0
        public Race(string filename, string playerVehicleFile)
        {
            Race.Current = this;

            Logger.Log("Starting race " + Path.GetFileName(filename));

            ConfigFile = new RaceFile(filename);

            foreach (string matFileName in ConfigFile.MaterialFiles)
            {
                MatFile matFile = new MatFile(matFileName);
                ResourceCache.Add(matFile);
            }

            foreach (string pixFileName in ConfigFile.PixFiles)
            {
                PixFile pixFile = new PixFile(pixFileName);
                ResourceCache.Add(pixFile);
            }

            if (GameVars.Emulation == EmulationMode.Demo)
            {
                ResourceCache.Add(new CMaterial("drkcurb.mat", 226)); //demo doesn't have this file, I guess the color is hard-coded
            }
            else
            {
                ResourceCache.Add(new MatFile("drkcurb.mat"));
            }

            ResourceCache.ResolveMaterials();

            if (filename.Contains("TESTMAP")) //nasty hack...
            {
                GameVars.Scale.Y *= 0.5f;
            }

            DatFile modelFile = new DatFile(ConfigFile.ModelFile);

            ActFile actFile = new ActFile(ConfigFile.ActorFile);

            _actors = actFile.Hierarchy;
            _actors.AttachModels(modelFile.Models);
            _actors.ResolveTransforms(false, ConfigFile.Grooves);

            if (filename.Contains("TESTMAP")) //nasty hack...
            {
                GameVars.Scale.Y *= 2f;
            }

            // link the actors and grooves
            foreach (BaseGroove g in ConfigFile.Grooves)
            {
                g.SetActor(_actors.GetByName(g.ActorName));
            }

            // link the funks and materials
            foreach (BaseFunk f in ConfigFile.Funks)
            {
                f.Resolve();
            }

            if (ConfigFile.SkyboxTexture != "none")
            {
                PixFile horizonPix = new PixFile(ConfigFile.SkyboxTexture);
                _skybox = SkyboxGenerator.Generate(horizonPix.PixMaps[0].Texture, ConfigFile.SkyboxRepetitionsX - 3f, ConfigFile.DepthCueMode);
                _skybox.HeightOffset = -220 + ConfigFile.SkyboxPositionY * 1.5f;
            }

            Physics.TrackProcessor.GenerateTrackActor(ConfigFile, _actors, out _nonCars);

            Logger.Log("NonCars: " + _nonCars.Count);

            GridPlacer.Reset();

            List <int> opponentIds = new List <int>();
            List <int> pickedNbrs  = new List <int>();

            for (int i = 0; i < 5; i++)
            {
                int index = 0;
                while (true)
                {
                    index = GameEngine.Random.Next(1, OpponentsFile.Instance.Opponents.Count);
                    if (!pickedNbrs.Contains(index))
                    {
                        pickedNbrs.Add(index);
                        break;
                    }
                }
                try
                {
                    Opponents.Add(new Opponent(OpponentsFile.Instance.Opponents[index].FileName, ConfigFile.GridPosition, ConfigFile.GridDirection));
                    NbrOpponents++;
                }
                catch (Exception ex)
                {
                    Logger.Log("Error while loading opponent " + OpponentsFile.Instance.Opponents[index].FileName + ", " + ex.Message);
                }
            }

            foreach (CopStartPoint point in ConfigFile.CopStartPoints)
            {
                Opponents.Add(new Opponent(point.IsSpecialForces ? "bigapc.txt" : "apc.txt", point.Position, 0, new CopDriver()));
            }

            foreach (Opponent o in Opponents)
            {
                Drivers.Add(o.Driver);
            }

            OpponentController.Nodes = ConfigFile.OpponentPathNodes;

            PlayerVehicle = new Vehicle(GameVars.BasePath + @"cars\" + playerVehicleFile, new PlayerDriver());
            PlayerVehicle.PlaceOnGrid(ConfigFile.GridPosition, ConfigFile.GridDirection);
            Drivers.Add(PlayerVehicle.Driver);

            Peds = new PedestrianController(ConfigFile.Peds);
            _map = new RaceMap(this);

            RaceTime = new RaceTimeController();

            PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.TrackId, PhysXConsts.VehicleId, ContactPairFlag.Forces | ContactPairFlag.OnStartTouch | ContactPairFlag.OnTouch);
            PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.VehicleId, PhysXConsts.NonCarId, ContactPairFlag.Forces | ContactPairFlag.OnStartTouch | ContactPairFlag.OnTouch);
            PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.TrackId, PhysXConsts.NonCarId, ContactPairFlag.OnTouch);
            PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.VehicleId, PhysXConsts.VehicleId, ContactPairFlag.Forces | ContactPairFlag.OnTouch | ContactPairFlag.OnStartTouch | ContactPairFlag.OnEndTouch);
        }
Exemplo n.º 4
0
        public Race(string filename, string playerVehicleFile)
        {
            Race.Current = this;

            Logger.Log("Starting race " + Path.GetFileName(filename));

            ConfigFile = new RaceFile(filename);

            foreach (string matFileName in ConfigFile.MaterialFiles)
            {
                MatFile matFile = new MatFile(matFileName);
                ResourceCache.Add(matFile);
            }

            foreach (string pixFileName in ConfigFile.PixFiles)
            {
                PixFile pixFile = new PixFile(pixFileName);
                ResourceCache.Add(pixFile);
            }

            if (GameVars.Emulation == EmulationMode.Demo)
                ResourceCache.Add(new CMaterial("drkcurb.mat", 226)); //demo doesn't have this file, I guess the color is hard-coded
            else
                ResourceCache.Add(new MatFile("drkcurb.mat"));

            ResourceCache.ResolveMaterials();

            if (filename.Contains("TESTMAP")) //nasty hack...
                GameVars.Scale.Y *= 0.5f;

            DatFile modelFile = new DatFile(ConfigFile.ModelFile);

            ActFile actFile = new ActFile(ConfigFile.ActorFile);
            _actors = actFile.Hierarchy;
            _actors.AttachModels(modelFile.Models);
            _actors.ResolveTransforms(false, ConfigFile.Grooves);

            if (filename.Contains("TESTMAP")) //nasty hack...
                GameVars.Scale.Y *= 2f;

            // link the actors and grooves
            foreach (BaseGroove g in ConfigFile.Grooves)
                g.SetActor(_actors.GetByName(g.ActorName));

            // link the funks and materials
            foreach (BaseFunk f in ConfigFile.Funks)
            {
                f.Resolve();
            }

            if (ConfigFile.SkyboxTexture != "none")
            {
                PixFile horizonPix = new PixFile(ConfigFile.SkyboxTexture);
                _skybox = SkyboxGenerator.Generate(horizonPix.PixMaps[0].Texture, ConfigFile.SkyboxRepetitionsX - 3f, ConfigFile.DepthCueMode);
                _skybox.HeightOffset = -220 + ConfigFile.SkyboxPositionY * 1.5f;
            }

            Physics.TrackProcessor.GenerateTrackActor(ConfigFile, _actors, out _nonCars);

            Logger.Log("NonCars: " + _nonCars.Count);

            GridPlacer.Reset();

            List<int> opponentIds = new List<int>();
            List<int> pickedNbrs = new List<int>();
            for (int i = 0; i < 5; i++)
            {
                int index = 0;
                while (true)
                {
                    index = Engine.Random.Next(1, OpponentsFile.Instance.Opponents.Count);
                    if (!pickedNbrs.Contains(index))
                    {
                        pickedNbrs.Add(index);
                        break;
                    }
                }
                try
                {
                    Opponents.Add(new Opponent(OpponentsFile.Instance.Opponents[index].FileName, ConfigFile.GridPosition, ConfigFile.GridDirection));
                    NbrOpponents++;
                }
                catch(Exception ex)
                {
                    Logger.Log("Error while loading opponent " + OpponentsFile.Instance.Opponents[index].FileName + ", " + ex.Message);
                }
            }

            foreach (CopStartPoint point in ConfigFile.CopStartPoints)
            {
                Opponents.Add(new Opponent(point.IsSpecialForces ? "bigapc.txt" : "apc.txt", point.Position, 0, new CopDriver()));
            }

            foreach (Opponent o in Opponents) Drivers.Add(o.Driver);

            OpponentController.Nodes = ConfigFile.OpponentPathNodes;

            PlayerVehicle = new Vehicle(GameVars.BasePath + @"cars\" + playerVehicleFile, new PlayerDriver());
            PlayerVehicle.PlaceOnGrid(ConfigFile.GridPosition, ConfigFile.GridDirection);
            Drivers.Add(PlayerVehicle.Driver);

            Peds = new PedestrianController(ConfigFile.Peds);
            _map = new RaceMap(this);

            RaceTime = new RaceTimeController();

            PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.TrackId, PhysXConsts.VehicleId, ContactPairFlag.Forces | ContactPairFlag.OnStartTouch | ContactPairFlag.OnTouch);
            PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.VehicleId, PhysXConsts.NonCarId, ContactPairFlag.Forces | ContactPairFlag.OnStartTouch | ContactPairFlag.OnTouch);
            PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.TrackId, PhysXConsts.NonCarId, ContactPairFlag.OnTouch);
            PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.VehicleId, PhysXConsts.VehicleId, ContactPairFlag.Forces | ContactPairFlag.OnTouch | ContactPairFlag.OnStartTouch | ContactPairFlag.OnEndTouch);
        }
Exemplo n.º 5
0
        public void ExitAndReturnToMenu()
        {
            ResourceCache.Clear();
            foreach (var d in Drivers)
                d.Vehicle.Audio.Stop();

            ParticleSystem.AllParticleSystems.Clear();
            Race.Current = null;
            PhysX.Instance.Delete();
            var screen = Engine.Screen.Parent;
            if (screen is PlayGameScreen)  //this will be true if called from the pause screen
                screen = screen.Parent;

            Engine.Screen = null;
            GC.Collect();
            Engine.Screen = screen;
        }