/// <summary>
 /// Decides which UI to show when a level is loaded
 /// </summary>
 private void OnLevelLoad(LevelChangedEventArgs eventArgs)
 {
     if (eventArgs.NewLevel.Type.HasFlag(LevelType.Race)) {
         // when going from the menu to something else
         levelGui.Visible = true;
     }
 }
		/// <summary>
		/// Sets up our dictionaries and hooks up to the frame started event
		/// </summary>
		void OnLevelLoad(LevelChangedEventArgs eventArgs) {
			if (eventArgs.NewLevel.Type == LevelType.Race) {
				SelfRighters = new ConcurrentDictionary<Kart, SelfRighter>();
				CurrentlyDrivingOn = new ConcurrentDictionary<Kart, CollisionObject>();

				PhysicsMain.PreSimulate += PreSimulate;
			}
		}
        void OnLevelPostLoad(LevelChangedEventArgs eventArgs)
        {
            if (eventArgs.NewLevel.Type == LevelType.Race) {
                var sceneMgr = LKernel.GetG<SceneManager>();
                var def = eventArgs.NewLevel.Definition;

                // background color
                LKernel.GetG<Viewport>().BackgroundColour = def.GetVectorProperty("Background", Vector3.UNIT_SCALE).ToColourValue();

                // ambient
                sceneMgr.AmbientLight = def.GetVectorProperty("Ambient", Vector3.UNIT_SCALE).ToColourValue();

                // sunlight
                Light light = sceneMgr.CreateLight("sun");
                light.Type = Light.LightTypes.LT_DIRECTIONAL;
                light.Direction = def.GetVectorProperty("SunlightDirection", new Vector3(0.1f, -1f, 0.1f));
                light.Direction.Normalise();
                light.DiffuseColour = def.GetVectorProperty("SunlightColour", Vector3.UNIT_SCALE).ToColourValue();
                light.SpecularColour = def.GetVectorProperty("SunlightColour", Vector3.UNIT_SCALE).ToColourValue();
                // cast shadows if we want some
                if (Options.ShadowDetail != ShadowDetailOption.None)
                    light.CastShadows = true;

                // skybox
                if (def.StringTokens.ContainsKey("skybox"))
                    sceneMgr.SetSkyBox(true, def.GetStringProperty("Skybox", null), 399f);

                // fog
                FogMode mode = FogMode.FOG_NONE;
                string sMode = def.GetStringProperty("FogType", "None");

                if (sMode.Equals("None", StringComparison.InvariantCultureIgnoreCase))
                    mode = FogMode.FOG_NONE;
                else if (sMode.Equals("Exp", StringComparison.InvariantCultureIgnoreCase))
                    mode = FogMode.FOG_EXP;
                else if (sMode.Equals("Exp2", StringComparison.InvariantCultureIgnoreCase))
                    mode = FogMode.FOG_EXP2;
                else if (sMode.Equals("Linear", StringComparison.InvariantCultureIgnoreCase))
                    mode = FogMode.FOG_LINEAR;

                if (mode != FogMode.FOG_NONE) {
                    sceneMgr.SetFog(
                        mode,
                        def.GetQuatProperty("FogColour", Quaternion.IDENTITY).ToColourValue(),
                        0.001f,
                        def.GetFloatProperty("FogStart", 20),
                        def.GetFloatProperty("FogEnd", 100));
                }

            #if DEBUG
                // make some axes
                LKernel.GetG<Spawner>().Spawn("Axis", Vector3.ZERO);
            #endif
            }
            else if (eventArgs.NewLevel.Type == LevelType.Menu) {
                LKernel.GetG<SceneManager>().AmbientLight = new ColourValue(1, 1, 1);
            }
        }
