示例#1
0
文件: Shooter.cs 项目: Antwnina/Sweet
 void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "Ghost")
     {
         Destroy(collision.gameObject);
         Destroy(GameObject.Find("Bolt(Clone)"), 0.1f);
         GameHandler.AddScore(30);
     }
     if (collision.gameObject.tag == "Bear")
     {
         //Debug.Log(GameHandler.GetBearLifes());
         if (GameHandler.HasBearLifes() && GameHandler.GetBearLifes() > 1)
         {
             GameHandler.ReduceBearLife();
             Destroy(GameObject.Find("Bolt(Clone)"), 0.1f);
         }
         else if (GameHandler.HasBearLifes() && GameHandler.GetBearLifes() == 1)
         {
             GameHandler.ReduceBearLife();
             Destroy(collision.gameObject);
             GameHandler.AddScore(500);
             var particles = GameObject.FindObjectOfType <ParticleSystem>();
             particles.Play();
             Destroy(GameObject.Find("Bolt(Clone)"), 0.1f);
         }
     }
 }
示例#2
0
 public bool TrySnakeEatFood(Vector2Int snakeGridPosition)
 {
     if (snakeGridPosition == foodGridPosition)
     {
         Object.Destroy(foodGameObject);
         SpawnFood();
         GameHandler.AddScore();
         return(true);
     }
     return(false);
 }
示例#3
0
 void OnTriggerEnter2D(Collider2D o) // increase score
 {
     if (o.gameObject.tag == "mushroom")
     {
         GameHandler.AddScore(100);
     }
     if (o.gameObject.tag == "snakehead")
     {
         GameHandler.AddScore(300);
     }
 }
 public bool TryEatFood(Vector2Int snakePosition, bool specialMode)
 {
     if (snakePosition == foodPosition)
     {
         Object.Destroy(foodImg);
         SpawnFood(specialMode);
         GameHandler.AddScore();
         return(true);
     }
     return(false);
 }
示例#5
0
 public bool TrySnakeEatFood(Vector2Int snakeGridPosition)
 {
     if (snakeGridPosition == foodGridPosition)
     {
         Object.Destroy(foodGameObject);
         SpawnFood();
         GameHandler.AddScore();
         // CMDebug.TextPopupMouse("Snake Ate Food!");
         return(true);
     }
     return(false);
 }
示例#6
0
    void Update()
    {
        if (_mode == MonsterMode.Approach)
        {
            Approach();
        }
        else if (_mode == MonsterMode.Attack)
        {
            Attack();
        }
        else if (_mode == MonsterMode.Retreat)
        {
            Retreat();
        }

        if (_damageable.GetHitPoints() == 0 && !_deathBehaviour.enabled)
        {
            _deathBehaviour.enabled = true;
            GameHandler.AddScore(PointsWhenKilled);
        }
    }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.x > Ship.instance.transform.position.x)
        {
            _facing.Set(Facing.Direction.Left);
        }
        else
        {
            _facing.Set(Facing.Direction.Right);
        }


        if (_mode == MonsterMode.Approach)
        {
            Approach();
        }

        if (_damageable.GetHitPoints() == 0 && !_deathBehaviour.enabled)
        {
            _deathBehaviour.enabled = true;
            GetComponent <FloatingObject>().isFloating = false;
            GameHandler.AddScore(PointsWhenKilled);
        }
    }
