public void DropGem() { this.skyPiece = null; this.SetSize(0f, 0f); this.GetFractionLabel().Hide(); }
// TODO: Validate results /// <summary> /// Absorbs a SkyFragmentPiece and adds its value back to it. /// Also destroy the piece here. /// </summary> /// <param name="piece">Sky Fragment</param> public void Absorb(SkyFragmentPiece piece) { // If empty, set numerator and denominator as the absorbed piece's // if (this.GetNumerator() == 0) { // this.SetNumerator (piece.GetNumerator()); // this.SetDenominator (piece.GetDenominator()); // } // // Else get the LCD and update the value by adding the current value // // with the absorbed piece's value // else { int lcd = General.LCD((int)this.GetDenominator(), (int)piece.GetDenominator()); // float lcdPieceNumVal = piece.GetDenominator () / lcd * piece.GetNumerator (); // float lcdBlockNumeratorVal = this.GetDenominator () / lcd * this.GetNumerator (); float lcdPieceNumVal = lcd / piece.GetDenominator() * piece.GetNumerator(); float lcdBlockNumeratorVal = lcd / this.GetDenominator() * this.GetNumerator(); float newNum = lcdPieceNumVal + lcdBlockNumeratorVal; this.SetNumerator((int)newNum); this.SetDenominator(lcd); float[] results = General.SimplifyFraction(this.GetNumerator(), this.GetDenominator()); this.SetNumerator(results[0]); this.SetDenominator(results[1]); // } this.skyFragmentPieces.Remove(piece); Destroy(piece.gameObject); }
/// <summary> /// Carries the overlapping piece. /// </summary> /// <returns></returns> public void Carry() { if (this.carriedPiece == null || this.lastPiece != this.GetSkyGem().GetOverlappingPiece()) { if ( /*this.player.GetPlayerAttack().HasNeedle() &&*/ this.GetSkyGem().GetOverlappingPiece() != null && !this.GetSkyGem().GetOverlappingPiece().IsAssigned()) { //&& // (this.lastPiece != this.GetSkyGem ().GetOverlappingPiece ()) || // this.lastPiece != null) { // if (this.carriedPiece == null || // this.lastPiece != this.GetSkyGem ().GetOverlappingPiece ()) { SoundManager.Instance.Play(AudibleNames.Room.PICKUP_FRAGMENT, false); this.lastPiece = null; this.player.CarryGemItem(); this.carriedPiece = this.GetSkyGem().GetOverlappingPiece(); Vector3 liftedOffset = new Vector3(0f, // carriedPiece.GetHeight()+(carriedPiece.GetHeight()/2)+yPadding, player.GetLiftedPiecePosition().localPosition.y, 0f); this.carriedPiece.Carry(gameObject, liftedOffset); this.PostCarryEvent(this.carriedPiece); // } } } }
/// <summary> /// Posts a carry event. /// </summary> /// <param name="carriedPiece"></param> /// <returns></returns> public void PostCarryEvent(SkyFragmentPiece carriedPiece) { Parameters parameters = new Parameters(); parameters.PutObjectExtra(SkyFragmentPieceUI.SKY_PIECE, carriedPiece); EventBroadcaster.Instance.PostEvent(EventNames.ON_PLAYER_GEM_CARRY, parameters); }
/// <summary> /// Setter function that sets the overlappine piece. /// </summary> /// <param name="skyPiece"></param> /// <returns></returns> public void SetOverlappingPiece(SkyFragmentPiece skyPiece) { if (this.overlappingPiece != null) { this.overlappingPiece.Unobserve(); } // If gem piece distance is less than sky piece distance if (skyPiece != null && Physics2D.Distance(this.GetComponent <Collider2D> (), skyPiece.GetComponent <Collider2D> ()).distance < this.GetPlayer().GetLiftOverlapDistance()) { this.GetPlayer().UnobserveLift(); this.overlappingPiece = skyPiece; // if (this.overlappingPiece != null) { this.overlappingPiece.Observe(); EventBroadcaster.Instance.PostEvent(EventNames.SHOW_PLAYER_CARRY); // } } else { if (skyPiece != null) { skyPiece.Unobserve(); } this.overlappingPiece = null; // EventBroadcaster.Instance.PostEvent (EventNames.HIDE_PLAYER_CARRY); } // this.GetPlayer ().CheckOverlap (); this.BroadcastOverlappingPiece(); }
// Must be Ground // [SerializeField] private Collider2D collider2D; // [SerializeField] private PlayerYuni player; // void Awake() { // this.collider2D = GetComponent<Collider2D> (); // } void OnCollisionStay2D(Collision2D other) { // Debug.Log ("<color=white>LOCK COLLISION</color> "+other.collider.gameObject.name); if (other.collider.gameObject.GetComponent <SkyFragmentPiece> () != null) { SkyFragmentPiece skyPiece = other.gameObject.GetComponent <SkyFragmentPiece> (); if (!skyPiece.IsCarried() && !skyPiece.IsAssigned()) { skyPiece.LockPiece(this); } if (skyPiece.IsCarried()) { skyPiece.UnlockPiece(this); } } if (other.collider.gameObject.GetComponent <HollowBlock> () != null) { HollowBlock hollowBlock = other.gameObject.GetComponent <HollowBlock> (); if (!hollowBlock.IsCarried() && hollowBlock.gameObject.transform.parent.GetComponent <PlayerYuni>() == null && hollowBlock.GetRigidBody2D().velocity == Vector2.zero) { hollowBlock.LockPiece(this); } else { hollowBlock.UnlockPiece(this); } } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag(Tags.SKY_FRAGMENT_PIECE)) { this.skyFragmentPiece = other.gameObject.GetComponent <SkyFragmentPiece> (); } }
public SkyFragmentPiece GetSkyPiece() { if (this.skyPiece == null) { this.skyPiece = GetComponentInParent <SkyFragmentPiece> (); } return(this.skyPiece); }
void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.CompareTag(Tags.SKY_FRAGMENT_PIECE)) { SkyFragmentPiece piece = other.gameObject.GetComponent <SkyFragmentPiece> (); piece.transform.position = piece.GetDetachedManagerParent().transform.position; } }
/// <summary> /// Absorb a sky fragment. Fills this ghost block. /// /// Once the sky fragments add up to the ghost block's value, the ghost block will be filled. /// </summary> /// <param name="skyPiece">Sky Fragment</param> public void Absorb(SkyFragmentPiece skyPiece) { if (!isSolved) { this.GetSkyPieceContainer().Absorb(skyPiece); this.UpdateStabilityLabel(); this.CheckStability(); } }
// public void CheckOverlappingPiece(Parameters parameters) { // SkyFragmentPiece overlappingPiece = parameters.GetObjectExtra (OVERLAPPING_PIECE) as SkyFragmentPiece; // // Hide if not overlapping piece // if (!this.SamePiece(this.GetSkyPiece(), overlappingPiece)) { // if (this.isOpen) { // this.GetBubbleManager().HideHint(); // } // } // } public bool SamePiece(SkyFragmentPiece skyPiece, SkyFragmentPiece overlappingPiece) { if (overlappingPiece != null && skyPiece == overlappingPiece) { return(true); } else { return(false); } }
private void UnusedBlockPlace() { for (int i = 0; i < piecesUnused; i++) { SkyFragmentPiece piece = fragmentCatcher.pieces.Pop(); if (piece != null) { piece.gameObject.SetActive(true); piece.transform.position = placement.transform.position; } } }
/// <summary> /// Releases the carried piece and posts a drop event. /// </summary> /// <returns></returns> public void Release() { if (this.carriedPiece != null) { this.player.DropGemItem(); this.lastPiece = this.carriedPiece; this.carriedPiece.gameObject.transform.position = this.player.GetDropPiecePosition().position; this.carriedPiece.Drop(); this.carriedPiece = null; SoundManager.Instance.Play(AudibleNames.Room.PICKUP_FRAGMENT, false); EventBroadcaster.Instance.PostEvent(EventNames.ON_PLAYER_GEM_DROP); } }
private void WrongBlockAbsorb() { for (int i = 0; i < piecesForWrongBlock; i++) { SkyFragmentPiece piece = fragmentCatcher.pieces.Pop(); if (piece != null && !piece.IsCarried()) // TODO { piece.gameObject.SetActive(true); wrongHollowBlock.Absorb(piece); } } }
private void ReturnPieces() { for (int i = 0; i < piecesReturned; i++) { SkyFragmentPiece piece = fragmentCatcher.pieces.Pop(); if (piece != null) { piece.gameObject.SetActive(true); // piece.Break (); skyBlock.Absorb(piece); } } }
void OnCollisionExit2D(Collision2D other) { // Debug.Log ("<color=white>LOCK COLLISION EXIT</color>"); if (other.collider.gameObject.GetComponent <SkyFragmentPiece> () != null) { SkyFragmentPiece skyPiece = other.gameObject.GetComponent <SkyFragmentPiece> (); skyPiece.UnlockPiece(this); } if (other.gameObject.GetComponent <HollowBlock> () != null) { HollowBlock hollowBlock = other.gameObject.GetComponent <HollowBlock> (); hollowBlock.UnlockPiece(this); } }
// For player fragment label public void SkyOverlapUpdate(Parameters parameters) { SkyFragmentPiece overlappingPiece = parameters.GetObjectExtra(OVERLAPPING_PIECE) as SkyFragmentPiece; if (overlappingPiece != null) { this.UpdateLabel((int)overlappingPiece.GetNumerator(), (int)overlappingPiece.GetDenominator()); this.ShowHint(); } else { this.HideHint(); } }
/// <summary> /// Instantiate a sky fragment from the pieceReference prefab. The sky fragment is then parented to the parent game object and assigned a numerator and denominator for its fraction value. /// </summary> /// <param name="parent">Parent (which is usually the sky block game object)</param> /// <param name="numValue">Numerator</param> /// <param name="denValue">Denominator</param> /// <returns></returns> public SkyFragmentPiece CreateSkyFragmentPiece(GameObject parent, int numValue, int denValue) { SkyFragmentPiece holder = SkyFragmentPiece.Instantiate(pieceReference, Vector3.zero, Quaternion.identity); //pieceReference is the sky piece prefab holder.gameObject.transform.SetParent(parent.transform); //parent.transform = detachedmanager of skyblock parent holder.AlignToLocal(Vector3.zero); holder.Initialize(this.skyBlockParent, numValue, denValue); //on load, this.skyBlockParent will be set to the recorded parent skyblock holder.ChangeColor(this.skyBlockParent.GetPieceColor(), this.skyBlockParent.GetPieceOutlineColor()); // brokenPiece.SetSize (pieceWidth, pieceHeight); holder.gameObject.SetActive(true); return(holder); }
public void Absorb(SkyFragmentPiece skyPiece) { skyPiece.DisableRigidBody(); skyPiece.SetHollowBlock(this.GetHollowBlock()); skyPiece.gameObject.transform.SetParent(this.GetContainer().gameObject.transform); skyPiece.SetPreviousParent(this.GetContainer().gameObject.transform); skyPiece.gameObject.transform.localPosition = Vector3.zero; skyPiece.gameObject.transform.eulerAngles = Vector3.zero; skyPiece.WearAttachedSkin(); UpdateSkyPieceList(); UpdateSkyPiecePositions(); UpdateCurrentStability(); }
/// <summary> /// Loads saved scene data, if it exists /// </summary> void LoadSceneData() { if (File.Exists(sceneDataPath)) { string data = File.ReadAllText(sceneDataPath); sceneData = JsonUtility.FromJson <SceneData> (data); if (sceneData.timeSolved != "NONE") { Debug.Log("<color='blue'>TIME SOLVED </color>" + DateTime.Parse(sceneData.timeSolved)); TimeSpan elapsedTime = System.DateTime.Now - DateTime.Parse(sceneData.timeSolved); Debug.Log("<color='blue'>ELAPSED TIME </color>" + elapsedTime); Debug.Log("<color='blue'>ELAPSED TIME </color>" + elapsedTime.TotalMinutes); // if (elapsedTime.TotalMinutes < MAX_MINUTES) { //DO NOT SAVE DATA foreach (HollowBlockData block in sceneData.hollowBlocks) { Debug.Log("Block " + block.name); hollowBlocks [block.id - 1].SetPiecesReturnToSkyBlock(true); hollowBlocks [block.id - 1].Break(); foreach (SkyFragmentData skyFragmentData in block.hollowBlockPieces) { SkyFragmentPiece piece = skyBlocks [skyFragmentData.skyBlockParentID - 1].GetComponentInChildren <SkyFragmentBlock> ().CreateSkyFragmentPiece(skyBlocks [skyFragmentData.skyBlockParentID - 1].GetDetachedManager().gameObject, (int)skyFragmentData.numerator, (int)skyFragmentData.denominator); hollowBlocks [block.id - 1].Absorb(piece); } // if (block.isSolved) // hollowBlocks [block.id - 1].Solved (); } Debug.Log("Disable tutorials"); EventBroadcaster.Instance.PostEvent(EventNames.DISABLE_TUTORIALS); // } else { // Debug.Log ("Reset puzzles"); // } } Debug.Log("Loaded scene data"); } else { // Debug.LogError ("Unable to read the saved data, file doesn't exist"); sceneData = new SceneData(); } }
/// <summary> /// Unity Function. Checks if another game object' collider went in the collider of this game object. /// /// Depending on the flags set to true, certain types of objects will be destroyed/killed. /// </summary> /// <param name="other">Other Game Object's Collider.</param> void OnTriggerEnter2D(Collider2D other) { if (killsPlayer && other.gameObject.GetComponent <PlayerYuni> () != null) { Debug.Log("Entered Player Death"); PlayerHealth player = other.gameObject.GetComponent <PlayerHealth> (); player.isAlive = false; } else if (killsEnemy && other.gameObject.CompareTag(Tags.ENEMY)) { EnemyHealth enemy = other.gameObject.GetComponent <EnemyHealth> (); enemy.Death(); } else if (killsSkyPiece && other.gameObject.CompareTag(Tags.SKY_FRAGMENT_PIECE)) { SkyFragmentPiece piece = other.gameObject.GetComponent <SkyFragmentPiece> (); piece.transform.position = piece.GetDetachedManagerParent().transform.position; } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag(Tags.SKY_FRAGMENT_PIECE)) { SkyFragmentPiece piece = other.gameObject.GetComponent <SkyFragmentPiece> (); if (!pieces.Contains(piece)) { pieces.Push(piece); } piece.gameObject.SetActive(false); if (pieces.Count == expectedPieces) { fragmentChecker.enabled = false; } } }
public void UpdateCarriedGem(Parameters parameters) { SkyFragmentPiece piece = parameters.GetObjectExtra(SKY_PIECE) as SkyFragmentPiece; this.skyPiece = piece; // Safety measure. Should never enter this. if (this.skyPiece == null) { DropGem(); } else { this.SetSize(this.skyPiece.GetWidth(), this.skyPiece.GetHeight()); this.ChangeColor(this.skyPiece.GetFillColor(), this.skyPiece.GetOutlineColor()); this.spriteRenderer.material = skyPiece.GetSpriteRenderer().material; this.GetFractionLabel().Show(); this.SetFractionLabel((int)this.skyPiece.GetNumerator(), (int)this.skyPiece.GetDenominator()); } }
/// <summary> /// Deprecated, trigger should be used. /// </summary> /// <param name="other">Other Game Object's Collider.</param> void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.CompareTag(Tags.PLAYER)) { PlayerHealth player = other.gameObject.GetComponent <PlayerHealth> (); player.isAlive = false; } else if (other.gameObject.CompareTag(Tags.ENEMY)) { EnemyHealth enemy = other.gameObject.GetComponent <EnemyHealth> (); enemy.Death(); } else if (other.gameObject.CompareTag(Tags.SKY_FRAGMENT_PIECE)) { SkyFragmentPiece piece = other.gameObject.GetComponent <SkyFragmentPiece> (); piece.transform.position = piece.GetDetachedManagerParent().transform.position; } // else // Destroy (other.gameObject); }
/// <summary> /// Return detached sky fragments to the sky block. /// </summary> /// <param name="detachedPiece">Sky Fragments</param> public void Absorb(SkyFragmentPiece detachedPiece) { this.attachedFragmentBlock.Absorb(detachedPiece); }
/// <summary> /// Absorbs sky fragments back to this main block. /// Return the value of the detachedFragment to the attachedFragment. /// </summary> /// <param name="detachedFragment"></param> public void Absorb(SkyFragmentPiece detachedFragment) { this.attachedManager.Absorb(detachedFragment); }
public void SetSkyPiece(SkyFragmentPiece fragmentParent) { this.skyPiece = fragmentParent; }
/// <summary> /// Function called upon awake. /// </summary> /// <returns></returns> void Awake() { this.overlappingPiece = null; Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Player"), LayerMask.NameToLayer("SkyGem")); }