示例#1
0
    void SetupChain()
    {
        Destroy(targetObject);

        GemScript[] availableGems = FindObjectsOfType <GemScript>();
        minDist     = 999999f;
        selectedGem = null;

        for (int i = 0; i < availableGems.Length; i++)
        {
            if (availableGems[i] != null)
            {
                Vector3 dist = availableGems[i].transform.position - transform.position;
                if (dist.magnitude < minDist)
                {
                    minDist     = dist.magnitude;
                    selectedGem = availableGems[i];
                }
            }
        }

        spawnedChain = Instantiate <GameObject>(chainPrefab);
        GameObject snd = Instantiate <GameObject>(soundPrefab);

        snd.GetComponent <SFXScript>().sfx = hitSFX;
    }
    void Update()
    {
        if (!MenuController.isGameActive())
        {
            return;
        }

        modifiers.ForEach(m =>
        {
            if (m.timer < 0)
            {
                modifiers.Remove(m);
            }
        });
        this.flowerManager.flowers.ForEach(flower =>
        {
            flower.FlyToFrog(this.frogScript.gameObject);
            if (flower.hitsFrog(this.frogScript.gameObject))
            {
                this.dymek.gameObject.SetActive(true);
                this.dymek.GetComponent <Animator>().Play(0);
                this.flowerManager.RemoveFlower(flower);
                float happinesToDeal = flower.Happines;
                modifiers.ForEach(m => { happinesToDeal *= m.modifier; });
                Debug.Log(happinesToDeal);
                this.frogScript.TakeFlowers(happinesToDeal);
            }
        });

        this.lootSpawner.coins.ForEach(coin =>
        {
            if (coin.GetComponent <CoinScript>().hitsCounter())
            {
                this.playerResourcesScript.IncrementCurrentCoinsNumber();
                this.lootSpawner.RemoveCoin(coin);
            }
        });

        this.lootSpawner.gems.ForEach(gem =>
        {
            GemScript gemScript = gem.GetComponent <GemScript>();
            if (gemScript.hitsDestination())
            {
                this.playerResourcesScript.IncrementCurrentGemsNumber(gemScript.GetGemType());
                this.goToCollectionButton.GetComponent <HighlightableObjectScript>().setHighlightSprite(true);
                this.lootSpawner.RemoveGem(gem);
            }
        });

        if (!frogScript.IsSad())
        {
            lootSpawner.SpawnCoins(frogScript.gameObject);
            lootSpawner.SpawnGems(frogScript.gameObject);
            this.wybuch.gameObject.SetActive(true);
            this.wybuch.GetComponent <Animator>().Play(0);
            ZaboPodmieniarka(rzabkaGiver.ProszemDacRzabke(this.frogScript.transform.position));
        }
    }
 private void Gem(Collider2D collision)
 {
     if (collision.tag == "Collectible")
     {
         GemScript gem = collision.gameObject.GetComponent <GemScript>();
         gem.Collected();
         PermaUIScript.perm.gems          += 1;
         PermaUIScript.perm.gemAmount.text = PermaUIScript.perm.gems.ToString();
     }
 }
示例#4
0
    void OnCollisionEnter(Collision collision)
    {
        if (this.gameObject.transform.position.x > -24)
        {
            Debug.Log("GameOver");
            // hasEnded = true;
            // print(hasEnded);
            Instantiate(particleObject, this.transform.position, Quaternion.identity);
            GameObject[] stop        = GameObject.FindGameObjectsWithTag("stage");
            GameObject   noMoreStage = GameObject.Find("StageManager");
            _stageManagerScript           = noMoreStage.GetComponent <StageManagerScript>();
            _stageManagerScript.countDown = 200000;

            GameObject[] gemsStop   = GameObject.FindGameObjectsWithTag("gem");
            GameObject   gemManager = GameObject.Find("GemManager");

            Destroy(collision.gameObject);
            foreach (var gems in gemsStop)
            {
                _gemScript       = gemManager.GetComponent <GemScript>();
                _gemScript.speed = 0;
                _gemScript.count = 200000;
            }

            foreach (var stage in stop)
            {
                _stageMoveScript       = stage.GetComponent <StageMoveScript>();
                _stageMoveScript.speed = 0;
            }

            // Destroy(this.gameObject);
            GameObject childParticle = GameObject.Find("ParticleOnPlayer");
            Destroy(childParticle);
            _rb            = GameObject.Find("Cube").GetComponent <Rigidbody>();
            _rb.useGravity = false;


            GameObject cubeScore = GameObject.Find("Cube");
            _playerScript = cubeScore.GetComponent <PlayerScript>();

            _playerScript.hasEnded = true;
            if (highScore < _playerScript.score)
            {
                highScore = _playerScript.score;

                PlayerPrefs.SetInt("SCORE", highScore);
                PlayerPrefs.Save();
            }

            // print("your highscore: " + highScore);

            print(PlayerPrefs.GetInt("SCORE", highScore));
        }
    }