Exemple #4
0
        public Player(LevelChangedEventArgs eventArgs, int id, bool isComputerControlled)
        {
            // don't want to create a player if it's ID isn't valid
            if (id < 0 || id >= Settings.Default.NumberOfPlayers)
                throw new ArgumentOutOfRangeException("id", "ID number specified for kart spawn position is not valid!");
            Launch.Log("[Loading] Player with ID " + id + " created");

            this.IsComputerControlled = isComputerControlled;

            // set up the spawn position/orientation
            Vector3 spawnPos = eventArgs.NewLevel.Definition.GetVectorProperty("KartSpawnPosition" + id, null);
            Quaternion spawnOrient = eventArgs.NewLevel.Definition.GetQuatProperty("KartSpawnOrientation" + id, Quaternion.IDENTITY);

            ThingBlock block = new ThingBlock("TwiCutlass", spawnPos, spawnOrient);

            string driverName, kartName;
            switch (eventArgs.Request.CharacterNames[id]) {
                case "Twilight Sparkle":
                    driverName = "Twilight";
                    kartName = "TwiCutlass";
                    break;
                case "Rainbow Dash":
                    driverName = "RainbowDash";
                    kartName = "DashJavelin";
                    break;
                case "Applejack":
                    driverName = "Applejack";
                    kartName = "AJKart";
                    break;
                case "Rarity":
                    driverName = "Rarity";
                    kartName = "TwiCutlass";
                    break;
                case "Fluttershy":
                    driverName = "Fluttershy";
                    kartName = "TwiCutlass";
                    break;
                case "Pinkie Pie":
                    driverName = "PinkiePie";
                    kartName = "TwiCutlass";
                    break;
                default:
                    throw new ArgumentException("Invalid character name!", "eventArgs");
            }

            Kart = LKernel.GetG<Spawner>().SpawnKart(kartName, block);
            Driver = LKernel.GetG<Spawner>().SpawnDriver(driverName, block);
            Driver.AttachToKart(Kart, Vector3.ZERO);
            Kart.Player = this;
            Driver.Player = this;

            Character = eventArgs.Request.CharacterNames[id];

            Kart.OwnerID = id;
            ID = id;
        }
 /// <summary>
 /// Runs whenever a new level is loaded. We create the background music now so it loads, then pause it until we need to play it.
 /// </summary>
 void OnLevelLoad(LevelChangedEventArgs eventArgs)
 {
     // only want to load this on nonempty levels
     if (eventArgs.NewLevel.Type != LevelType.EmptyLevel) {
         // get the property from the .muffin file, if it has one
         string musicFile = eventArgs.NewLevel.Definition.GetStringProperty("Music", string.Empty);
         if (musicFile != string.Empty) {
             // if it's a race level, don't play the music until we need it
             bgMusic = LKernel.GetG<SoundMain>().PlayMusic(musicFile, eventArgs.NewLevel.Type == LevelType.Race);
         }
     }
 }
        public ComputerPlayer(LevelChangedEventArgs eventArgs, int id)
            : base(eventArgs, id, true)
        {
            //LKernel.GetG<CollisionReporter>().AddEvent(PonykartCollisionGroups.Karts, PonykartCollisionGroups.Environment, OnCol);
                #if DEBUG
                axis = LKernel.GetG<Core.Spawner>().Spawn("Axis", Kart.RootNode.Position);
                axis.ModelComponents[0].Node.SetScale(0.1f, 0.1f, 0.1f);
                axis2 = LKernel.GetG<Core.Spawner>().Spawn("Axis", Kart.RootNode.Position);
                axis2.ModelComponents[0].Node.SetScale(0.1f, 0.1f, 0.1f);
                #endif

            Launch.OnEveryUnpausedTenthOfASecondEvent += EveryTenth;
        }
        public WiiMotePlayer(LevelChangedEventArgs eventArgs, int id)
            : base(eventArgs, id, false)
        {
            while (true)
            {
                try
                {
                    _wiimote = new Wiimote();
                    _wiimote.Connect();
                    break;
                }
                catch (WiimoteNotFoundException)
                {
                    MessageBox.Show("Please ensure a wiimote is paired to your computer via Bluetooth, then press OK to try again");
                }

            }
            _wiimote.SetLEDs(id + 1);
        }
		public HumanPlayer(LevelChangedEventArgs eventArgs, int id)
			: base(eventArgs, id, false) {

			// hook up to input events
			bindings = LKernel.Get<KeyBindingManager>();

            LKernel.GetG<GameUIManager>().SetItemLevel(0);
            
			bindings.PressEventsDict[LKey.Accelerate] += OnStartAccelerate;
			bindings.ReleaseEventsDict[LKey.Accelerate] += OnStopAccelerate;
			bindings.PressEventsDict[LKey.Drift] += OnStartDrift;
			bindings.ReleaseEventsDict[LKey.Drift] += OnStopDrift;
			bindings.PressEventsDict[LKey.Reverse] += OnStartReverse;
			bindings.ReleaseEventsDict[LKey.Reverse] += OnStopReverse;
			bindings.PressEventsDict[LKey.TurnLeft] += OnStartTurnLeft;
			bindings.ReleaseEventsDict[LKey.TurnLeft] += OnStopTurnLeft;
			bindings.PressEventsDict[LKey.TurnRight] += OnStartTurnRight;
			bindings.ReleaseEventsDict[LKey.TurnRight] += OnStopTurnRight;
            bindings.PressEventsDict[LKey.Item] += UseItem;
            //bindings.ReleaseEventsDict[LKey.=Item] += ; Might need this later
			//bindings.AxisEvents[LKey.SteeringAxis] += OnSteeringAxisMoved;
			//bindings.AxisEvents[LKey.AccelerateAxis] += OnAccelerateAxisMoved;
		}
 /// <summary>
 /// hook up to the frame started event
 /// </summary>
 void OnLevelLoad(LevelChangedEventArgs eventArgs)
 {
     LKernel.GetG<Root>().FrameStarted += FrameStarted;
 }
 private void InvokeLevelProgress(LevelChangedEventArgs args, string message)
 {
     if (OnLevelLoadProgress != null)
         OnLevelLoadProgress(args, message);
 }
 /// <summary>
 /// helper
 /// </summary>
 private void Invoke(LevelEvent e, LevelChangedEventArgs args)
 {
     if (e != null)
         e(args);
 }
 void OnLevelLoad(LevelChangedEventArgs eventArgs)
 {
     if (eventArgs.NewLevel.Type == LevelType.Menu) {
         MenuBackgroundGui.Visible = true;
         GameTypeGui.Visible = true;
     }
 }
 void OnLevelPreUnload(LevelChangedEventArgs eventArgs)
 {
     if (eventArgs.OldLevel.Type == LevelType.Menu) {
         MenuBackgroundGui.Visible = false;
         GameTypeGui.Visible = NetworkHostGui.Visible = NetworkClientGui.Visible = LevelSelectGui.Visible
             = CharacterSelectGui.Visible = OptionsGui.Visible = LobbyGui.Visible = false;
     }
 }
        private void OnLevelUnload(LevelChangedEventArgs eventArgs)
        {
            LKernel.GetG<TriggerReporter>().OnTriggerEnter -= OnTriggerEnter;

            nextTriggerRegions.Clear();
        }
 void OnLevelUnload(LevelChangedEventArgs eventArgs)
 {
     if (eventArgs.OldLevel.Type == LevelType.Race)
     {
         //Clean up any remaining items
         activeItems.Clear();
         boxes.Clear();
     }
 }
        /// <summary>
        /// Unloads the current level and loads the new level
        /// </summary>
        private void LoadLevelNow(LevelChangedEventArgs args)
        {
            Level newLevel = args.NewLevel;

            // Unload current level
            UnloadLevel(args);

            CurrentLevel = newLevel;

            // Load new Level
            if (newLevel != null) {
                Launch.Log("==========================================================");
                Launch.Log("======= Level loading: " + newLevel.Name + " =======");
                Launch.Log("==========================================================");

                // load our resource group, if we have one
                InvokeLevelProgress(args, "Initialising new resource group...");
                if (ResourceGroupManager.Singleton.ResourceGroupExists(newLevel.Name) && !ResourceGroupManager.Singleton.IsResourceGroupInitialised(newLevel.Name)) {
                    Launch.Log("[Loading] Initialising resource group: " + newLevel.Name);
                    ResourceGroupManager.Singleton.InitialiseResourceGroup(newLevel.Name);
                }

                // load up the world definition from the .muffin file
                InvokeLevelProgress(args, "Reading .muffin files...");
                newLevel.ReadMuffin();

                // set up shadows, create stuff in the .scene file, and set up physics
                InvokeLevelProgress(args, "Reading .scene file and setting up shadows and physics...");
                LKernel.GetG<SceneManager>().SetupShadows(newLevel);
                newLevel.ReadDotSceneAndSetupPhysics();

                // run our level loading events
                Launch.Log("[Loading] Loading everything else...");
                InvokeLevelProgress(args, "Invoking level load event...");
                Invoke(OnLevelLoad, args);

                // then put Things into our world
                InvokeLevelProgress(args, "Creating entities...");
                newLevel.CreateEntities();
                // then load the rest of the handlers
                InvokeLevelProgress(args, "Loading level handlers...");
                LKernel.LoadLevelHandlers(newLevel);

                IsValidLevel = true;

                if (IsPlayableLevel)
                    LKernel.GetG<PhysicsMain>().StartSimulation();

                // run our scripts
                InvokeLevelProgress(args, "Running scripts...");
                LKernel.GetG<LuaMain>().LoadScriptFiles(newLevel.Name);
                newLevel.RunLevelScript();
                newLevel.RunThingScripts();

                InvokeLevelProgress(args, "Building static and instanced geometry...");
                LKernel.GetG<StaticGeometryManager>().Build();
                LKernel.GetG<InstancedGeometryManager>().Build();
            }

            // if we're on the main menu, pause it
            if (newLevel.Name == Settings.Default.MainMenuName)
                Pauser.IsPaused = true;

            // last bit of cleanup
            InvokeLevelProgress(args, "Garbage collecting...");
            GC.Collect();

            // post load event needs to be delayed
            if (newLevel != null) {
                // reset these
                elapsed = 0;
                frameOneRendered = frameTwoRendered = false;

                // set up our handler
                postLoadFrameStartedHandler = new FrameListener.FrameStartedHandler(
                    (fe) => {
                        return DelayedRun_FrameStarted(fe, INITIAL_DELAY, (a) => { Invoke(OnLevelPostLoad, a); }, args);
                    });
                LKernel.Get<Root>().FrameStarted += postLoadFrameStartedHandler;
            }
        }
