private void LoseLevel() { Debug.Log("LOSE!"); state = State.Disabled; GameUI.I.SetWinText(false); CRManager.CallAfterTime(2f, () => { //GoTomMenu(); RetryLevel(); }); }
private void WinLevel() { Debug.Log("WIN!"); state = State.Disabled; PlayerPrefs.SetInt("Best_" + currLevelIdx, turn); GameUI.I.SetWinText(true); CRManager.CallAfterTime(2f, () => { GoTomMenu(); }); }
/// <summary> /// Enters the player into the subworld of the given ID. /// If the given subworld is the one the player is already in, leave the subworld <see cref="WorldManager.LeaveSubworld"/> /// Unloads world chunks /// </summary> /// <param name="id"></param> public void EnterSubworld(int id) { //Collect subworld based on its ID Subworld sub = World.GetSubworld(id); //Check for null if (sub == null) { Debug.Error("Subworld of ID '" + id + "' could not be found"); return; } if (sub == CurrentSubworld) { LeaveSubworld(); return; } //If the subworld doesn't have an entrance, set its entrance as the current player position. if (sub.InternalEntrancePos == null) { Debug.Error("Subworld " + sub.ToString() + " has no WorldEntrance, Player position " + Player.Position + " has been set"); sub.SetWorldEntrance(Vec2i.FromVector3(Player.Position)); } if (CurrentSubworld != null) { Debug.Error("Cannot enter a subworld while already in one."); return; } if (sub != null) { Debug.Log("Player entering subworld " + sub.ToString(), Debug.NORMAL); //First unload all world chunks and set the current subworld CurrentSubworld = sub; //EntityManager.Instance?.UnloadAllChunks(); //Load all subworld chunks and add them to the the relevent list CRManager.LoadSubworldChunks(sub); //GameManager.PathFinder.LoadSubworld(sub); //Inform entity manager we are entering the sub world, then teleport player to correct position. Player.SetPosition(sub.InternalEntrancePos.AsVector3()); WaitAndPathScanCoroutine(); EntityManager.Instance?.EnterSubworld(sub); //PlayerManager.Instance.ProceduralGridMover.UpdateGraph(); } }
/// <summary> /// Called when a player leaves a Sub World. /// Unloads all the chunks in the sub world, and sets the players position back /// to the world entrance. /// </summary> public void LeaveSubworld() { Debug.Log("leaving subworld"); if (CurrentSubworld != null) { foreach (LoadedChunk c in SubworldChunks) { Destroy(c.gameObject); } CRManager.LeaveSubworld(); Player.SetPosition(CurrentSubworld.WorldEntrance); CurrentSubworld = null; LoadedChunksCentre = null; GameManager.EntityManager.LeaveSubworld(); } }
/// <summary> /// Called when a player leaves a Sub World. /// Unloads all the chunks in the sub world, and sets the players position back /// to the world entrance. /// </summary> public void LeaveSubworld() { Debug.Log("leaving subworld"); if (CurrentSubworld != null) { EntityManager.Instance?.LeaveSubworld(); CRManager.LeaveSubworld(); Player.SetPosition(CurrentSubworld.ExternalEntrancePos.AsVector3()); WaitAndPathScanCoroutine(); //CurrentSubworld = null; LoadedChunksCentre = null; CurrentSubworld = null; //Rescan pathfinding } }
public InputWaiter(string CRsID) { if (!CRManager.IsConnected(CRsID)) { if (MessageBox.Show("נראה שהקורא כרטיסים אינו מחובר, האם ברצונך להמשיך בכל זאת?", "שגיאה", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) { Dispose(); return; } } this.InsertedCRsID = CRsID; InitializeComponent(); id = new InputDevice(Handle); id.KeyPressed += new InputDevice.DeviceEventHandler(m_KeyPressed); }
/// <summary> /// Destroys the object at the given point /// TODO - make sure multi-tile objects are destroyed correctly. /// TODO - make sure objects with listeners (inventory that destroy on empty) have lsiteners removed correctly /// </summary> /// <param name="worldPos"></param> public void DestroyWorldObject(Vec2i worldPos) { Vec2i chunkPos = World.GetChunkPosition(worldPos); ChunkData c = CRManager.GetChunk(chunkPos); c.SetObject(worldPos.x, worldPos.z, null); //c.Objects[worldPos.x % World.ChunkSize, worldPos.z % World.ChunkSize] = null; LoadedChunk loaded = CRManager.GetLoadedChunk(chunkPos); Debug.Log("Destroy: " + worldPos); if (loaded != null) { if (loaded.LoadedWorldObjects[worldPos.x % World.ChunkSize, worldPos.z % World.ChunkSize] != null) { Destroy(loaded.LoadedWorldObjects[worldPos.x % World.ChunkSize, worldPos.z % World.ChunkSize].gameObject); loaded.LoadedWorldObjects[worldPos.x % World.ChunkSize, worldPos.z % World.ChunkSize] = null; } } }
/// <summary> /// Adds the given world object to the given world position. /// If the object is placed in a loaded chunk, then we load the object into the game /// </summary> /// <param name="worldPos"></param> /// <param name="worldObject"></param> public void AddNewObject(WorldObjectData worldObject) { //Get relevent chunk of object placement. Vec2i chunkPos = World.GetChunkPosition(worldObject.WorldPosition); ChunkData c = CRManager.GetChunk(chunkPos); Vec2i localPos = new Vec2i(worldObject.WorldPosition.x % World.ChunkSize, worldObject.WorldPosition.z % World.ChunkSize); c.SetObject(localPos.x, localPos.z, worldObject); //Check if the object has been added to a loaded chunk LoadedChunk loaded = CRManager.GetLoadedChunk(chunkPos); if (loaded != null) { WorldObject newObject = worldObject.CreateWorldObject(loaded.transform); loaded.LoadedWorldObjects[localPos.x, localPos.z] = newObject; } }
private void m_KeyPressed(object sender, InputDevice.KeyControlEventArgs e) { if (DateTimeExtensions.ApplicationIsActivated(Process.GetCurrentProcess().Id) && e.Keyboard.deviceName == InsertedCRsID && CRManager.IsConnected(InsertedCRsID)) { if (skip) { Console.WriteLine(e.Keyboard.vKey + ":" + e.Keyboard.key); if (e.Keyboard.vKey == Keys.Enter.ToString()) { SystemSounds.Beep.Play(); id.KeyPressed -= m_KeyPressed; Close(); } } skip = !skip; } else { Output = String.Empty; skip = false; } }