示例#5
0
    private void Start()
    {
        walls  = GameObject.FindGameObjectWithTag("Wall").GetComponent <PolygonCollider2D>();
        height = Camera.main.orthographicSize - 2f;
        width  = (height * Camera.main.aspect) - 2f;

        for (int i = 0; i < initialNumberOfGems; i++)
        {
            GemScript myGem = UnityEngine.Object.Instantiate(Gem, getSpawnLocation(walls, width, height, maxAttempts), Quaternion.identity).GetComponent <GemScript>();
            myGem.Initialize(getValue());
        }
    }
示例#6
0
    private void spawnNewGem(bool isRed, Vector2 gemPos, float value)
    {
        if (height >= 3f)
        {
            height -= gemConcentration;
        }
        if (width >= 3f)
        {
            width -= gemConcentration;
        }
        GemScript myGem = UnityEngine.Object.Instantiate(Gem, getSpawnLocation(walls, width, height, maxAttempts), Quaternion.identity).GetComponent <GemScript>();

        myGem.Initialize(getValue());
    }
示例#7
0
 private void Awake()
 {
     Instance = this;
     if (PlayerPrefs.HasKey("TotalGems"))
     {
         TotalGems = PlayerPrefs.GetInt("TotalGems");
     }
     else
     {
         TotalGems = 0;
         PlayerPrefs.SetInt("TotalGems", TotalGems);
         PlayerPrefs.Save();
     }
 }
示例#8
0
 // Use this for initialization
 private void Start()
 {
     gemScript = GetComponent <GemScript>();
     PlayerCollisions.OnGemCollected += Collect;
 }