Exemple #17
0
        /// <summary>
        /// prepares file locations
        /// </summary>
        void OnLevelLoad(LevelChangedEventArgs eventArgs)
        {
            fileList = new Dictionary<string, string>();

            foreach (string group in ResourceGroupManager.Singleton.GetResourceGroups().Where(s => ResourceGroupManager.Singleton.IsResourceGroupInitialised(s))) {
                if (group == "Bootstrap")
                    continue;

                var resourceLocations = ResourceGroupManager.Singleton.ListResourceLocations(group);

                foreach (string loc in resourceLocations) {
                    var soundfiles = Directory.EnumerateFiles(loc, "*.ogg").Union(Directory.EnumerateFiles(loc, "*.mp3")).Union(Directory.EnumerateFiles(loc, "*.wav"));

                    foreach (string file in soundfiles) {
                        fileList[Path.GetFileName(file)] = file;
                    }
                }
            }
        }
 /// <summary>
 /// Disposes all of our cameras and clears our list
 /// </summary>
 void OnLevelUnload(LevelChangedEventArgs eventArgs)
 {
     foreach (LCamera cam in cameras) {
         cam.Dispose();
     }
     cameras.Clear();
     CurrentCamera = null;
 }
Exemple #19
0
        void OnLevelPostLoad(LevelChangedEventArgs eventArgs)
        {
            if (eventArgs.NewLevel.Name == "SweetAppleAcres") {

                // create lap data array
                lapData = new Pair<bool, int>[Settings.Default.NumberOfPlayers];
                // fill it with default data
                for (int a = 0; a < lapData.Length; a++) {
                    lapData[a] = new Pair<bool, int>(true, 0);
                }

                anyoneFinishedYet = false;

                // hook up to the trigger regions
                var triggerReporter = LKernel.GetG<TriggerReporter>();
                triggerReporter.AddEvent("AITriggerRegion1", CrossFinishLine);
                triggerReporter.AddEvent("AITriggerRegion28", Halfway);

            }
        }
		/// <summary>
		/// cleanup
		/// </summary>
		void OnLevelUnload(LevelChangedEventArgs eventArgs) {
			if (eventArgs.OldLevel.Type == LevelType.Race) {
				PhysicsMain.PreSimulate -= PreSimulate;

				// clean up these
				foreach (SelfRighter h in SelfRighters.Values) {
					h.Detach();
				}
				SelfRighters.Clear();
			}
		}
        /// <summary>
        /// Unloads the current level
        /// - Sets IsValidLevel to false
        /// - Runs the levelUnload events
        /// - Tells the kernel to unload all level objects
        /// - Disposes the current level
        /// </summary>
        private void UnloadLevel(LevelChangedEventArgs eventArgs)
        {
            if (CurrentLevel.Name != null) {
                Launch.Log("==========================================================");
                Launch.Log("======= Level unloading: " + CurrentLevel.Name + " =======");
                Launch.Log("==========================================================");

                IsValidLevel = false;

                //CurrentLevel.Save();

                InvokeLevelProgress(eventArgs, "Unloading level handlers...");
                LKernel.UnloadLevelHandlers();

                InvokeLevelProgress(eventArgs, "Invoking level unload event...");
                // invoke the level unloading events
                Invoke(OnLevelUnload, eventArgs);

                InvokeLevelProgress(eventArgs, "Cleaning up...");
                LKernel.Cleanup();

                CurrentLevel.Dispose();
            }
        }
        /// <summary>
        /// Parses the level's .tr file (if it has one) and sets up the AI trigger regions
        /// </summary>
        private void OnLevelLoad(LevelChangedEventArgs eventArgs)
        {
            if (eventArgs.NewLevel.Type != LevelType.Race)
                return;

            nextTriggerRegions = new Dictionary<TriggerRegion, TriggerRegion>();

            /*
             * threshold
             * id idTO height width posX posY posZ orientX orientY orientZ orientW
             */

            if (File.Exists("media/worlds/" + eventArgs.NewLevel.Name + ".tr"))
            {
                var collisionShapeMgr = LKernel.GetG<CollisionShapeManager>();
                var tempDic = new Dictionary<TriggerRegion, int>();
                var triggerRegions = new Dictionary<int, TriggerRegion>();

                using (StreamReader reader = new StreamReader("media/worlds/" + eventArgs.NewLevel.Name + ".tr"))
                {
                    float threshold = float.Parse(reader.ReadLine());

                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        // ignore comments
                        if (line.StartsWith("//"))
                            continue;

                        string[] parts = line.Split(' ');
                        if (parts.Length == 11)
                        {
                            int id = int.Parse(parts[0], culture);
                            int idTo = int.Parse(parts[1], culture);
                            Vector3 dims = new Vector3(
                                threshold,
                                float.Parse(parts[2], culture),
                                float.Parse(parts[3], culture));
                            Vector3 pos = new Vector3(
                                float.Parse(parts[4], culture),
                                float.Parse(parts[5], culture),
                                float.Parse(parts[6], culture));
                            Quaternion orient = new Quaternion(
                                float.Parse(parts[7], culture),
                                float.Parse(parts[8], culture),
                                float.Parse(parts[9], culture),
                                float.Parse(parts[10], culture));

                            CollisionShape shape;
                            if (!collisionShapeMgr.TryGetShape(parts[2] + parts[3], out shape))
                            {
                                shape = new BoxShape(dims);
                                collisionShapeMgr.RegisterShape(parts[2] + parts[3], shape);
                            }

                            TriggerRegion tr = new TriggerRegion("AITriggerRegion" + id, pos, orient, shape);

                            triggerRegions[id] = tr;
                            tempDic[tr] = idTo;
                        }
                    }
                }
                foreach (var kvp in tempDic)
                {
                    nextTriggerRegions[kvp.Key] = triggerRegions[kvp.Value];
                }

                tempDic.Clear();
                triggerRegions.Clear();

                LKernel.GetG<TriggerReporter>().OnTriggerEnter += OnTriggerEnter;
            }
        }
 /// <summary>
 /// clear our states list and disconnect from the frame started event
 /// </summary>
 void OnLevelUnload(LevelChangedEventArgs eventArgs)
 {
     blenders.Clear();
     states.Clear();
     skeletonEntities.Clear();
     LKernel.GetG<Root>().FrameStarted -= FrameStarted;
 }