示例#8
0
    public bool TrySnakeEatFood(Vector2Int snakeGridPosition)
    {
        // If snake took food0
        if (snakeGridPosition == foodGridPositionArr[0])
        {
            GameSound.PlayGoodFoodSound();
            Object.Destroy(foodGameObjectArr[0]);
            SpawnFood0();
            GameHandler.AddScore(10);
            GameHandler.AddProgressBar();
            GameHandler.SetProgressImage("Good");
            return(true);
        }
        foodTimerArr[0]--;
        if (foodTimerArr[0] <= 0 && (!stopSpawningFoods))   //Relocate food0
        {
            Object.Destroy(foodGameObjectArr[0]);
            SpawnFood0();
            foodTimerArr[0] = 31;
        }


        // If snake took food1
        if (snakeGridPosition == foodGridPositionArr[1])
        {
            GameSound.PlayGoodFoodSound();
            Object.Destroy(foodGameObjectArr[1]);
            SpawnFood1();
            GameHandler.AddScore(10);
            GameHandler.AddProgressBar();
            GameHandler.SetProgressImage("Good");
            return(true);
        }

        foodTimerArr[1]--;
        if (foodTimerArr[1] <= 0 && (!stopSpawningFoods))    //Relocate food1
        {
            Object.Destroy(foodGameObjectArr[1]);
            SpawnFood1();
            foodTimerArr[1] = 22;
        }

        // If snake took Bad food0
        if (snakeGridPosition == badFoodGridPositionArr[0])
        {
            GameSound.PlayBadFoodSound();
            Object.Destroy(badFoodGameObjectArr[0]);
            SpawnBad0();
            GameHandler.ReduceScore(10);
            GameHandler.ReduceProgressBar();
            GameHandler.SetProgressImage("Bad");
            return(true);
        }
        badFoodTimerArr[0]--;
        if (badFoodTimerArr[0] <= 0 && (!stopSpawningFoods))  //Relocate bad food0
        {
            Object.Destroy(badFoodGameObjectArr[0]);
            SpawnBad0();
            badFoodTimerArr[0] = 28;
        }

        // If snake took Bad food1
        if (snakeGridPosition == badFoodGridPositionArr[1])
        {
            GameSound.PlayBadFoodSound();
            Object.Destroy(badFoodGameObjectArr[1]);
            SpawnBad1();
            GameHandler.ReduceScore(10);
            GameHandler.ReduceProgressBar();
            GameHandler.SetProgressImage("Bad");
            return(true);
        }

        badFoodTimerArr[1]--;
        if (badFoodTimerArr[1] <= 0 && (!stopSpawningFoods))  //Relocate bad food1
        {
            Object.Destroy(badFoodGameObjectArr[1]);
            SpawnBad1();
            badFoodTimerArr[1] = 16;
        }
        ////////////////////////////////////////////
        //     Prize handler  //
        //If took Prise0
        if (snakeGridPosition == prizeGridPositionArr[0])
        {
            Object.Destroy(prizeGameObjectArr[0]);
            GameHandler.prizesLeftToWin--;
            return(true);
        }
        //If took Prise1
        if (snakeGridPosition == prizeGridPositionArr[1])
        {
            Object.Destroy(prizeGameObjectArr[1]);
            GameHandler.prizesLeftToWin--;
            return(true);
        }

        return(false);//Ate nothing
    }
