コード例 #1
0
    public void DropGem()
    {
        this.skyPiece = null;
        this.SetSize(0f, 0f);

        this.GetFractionLabel().Hide();
    }
コード例 #2
0
    // 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);
    }
コード例 #3
0
ファイル: PlayerGem.cs プロジェクト: KurogamiRyujin/Discord
    /// <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);
                //			}
            }
        }
    }
コード例 #4
0
ファイル: PlayerGem.cs プロジェクト: KurogamiRyujin/Discord
    /// <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);
    }
コード例 #5
0
    /// <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();
    }
コード例 #6
0
    // 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);
            }
        }
    }
コード例 #7
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag(Tags.SKY_FRAGMENT_PIECE))
     {
         this.skyFragmentPiece = other.gameObject.GetComponent <SkyFragmentPiece> ();
     }
 }
コード例 #8
0
 public SkyFragmentPiece GetSkyPiece()
 {
     if (this.skyPiece == null)
     {
         this.skyPiece = GetComponentInParent <SkyFragmentPiece> ();
     }
     return(this.skyPiece);
 }
コード例 #9
0
 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;
     }
 }
コード例 #10
0
 /// <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();
     }
 }
コード例 #11
0
//	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);
        }
    }
コード例 #12
0
 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;
         }
     }
 }
コード例 #13
0
ファイル: PlayerGem.cs プロジェクト: KurogamiRyujin/Discord
 /// <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);
     }
 }
コード例 #14
0
    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);
            }
        }
    }
コード例 #15
0
    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);
            }
        }
    }
コード例 #16
0
    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);
        }
    }
コード例 #17
0
    // 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();
        }
    }
コード例 #18
0
    /// <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);
    }
コード例 #19
0
    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();
    }
コード例 #20
0
    /// <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();
        }
    }
コード例 #21
0
 /// <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;
     }
 }
コード例 #22
0
    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;
            }
        }
    }
コード例 #23
0
    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());
        }
    }
コード例 #24
0
    /// <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);
    }
コード例 #25
0
 /// <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);
 }
コード例 #26
0
ファイル: SkyBlock.cs プロジェクト: KurogamiRyujin/Discord
 /// <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);
 }
コード例 #27
0
 public void SetSkyPiece(SkyFragmentPiece fragmentParent)
 {
     this.skyPiece = fragmentParent;
 }
コード例 #28
0
 /// <summary>
 /// Function called upon awake.
 /// </summary>
 /// <returns></returns>
 void Awake()
 {
     this.overlappingPiece = null;
     Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Player"), LayerMask.NameToLayer("SkyGem"));
 }