Exemple #24
0
        /// <summary>
        /// Dispose all of the sound sources
        /// </summary>
        void OnLevelUnload(LevelChangedEventArgs eventArgs)
        {
            Launch.OnEveryUnpausedTenthOfASecondEvent -= EveryTenth;

            Engine.RemoveAllSoundSources();
            Engine.SetListenerPosition(0, 0, 0, 0, 0, -1);
            musics.Clear();
            sounds.Clear();
            components.Clear();
            components = new HashSet<SoundComponent>();
        }
        /// <summary>
        /// Creates a new basic camera for the viewport to use temporarily while we set everything else up
        /// </summary>
        void OnLevelLoad(LevelChangedEventArgs eventArgs)
        {
            BasicCamera basicCamera = new BasicCamera("BasicCamera");
            cameras.Add(basicCamera);

            SwitchCurrentCamera(basicCamera);
        }
        void OnLevelUnload(LevelChangedEventArgs eventArgs)
        {
            ents.Clear();
            transforms.Clear();

            var sceneMgr = LKernel.GetG<SceneManager>();
            foreach (InstancedGeometry ig in igeoms.Values) {
                sceneMgr.DestroyInstancedGeometry(ig);
                ig.Dispose();
            }
            igeoms.Clear();
        }
 void OnLevelPreUnload(LevelChangedEventArgs eventArgs)
 {
     countGui.Visible = false;
 }
 /// <summary>
 /// Clean up all of the regions when we unload a level
 /// </summary>
 void OnLevelUnload(LevelChangedEventArgs args)
 {
     foreach (TriggerRegion tr in Regions.Values) {
         tr.Dispose();
     }
     Regions.Clear();
 }
