public void AddPoints()
 {
     spawner.addChainCount(_spawnChainId);
     if (_isLastInChain && spawner.isFullChainCheck(_spawnChainId))
     {
         playerScore.AddPoints(10 * spawner.getChainAmount(_spawnChainId));
         //playerScore.AddBonus();
     }
     else
     {
         CheckBonusReset();
         playerScore.AddPoints(10);
     }
 }
Beispiel #2
0
    private void HandleDeath()
    {
        if (m_IsDead)
        {
            return;
        }

        // call OnDie action
        if (currentHealth <= 0f)
        {
            if (onDie != null)
            {
                if (gameObject.CompareTag("Enemy"))
                {
                    PlayerScore player = FindObjectOfType <PlayerScore>();
                    player.AddPoints(30);
                    //print("Enemy killed " + player.currentPoints);
                }

                if (gameObject.CompareTag("Player"))
                {
                    PlayerScore player = FindObjectOfType <PlayerScore>();
                    player.DecreasePoints(30);
                    // print("Player died" + player.currentPoints);
                    player.UpdateHighScore();
                }
                m_IsDead = true;
                onDie.Invoke();
            }
        }
    }
Beispiel #3
0
    public void TakeDamage(float damage, GameObject damageSource)
    {
        if (invincible)
        {
            return;
        }

        if (gameObject.CompareTag("Enemy"))
        {
            PlayerScore player = FindObjectOfType <PlayerScore>();
            player.AddPoints(5);
            print("Enemy attacked" + player.currentPoints);
        }

        float healthBefore = currentHealth;

        currentHealth -= damage;
        currentHealth  = Mathf.Clamp(currentHealth, 0f, maxHealth);

        // call OnDamage action
        float trueDamageAmount = healthBefore - currentHealth;

        if (trueDamageAmount > 0f && onDamaged != null)
        {
            onDamaged.Invoke(trueDamageAmount, damageSource);
        }

        HandleDeath();
    }
 public void KillHellSpawnEnemy()
 {
     gameObject.SendMessage("StopFire");
     gameObject.GetComponent <Collider2D>().enabled = false;
     gameObject.GetComponent <Animator>().enabled   = false;
     gameObject.transform.DOKill();
     playerScore.AddPoints(_scorePerLife * enemyLivesStart);
 }
Beispiel #5
0
 private void AddPointsWhenPlayerHasNoAdvantage(PlayerScore player)
 {
     if (player.Points == Points.Forty && PlayerTwo.Points < Points.Forty
         ||
         player.Points == Points.Forty && PlayerOne.Points < Points.Forty)
     {
         player.AddPoints();
     }
 }
Beispiel #6
0
    /// <summary>
    /// Checks in every direction around the centerPos for atleast
    /// 4 animal tiles of the same type in a row. Animal rows that are found
    /// are marked matched at the tile level.
    /// </summary>
    /// <param name="centerPos"></param>
    public void CheckForMatches(IntVector2 centerPos)
    {
        if (!IsValidIndex(centerPos))
        {
            return;
        }
        AnimalTile centerAnimal = GetAnimal(centerPos);

        if (AnimalTile.IsNullOrMoving(centerAnimal))
        {
            return;
        }

        //Match count for each direction.
        int[] matchCounts = { 1, 1, 1, 1, 0, 0, 0, 0 };

        //Count matches found extending out from (x,y) in each direction.
        foreach (SwipeDirection direction in Enum.GetValues(typeof(SwipeDirection)))
        {
            IntVector2 currPos    = GetNextNeighbor(centerPos, direction);
            AnimalTile currAnimal = GetAnimal(currPos);

            //While neighbor in direction is the same as center. Add to count and move to next
            while (!AnimalTile.IsNullOrMoving(currAnimal) && AnimalTile.IsSameType(centerAnimal, currAnimal))
            {
                matchCounts[(int)direction]++;

                currPos    = GetNextNeighbor(currPos, direction);
                currAnimal = GetAnimal(currPos);
            }
        }

        //Only iterate: North, NorthEast, East, SouthEast. The rest can be considered part of these.
        for (int i = 0; i < 4; i++)
        {
            IntVector2     currStartPos  = new IntVector2(centerPos.x, centerPos.y);
            SwipeDirection currDirection = (SwipeDirection)i;
            int            currLength    = 0;

            //Center is not start of match
            SwipeDirection invertedDirection = InputController.InvertDirection(currDirection);

            //Find correct start, and how long it really is.
            currStartPos = GetNextNeighbor(currStartPos, invertedDirection, matchCounts[i + 4]);
            currLength  += matchCounts[i + 4] + matchCounts[i];

            //If the row is 4 or longer and has an unmatched animal in it. Remove it.
            if (currLength >= MinMatch && DoesRowHaveNonMatched(currStartPos, currLength, currDirection))
            {
                IsReady = false;
                //Set them marked in the board. And give player points.
                MarkRowMatched(currStartPos, currLength, currDirection);
                playerScore.AddPoints(currStartPos, currLength, currDirection);
            }
        }
    }