示例#9
0
 public void updateGemCollision(GemScript gem)
 {
     gameManager.GemPickUp(gem.getColor());
 }
    //private void FixedUpdate()
    //{
    //       if (levelPassed){
    //           Debug.Log("Level Passed");
    //       }
    //}
    private void OnTriggerEnter2D(Collider2D collision)
    {
        // If the collision object is a gem, picks it up and marks the
        // gem boolean as true.
        GemScript gem = collision.gameObject.GetComponent <GemScript>();

        if (gem != null)
        {
            power_acquired = true;
            Animator goalAni = goal.GetComponent <Animator>();
            if (goalAni != null)
            {
                goalAni.SetBool("goalReached", true);
            }
            // TODO implement what happens when power_acquired is true.
            Destroy(gem.gameObject);
        }

        // If the player touches the goal, first check if player has the gem
        // If the player has the gem, then level is cleared.
        // If not, then throw some kind of message to remind player to pick
        // up the gem.
        GoalScript goal1 = collision.gameObject.GetComponent <GoalScript>();

        if (goal1 != null)
        {
            if (power_acquired)
            {
                Collider2D goalCol = goal.GetComponent <Collider2D>();
                // TODO Player animation of goal reached
                levelPassed     = true;
                goalCol.enabled = false;
            }
        }

        // If the player touches hell fire before the player successfully
        // kills it with water, the player dies. Instantly.
        FireScript fire = collision.gameObject.GetComponent <FireScript>();

        if (fire != null)
        {
            GetComponent <HealthScript>()
            .Damage(GetComponent <HealthScript>().hp);
            foreach (GameObject heart in hearts)
            {
                if (heart != null)
                {
                    Destroy(heart);
                }
            }
        }

        // Checks if the player bumps into an enemy and reduces hp for both
        // sides accordingly.
        bool        damagePlayer = false;
        EnemyScript enemy        = collision.gameObject.GetComponent <EnemyScript>();

        if (enemy != null)
        {
            HealthScript enemyHealth = enemy.GetComponent <HealthScript>();
            if (enemyHealth != null)
            {
                enemyHealth.Damage(1);
            }
            damagePlayer = true;
        }

        if (damagePlayer)
        {
            HealthScript playerHealth = this.GetComponent <HealthScript>();
            if (playerHealth != null)
            {
                playerHealth.Damage(1);

                // Destroys one heart if player is damaged by 1.
                Destroy(hearts[playerHealth.hp]);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        PlanetScript planet     = GetComponent <GemScript>().GetPlanet();
        float        maxGemDist = 10f;

        if (planet != null)
        {
            Vector2 towardsPlanet = planet.transform.position - transform.position;
            GetComponent <Rigidbody2D>().velocity = GetComponent <Rigidbody2D>().velocity + towardsPlanet.normalized * Time.deltaTime * GetComponent <Rigidbody2D>().mass;
        }
        if (targetPlanet == null)
        {
            SpawnExplosion();
            ScoreTimerScript sts = FindObjectOfType <ScoreTimerScript>();
            sts.AddScore(15000 / sts.GetScoreScale());
            Destroy(this.gameObject);
        }

        if (state == 0)
        {
            spr.sprite  = frames[0];
            stateTimer += Time.deltaTime;
            if (stateTimer > 0.5f)
            {
                Vector3 addition = transform.up * 250f / 30f + transform.right * -100f / 30f;
                GetComponent <Rigidbody2D>().velocity += new Vector2(addition.x, addition.y);
                if (planet != null)
                {
                    GetComponent <Rigidbody2D>().velocity += GetComponent <Rigidbody2D>().velocity *3f / (transform.position - planet.transform.position).magnitude;
                }
                stateTimer = 0f;
                state      = 1;

                GameObject snd = Instantiate <GameObject>(soundPrefab);
                snd.GetComponent <SFXScript>().sfx = jumpSound;
            }
            if (planet != null)
            {
                float angleBetween = Vector3.SignedAngle(transform.up, transform.position - planet.transform.position, new Vector3(0f, 0f, 1f));
                transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), angleBetween * Time.deltaTime * 6f);
                GetComponent <Rigidbody2D>().velocity /= (transform.position - planet.transform.position).magnitude;
            }

            GemScript[] allGems = FindObjectsOfType <GemScript>();
            float       dist    = maxGemDist;
            for (int i = 0; i < allGems.Length; i++)
            {
                float gemDist = (transform.position - allGems[i].transform.position).magnitude;
                if (allGems[i] != null && allGems[i].shape == 0 && gemDist < dist)
                {
                    dist   = gemDist;
                    redGem = allGems[i];
                }
            }
            if (redGem != null)
            {
                state      = 2;
                stateTimer = 0f;

                GameObject snd = Instantiate <GameObject>(soundPrefab);
                snd.GetComponent <SFXScript>().sfx = angrySound;
            }
        }
        if (state == 1)
        {
            spr.sprite  = frames[3];
            stateTimer += Time.deltaTime;
            if (stateTimer > 1.2f)
            {
                state      = 0;
                stateTimer = 0f;
            }
            if (planet != null)
            {
                float angleBetween = Vector3.SignedAngle(transform.up, transform.position - planet.transform.position, new Vector3(0f, 0f, 1f));
                transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), angleBetween * Time.deltaTime * 6f);
            }
        }
        if (state == 2)
        {
            float changeTime = 0.5f;
            spr.sprite = frames[2];
            if (stateTimer < changeTime * 2f / 3f)
            {
                spr.sprite = frames[1];
            }
            stateTimer += Time.deltaTime;
            if (redGem == null || (transform.position - redGem.transform.position).magnitude > maxGemDist)
            {
                state      = 0;
                stateTimer = 0f;
                redGem     = null;
            }
            else
            {
                float angleBetween = Vector3.SignedAngle(transform.up, redGem.transform.position - transform.position, new Vector3(0f, 0f, 1f));
                transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), angleBetween);
                if (stateTimer > changeTime)
                {
                    state      = 3;
                    stateTimer = 0f;
                }
            }
        }
        if (state == 3)
        {
            spr.sprite = frames[4];
            if (redGem == null || (transform.position - redGem.transform.position).magnitude > maxGemDist)
            {
                state      = 0;
                stateTimer = 0f;
                redGem     = null;
            }
            else
            {
                float angleBetween = Vector3.SignedAngle(transform.up, redGem.transform.position - transform.position, new Vector3(0f, 0f, 1f));
                transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), angleBetween);
                Vector3 addition = transform.up * Time.deltaTime * 20f;
                GetComponent <Rigidbody2D>().velocity += new Vector2(addition.x, addition.y);
            }
        }
    }