Exemple #29
0
 void OnLevelUnload(LevelChangedEventArgs eventArgs)
 {
     // unhook from to the trigger regions
     if (eventArgs.OldLevel.Name == "SweetAppleAcres") {
         var triggerReporter = LKernel.GetG<TriggerReporter>();
         triggerReporter.RemoveEvent("AITriggerRegion1", CrossFinishLine);
         triggerReporter.RemoveEvent("AITriggerRegion28", Halfway);
     }
 }
        /// <summary>
        /// Enumerates through our resource group paths and finds all of the .bullet files
        /// </summary>
        void OnLevelLoad(LevelChangedEventArgs eventArgs)
        {
            bulletFiles = new Dictionary<string, string>();

            #if !DEBUG
            foreach (string group in ResourceGroupManager.Singleton.GetResourceGroups().Where(s => ResourceGroupManager.Singleton.IsResourceGroupInitialised(s))) {
                if (group == "Bootstrap")
                        continue;

                var resourceLocations = ResourceGroupManager.Singleton.ListResourceLocations(group);

                foreach (string loc in resourceLocations) {
                    var scripts = Directory.EnumerateFiles(loc, "*.bullet", SearchOption.TopDirectoryOnly);

                    foreach (string file in scripts) {
                        bulletFiles[Path.GetFileNameWithoutExtension(file)] = file;
                    }
                }
            }
            #else
            var files = Directory.EnumerateFiles("media/", "*.bullet", SearchOption.AllDirectories);
            foreach (string file in files) {
                bulletFiles[Path.GetFileNameWithoutExtension(file)] = file;
            }
            #endif
        }