Beispiel #7
0
    void OnTriggerEnter2D(Collider2D co)
    {
        if (co.name == "Joker")
        {
            PlayerScore.AddPoints(pointToAdd);
        }
        EezoScore.AddPoints(eezoToAdd);

        Destroy(gameObject);
    }
Beispiel #8
0
 public void DealDamageToEnemy(short damage)
 {
     _enemyCurrentHP -= damage;
     if (IsDead())
     {
         Points p = gameObject.GetComponent <Points>();
         PlayerScore.AddPoints(p.Amount);
         HUD.UpdateScore();
         Destroy(gameObject);
     }
 }
Beispiel #9
0
    public void Heal(float healAmount)
    {
        float healthBefore = currentHealth;

        currentHealth += healAmount;
        currentHealth  = Mathf.Clamp(currentHealth, 0f, maxHealth);

        // call OnHeal action
        float trueHealAmount = currentHealth - healthBefore;

        if (gameObject.CompareTag("Player"))
        {
            PlayerScore player = FindObjectOfType <PlayerScore>();
            player.AddPoints(5);
            print("Player healed" + player.currentPoints);
        }
        if (trueHealAmount > 0f && onHealed != null)
        {
            onHealed.Invoke(trueHealAmount);
        }
    }
Beispiel #10
0
    void PlayerRaycast()
    {
        RaycastHit2D rayDown = Physics2D.Raycast(transform.position, Vector2.down);

        if (rayDown != null && rayDown.collider != null && rayDown.distance < 2.0f && rayDown.collider.tag == "enemy")
        {
            //Debug.Log("test");
            GetComponent <Rigidbody2D> ().AddForce(Vector2.up * 1000);
            rayDown.collider.gameObject.GetComponent <Rigidbody2D>().AddForce(Vector2.right * 200);
            rayDown.collider.gameObject.GetComponent <Rigidbody2D>().gravityScale   = 8;
            rayDown.collider.gameObject.GetComponent <Rigidbody2D>().freezeRotation = false;
            rayDown.collider.gameObject.GetComponent <BoxCollider2D>().enabled      = false;
            rayDown.collider.gameObject.GetComponent <Enemymove>().enabled          = false;

            score.AddPoints(10);
        }
        if (rayDown != null && rayDown.collider != null && rayDown.distance < 1.2f && rayDown.collider.tag == "ground")
        {
            isGrounded = true;
        }
    }
Beispiel #11
0
    void EndGame(bool win)
    {
        // unlocks the cursor before leaving the scene, to be able to click buttons
        Cursor.lockState = CursorLockMode.None;
        Cursor.visible   = true;

        // Remember that we need to load the appropriate end scene after a delay
        gameIsEnding = true;
        endGameFadeCanvasGroup.gameObject.SetActive(true);
        if (win)
        {
            PlayerScore playerScore = FindObjectOfType <PlayerScore>();
            playerScore.AddPoints(100);
            playerScore.UpdateHighScore();

            m_SceneToLoad          = winSceneName;
            m_TimeLoadEndGameScene = Time.time + endSceneLoadDelay + delayBeforeFadeToBlack;

            // play a sound on win
            var audioSource = gameObject.AddComponent <AudioSource>();
            audioSource.clip                  = victorySound;
            audioSource.playOnAwake           = false;
            audioSource.outputAudioMixerGroup = AudioUtility.GetAudioGroup(AudioUtility.AudioGroups.HUDVictory);
            audioSource.PlayScheduled(AudioSettings.dspTime + delayBeforeWinMessage);

            // create a game message
            var message = Instantiate(WinGameMessagePrefab).GetComponent <DisplayMessage>();
            if (message)
            {
                message.delayBeforeShowing = delayBeforeWinMessage;
                message.GetComponent <Transform>().SetAsLastSibling();
            }
        }
        else
        {
            m_SceneToLoad          = loseSceneName;
            m_TimeLoadEndGameScene = Time.time + endSceneLoadDelay;
        }
    }
Beispiel #12
0
    public void checkAnswer(int buttonNum)
    {
        if (buttonNum == currentQuestion.correctAnswerIndex)
        {
            print("correct");
            //Destroy(gameObject);
            //panelQuest.SetActive(false);
            score.AddPoints(10);
            popup.SetActive(true);
        }
        else
        {
            print("incorrect");
            //panelQuest.SetActive(false);
        }

        if (questionfinished < questionNumbersChoosen.Length - 1)
        {
            movetoNextQuestion();
            panelQuest.SetActive(false);
            questionfinished++;
        }
    }
Beispiel #13
0
 private void AddPointsToPlayer(PlayerScore player)
 {
     player.AddPoints();
 }