示例#12
0
    // Update is called once per frame
    void Update()
    {
        stateTimer += Time.deltaTime;

        if (transform.localScale.x < 0.85f)
        {
            transform.localScale = new Vector3(1f, 1f, 1f) * (transform.localScale.x + Time.deltaTime);
        }
        if (transform.localScale.x > 0.85f)
        {
            transform.localScale = new Vector3(1f, 1f, 1f) * 0.85f;
        }

        if (state == 0)
        {
            GetComponent <SpriteRenderer>().sprite = frames[0];
            GetComponent <Rigidbody2D>().velocity  = Vector3.right * Mathf.Cos(stateTimer * 1f) * 0.5f;
            Vector3 vel3         = new Vector3(GetComponent <Rigidbody2D>().velocity.normalized.x, GetComponent <Rigidbody2D>().velocity.normalized.y, 0f);
            float   angleBetween = Vector3.SignedAngle(transform.up, Vector3.up + vel3 * 0.75f, new Vector3(0f, 0f, 1f));
            transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), angleBetween * Time.deltaTime * 3f);
            if (stateTimer > 5f)
            {
                state      = 1;
                stateTimer = 0f;
                GameObject selectedPrefab = bombPrefab;
                spell = false;
                if (Random.Range(0f, 100f) < 25f)
                {
                    selectedPrefab = skullPrefab;
                    spell          = true;
                }
                createdSpell = Instantiate <GameObject>(selectedPrefab);
                createdSpell.transform.SetParent(this.transform);
                createdSpell.transform.position   = spellRef.transform.position;
                createdSpell.transform.rotation   = spellRef.transform.rotation;
                createdSpell.transform.localScale = spellRef.transform.localScale;
                createdSpell.GetComponent <PolygonCollider2D>().enabled = false;

                GameObject snd = Instantiate <GameObject>(soundPrefab);
                snd.GetComponent <SFXScript>().sfx = prepareSpell;
            }
        }
        else if (state == 1)
        {
            GetComponent <SpriteRenderer>().sprite = frames[1];
            GetComponent <Rigidbody2D>().velocity  = GetComponent <Rigidbody2D>().velocity.normalized;
            if (createdSpell != null)
            {
                createdSpell.transform.position   = spellRef.transform.position;
                createdSpell.transform.rotation   = spellRef.transform.rotation;
                createdSpell.transform.localScale = spellRef.transform.localScale;
                createdSpell.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            }
            Transform target = null;
            if (spell)
            {
                CannonScript cs = FindObjectOfType <CannonScript>();
                if (cs != null)
                {
                    target = cs.transform;
                }
            }
            else
            {
                float       minDist = 999999f;
                GemScript   gem     = null;
                GemScript[] allGems = FindObjectsOfType <GemScript>();
                foreach (GemScript gs in allGems)
                {
                    if (gs != null && (gs.transform.position - transform.position).magnitude < minDist)
                    {
                        minDist = (gs.transform.position - transform.position).magnitude;
                        gem     = gs;
                    }
                }
                if (gem != null)
                {
                    target = gem.transform;
                }
            }
            if (target != null)
            {
                float angleBetween = Vector3.SignedAngle(-transform.up, target.position - transform.position, new Vector3(0f, 0f, 1f));
                transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), angleBetween * Time.deltaTime * 6f);
            }
            if (stateTimer > 1.5f)
            {
                state      = 2;
                stateTimer = 0f;
                if (createdSpell != null)
                {
                    createdSpell.GetComponent <PolygonCollider2D>().enabled = true;
                    createdSpell.transform.SetParent(null);
                    if (target == null)
                    {
                        createdSpell.GetComponent <Rigidbody2D>().velocity = transform.up * -6f;
                    }
                    else
                    {
                        createdSpell.GetComponent <Rigidbody2D>().velocity = (target.position - createdSpell.transform.position) * 6f;
                    }
                    createdSpell = null;
                }

                GameObject snd = Instantiate <GameObject>(soundPrefab);
                snd.GetComponent <SFXScript>().sfx = castSpell;
            }
        }
        else
        {
            GetComponent <Rigidbody2D>().velocity  = Vector2.zero;
            GetComponent <SpriteRenderer>().sprite = frames[2];
            transform.position -= (transform.position * Time.deltaTime * 0.75f);
            if (stateTimer > 1.5f)
            {
                state      = 0;
                stateTimer = 0f;
            }
        }
    }
示例#13
0
 public void EndChain()
 {
     selectedGem = null;
 }