示例#9
0
    private void HandleGridMovement()
    {
        gridMoveTimer += Time.deltaTime;
        if (gridMoveTimer >= gridMoveTimerMax)
        {
            gridMoveTimer -= gridMoveTimerMax;


            if (!GameHandler.isPrizesSpwaned)
            {
                GameHandler.SetProgressTimer();
            }
            else
            {
                GameHandler.SetProgressTimerToMax();
            }



            //Setting start size
            if (GameHandler.startSize > 0)
            {
                snakeBodySize++;
                CreateSnakeBodyPart();
                GameHandler.startSize--;
            }

            SoundManager.PlaySound(SoundManager.Sound.SnakeMove);

            SnakeMovePosition previousSnakeMovePosition = null;
            if (snakeMovePositionList.Count > 0)
            {
                previousSnakeMovePosition = snakeMovePositionList[0];
            }

            SnakeMovePosition snakeMovePosition = new SnakeMovePosition(previousSnakeMovePosition, gridPosition, gridMoveDirection);
            snakeMovePositionList.Insert(0, snakeMovePosition);

            Vector2Int gridMoveDirectionVector;

            switch (gridMoveDirection)
            {
            default:
            case Direction.Right:   gridMoveDirectionVector = new Vector2Int(+1, 0); break;

            case Direction.Left:    gridMoveDirectionVector = new Vector2Int(-1, 0); break;

            case Direction.Up:      gridMoveDirectionVector = new Vector2Int(0, +1); break;

            case Direction.Down:    gridMoveDirectionVector = new Vector2Int(0, -1); break;
            }

            gridPosition += gridMoveDirectionVector;

            gridPosition = levelGrid.ValidateGridPosition(gridPosition);

            bool snakeAteFood = levelGrid.TrySnakeEatFood(gridPosition);
            if (snakeAteFood)
            {
                // Snake ate food, grow body
                snakeBodySize++;
                CreateSnakeBodyPart();
                SoundManager.PlaySound(SoundManager.Sound.SnakeEat);

                if (GameHandler.curProgPart <= 8 && GameSound.happyIsPlayed())
                {
                    GameSound.StopHappy();
                    GameSound.PlaySad();
                }

                else if (GameHandler.curProgPart > 8 && GameSound.sadIsPlayed())
                {
                    GameSound.StopSad();
                    GameSound.PlayHappy();
                }


                if (GameHandler.prizesLeftToWin <= 0)
                {
                    state = State.Dead;
                    GameHandler.OnWin();
                    SoundManager.PlaySound(SoundManager.Sound.SnakeDie);//TODO Change it to winning music
                }
            }
            // On Win - Clear evrything on field (do funtion in levelgrid), then summon final prizes
            if (GameHandler.curProgPart > 16 && !GameHandler.isPrizesSpwaned)
            {
                GameHandler.isPrizesSpwaned = true;
                levelGrid.DestroyAll();
                levelGrid.SpawnPrizes();
            }

            updateSizeCounter++;
            if (updateSizeCounter >= 10)
            {
                snakeBodySize++;
                CreateSnakeBodyPart();
                updateSizeCounter = 0;
            }

            if (snakeMovePositionList.Count >= snakeBodySize + 1)
            {
                snakeMovePositionList.RemoveAt(snakeMovePositionList.Count - 1);
            }

            UpdateSnakeBodyParts();

            foreach (SnakeBodyPart snakeBodyPart in snakeBodyPartList)
            {
                Vector2Int snakeBodyPartGridPosition = snakeBodyPart.GetGridPosition();
                if (gridPosition == snakeBodyPartGridPosition)
                {
                    //Game Over!
                    state = State.Dead;
                    GameHandler.SnakeDied();
                    SoundManager.PlaySound(SoundManager.Sound.SnakeDie);
                }
            }


            transform.position    = new Vector3(gridPosition.x, gridPosition.y);
            transform.eulerAngles = new Vector3(0, 0, GetAngleFromVector(gridMoveDirectionVector) - 90);



            GameHandler.AddScore(1);
            GameHandler.AddProgressBar();
        }
    }
示例#10
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Ground")
        {
            groundTouched     = true;
            groundBearTouched = false;
            JumpAnim(false);
        }

        if (collision.gameObject.tag == "GroundBear")
        {
            groundTouched     = true;
            groundBearTouched = true;
            IsOnBearGround    = true;
            JumpAnim(false);
        }

        if (collision.gameObject.tag == "PickUps")
        {
            GameHandler.AddScore(10);
            Destroy(collision.gameObject);
        }
        if (collision.gameObject.tag == "ChocolateDoor")
        {
            GameHandler.HasCheckpoint = false;
            SceneManager.LoadScene("Candy");
        }
        if (collision.gameObject.tag == "CandyDoor")
        {
            GameHandler.HasCheckpoint = false;
            SceneManager.LoadScene("Marshmallow");
        }
        if (collision.gameObject.tag == "FinalDoor")
        {
            GameHandler.HasCheckpoint = false;
            SceneManager.LoadScene("FinalStage");
        }
        if (collision.gameObject.tag == "Star")
        {
            startCollected = true;
            GameHandler.AddScore(20);
            Destroy(collision.gameObject);
        }

        if (collision.gameObject.tag == "Life")
        {
            Destroy(collision.gameObject);
            GameHandler.AddLife();
        }

        if (collision.gameObject.tag == "Bear" && GameHandler.HasLifes())
        {
            GameHandler.ReduceLife();
            Die();
        }

        if (collision.gameObject.tag == "Ghost" && GameHandler.HasLifes())
        {
            GameHandler.ReduceLife();
            Die();
        }
        if (collision.gameObject.tag == "LoseBar")
        {
            GameHandler.ReduceLife();
            Die();
        }

        if (collision.gameObject.tag == "Checkpoint")
        {
            GameHandler.HasCheckpoint            = true;
            GameHandler.LatestCheckpointPosition = collision.gameObject.transform.position;
            GameHandler.AddScore(30);
            Destroy(collision.gameObject);
        }

        SetCanvasText();
    }