Ejemplo n.º 1
0
 public void Mutate(float mutationRate, HunterMovement bestParent)
 {
     for (int i = 0; i < lifeSpan; i++)
     {
         genes[i] = Random.value > 1 - mutationRate ? bestParent.genes[i] : NewGene();
     }
 }
Ejemplo n.º 2
0
    public void setScore(int value)
    {
        score += value;

        if (value == 0)
        {
            return;
        }

        coinsCounter.text = score.ToString();

        GameObject go = GameObject.FindGameObjectWithTag("GameOver");

        if (b < 1 && go == null)
        {
            //isfinish = true;
            GetComponent <AudioSource>().clip = comboMultiAudio;
            GetComponent <AudioSource>().Play();
            GameObject     hunter = GameObject.FindGameObjectWithTag("Player");
            HunterMovement hm     = hunter.GetComponent <HunterMovement>();
            Debug.Log("Score GameOver");
            hm.lost();
            GameOver();
        }
    }
Ejemplo n.º 3
0
    /*void OnMouseDown()
     * {
     *      //gameObject.transform.localScale = new Vector2 (0.65f, 0.65f);
     *      //Time.timeScale = 1;
     *      //gameObject.collider2D.enabled = false;
     * }*/

    void OnMouseDown()
    {
        if (gameObject.GetComponent <Collider2D>().name == "PlayHand" && isPlayHand)
        {
            startLevel();

            if (startCanvas.activeSelf && canvasIsActive)
            {
                print("StartCanvas is active");
            }
            else
            {
                //print("StartCanvas is not active");
                //gameObject.GetComponent<Collider2D>().name = "Taptostart";
                //startCanvas.SetActive (false);

                hunter         = GameObject.FindGameObjectWithTag("Player");
                hunterMovement = hunter.GetComponent <HunterMovement> ();
                hunterMovement.letStart();
                startLevel();
                gameObject.transform.position = new Vector2(11f, 11f);
                render.sprite = start;
                StartCoroutine(waitTime(gameObject));
            }
            isPlayHand = false;
        }

        /*else if (gameObject.GetComponent<Collider2D>().name == "RestartButton") {
         *      //startLevel ();
         *
         *      GameComponent.transform.position = new Vector2 (6.24f, GameComponent.transform.position.y);
         *
         *      gameObject.transform.position = new Vector2 (11f, 11f);
         *      GameObject hunt = GameObject.Find("Object");
         *      if(hunt == null)
         *      {
         *              hunt = GameObject.Find ("Object(Clone)");
         *      }
         *      Destroy(hunt);
         *      Destroy(GameObject.Find ("GameOver(Clone)"));
         *      GameObject h = (GameObject)Instantiate(hunterPrefab, new Vector3(8.15f, -2.15f, 0.02769041f), Quaternion.identity);
         *      gameObject.GetComponent<Collider2D>().name = "StartButton";
         *
         *      HunterMovement hRestart = h.GetComponent<HunterMovement> ();
         *      hRestart.letStart();
         *
         *      GameObject[] birds = GameObject.FindGameObjectsWithTag("Bird2D");
         *      StartCoroutine(InitiateEnemy());
         *      if(birds.Length == 2)
         *      {
         *              firstWave = true;
         *              StartCoroutine(InitiateBird (1));
         *      }
         *      else if(birds.Length == 1){
         *              firstWave = true;
         *              StartCoroutine(InitiateBird (2));
         *      }
         * }*/
    }
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        fly        = owl.GetComponent <FlyMovement> ();
        axe        = GetComponentInChildren <Axe> ();
        huntermove = GetComponent <HunterMovement> ();

        disable();
    }
Ejemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        gamecontroller = GameObject.FindGameObjectWithTag("GameController");
        //gamecontroller.GetComponent<ButtonClickScript> ().PauseCanvasVisibility (true);

        StartCoroutine(Wait());

        //label = GameObject.FindGameObjectWithTag ("FreeGiftIn_Label").GetComponent<Image> ();
        gameController = GameObject.FindGameObjectWithTag("GameController");
        gc             = gameController.GetComponent <GameController> ();
        bool status = gc.getGiftTimer();

        if (status)
        {
            giftButton.SetActive(false);
            timerIcon.enabled = true;
            //textObject.sprite = freeGiftIn;
            //label.sprite = freeGiftIn;
            //label.transform.localScale = new Vector2(1.3f, 1.3f);
            freeGiftText.text = "FREE GIFT IN";
            //textObject.enabled = false;
            int timerLeft = int.Parse(gc.giftTimerLeft());
            prevtime    = timerLeft;
            minute.text = "6:00";             //numbers [timerLeft];
        }
        else
        {
            timerIcon.enabled = false;
            giftButton.SetActive(true);
            freeGiftText.text = "FREE GIFT";
        }

        gameController = GameObject.FindGameObjectWithTag("GameController");
        gc             = gameController.GetComponent <GameController> ();

        calculateAccuracy();
        calculateKills();
        calculateTotalCoins();
        calculateMatchScore();

        hunter = GameObject.FindGameObjectWithTag("Player");
        hm     = hunter.GetComponent <HunterMovement> ();
        //gc.setScoreToZero ();

        GameObject progressbar = GameObject.FindGameObjectWithTag("ProgressBar");

        if (progressbar != null)
        {
            progressbar.SetActive(false);
        }
    }
Ejemplo n.º 6
0
    // Use this for initialization
    void Start()
    {
        render  = this.gameObject.GetComponent <SpriteRenderer> ();
        counter = 0;
        //Time.timeScale = 0;

        startLevel();

        //GameComponent.transform.position = new Vector2 (6.24f, GameComponent.transform.position.y);

        hunter         = GameObject.FindGameObjectWithTag("Player");
        hunterMovement = hunter.GetComponent <HunterMovement> ();
        collider       = gameObject.GetComponent <BoxCollider2D> ();

        startCanvas = GameObject.Find("StartCanvas");
        startCanvas.SetActive(true);
    }
Ejemplo n.º 7
0
    void Start()
    {
        hunter = GameObject.Find("Object");
        if (hunter == null)
        {
            hunter = GameObject.Find("Object(Clone)");
        }
        hm = hunter.GetComponent <HunterMovement> ();

        anim = GetComponent <Animator> ();
        anim.SetBool("isHit", false);

        //anime = gameObject.GetComponent<Animator> ();
        //anime.SetInteger ("movementValue", 0);
        newpos.x += 5f;
        newpos.y  = cube.transform.position.y;
    }
    HunterMovement GetBestParent()
    {
        HunterMovement toReturn = null;
        float          fitness  = HunterMovement.lifeSpan;

        // If someone won, their fitness = moves made. The less, the better.
        if (winningHunters.Count != 0)
        {
            foreach (HunterMovement hm in winningHunterMovements)
            {
                averageFitness += hm.GetGenesUsed();
                if (hm.GetGenesUsed() < fitness)
                {
                    fitness  = hm.GetGenesUsed();
                    toReturn = hm;
                }
            }
            averageFitness /= winningHunters.Count;
            return(toReturn);
        }

        // Otherwise, use their distance from the goal:

        foreach (HunterMovement hm in hunterMovements)
        {
            if (hm.IsTouchingBorder())
            {
                continue;
            }

            averageFitness += hm.GetFitness();
            if (hm.GetFitness() < fitness)
            {
                fitness  = hm.GetFitness();
                toReturn = hm;
            }
        }

        averageFitness /= hunterMovements.Count;
        return(toReturn == null ? hunterMovements[0] : toReturn);
    }
Ejemplo n.º 9
0
    IEnumerator Start()
    {
        treeLeft = GameObject.Find("ObstacleTreeLeft");

        hunter = GameObject.Find("Object");
        hm     = hunter.GetComponent <HunterMovement> ();

        anim = GetComponent <Animator> ();
        anim.SetBool("isHit", false);

        Vector3 pointA = transform.position;

        //float time = 1.5f;

        x1 = 9.5f;

        yield return(StartCoroutine(MoveObject(transform, new Vector2(4.1f, 2.958249f), new Vector2(x1, 2.958249f), birdSpeed)));

        yield return(StartCoroutine(MoveObject(transform, new Vector2(x1, 2.958249f), new Vector2(x2, y2), birdSpeed)));

        while (!isHit)
        {
            //yield return StartCoroutine(MoveObject(transform, pointA, pointB, 3.0f));
            //yield return StartCoroutine(MoveObject(transform, pointB, pointA, 3.0f));

            x1 = Random.Range(5.3f, 9.5f);
            y1 = Random.Range(0.8f, 4f);

            yield return(StartCoroutine(MoveObject(transform, new Vector2(transform.position.x, transform.position.y), new Vector2(x1, y1), birdSpeed)));            //3.692791f

            //if(!isHit)
            //{

            //	x2 = Random.Range(5.2f, 9.5f);
            //	y2 = Random.Range(1.5f, 4f);

            //	yield return StartCoroutine(MoveObject(transform, new Vector2(x1, y1), new Vector2(x2, y2), birdSpeed));
            //	prevX2 = x2;
            //}
        }
    }
Ejemplo n.º 10
0
    public void Mutate(float mutationRate, HunterMovement bestParent, List <HunterMovement> potentialParents)
    {
        if (potentialParents.Count == 0)
        {
            // Should never really be here.
            for (int i = 0; i < lifeSpan; i++)
            {
                genes[i] = Random.value < 1 - mutationRate ? bestParent.genes[i] : NewGene();
            }
            return;
        }

        HunterMovement parent1, parent2;

        int randomParentIndex = Random.Range(0, potentialParents.Count - 1);

        // 50% chance parent1 = best
        parent1 = Random.value > .5f ? bestParent : potentialParents[randomParentIndex];

        // Parent 2 is random from the potentials
        randomParentIndex = Random.Range(0, potentialParents.Count - 1);
        parent2           = potentialParents[randomParentIndex];

        // 50/50 from the two parents, with added potential mutation:

        for (int i = 0; i < lifeSpan; i++)
        {
            if (i % 2 == 0)
            {
                genes[i] = parent1.genes[i];
            }
            else
            {
                genes[i] = parent2.genes[i];
            }

            genes[i] = Random.value < 1 - mutationRate ? bestParent.genes[i] : NewGene();
        }
    }
Ejemplo n.º 11
0
    public void ButtonClick(string buttonName)
    {
        //GetComponent<AudioSource>().clip = buttonAudio;
        //GetComponent<AudioSource>().Play();
        playHand = GameObject.FindGameObjectWithTag("PlayHand");
        //sg = playHand.GetComponent<StartGame> ();
        if (buttonName == "GunsButton")
        {
            HunterMovement hm = GameObject.FindGameObjectWithTag("Player").GetComponent <HunterMovement>();
            hm.stopStart();
            sr.reset(PlayerPrefs.GetInt("gunIndex") - 1);
            PlayerPrefs.SetInt("isGuncanvasOpen", 1);
            isGuncanvasOpen = true;
            guns.SetActive(true);
        }
        else if (buttonName == "BackButton")
        {
            PlayerPrefs.SetInt("isGuncanvasOpen", 0);
            isGuncanvasOpen = false;
            guns.SetActive(false);
            //sg.deactiveCanvas();
        }
        if (buttonName == "StartButton")
        {
            /**/
            GameObject.FindGameObjectWithTag("GameTitle").GetComponent <Animator>().SetBool("isDown", true);
            GameObject.FindGameObjectWithTag("ButtonCountDown").GetComponent <Animator>().SetBool("isStart", true);
            GameObject.FindGameObjectWithTag("CoinObject").GetComponent <Animator>().SetBool("isStart", true);
            PlayerPrefs.SetInt("isGuncanvasOpen", 0);
            StartCoroutine(startanimation());
        }

        if (buttonName == "MapButton")
        {
            HunterMovement hm = GameObject.FindGameObjectWithTag("Player").GetComponent <HunterMovement>();
            hm.stopStart();
            MapScrollScript sr = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapScrollScript>();
            sr.reset(0);
            maps.SetActive(true);
        }

        if (buttonName == "BackMapButton")
        {
            maps.SetActive(false);
            //sg.deactiveCanvas();
        }

        if (buttonName == "Play")
        {
        }

        if (buttonName == "Pause")
        {
            Time.timeScale = 0;
            pauseCanvas.SetActive(true);
            pauseSmallCanvas.SetActive(false);
        }

        if (buttonName == "Resume")
        {
            Time.timeScale = 1;
            pauseCanvas.SetActive(false);
            pauseSmallCanvas.SetActive(true);
        }

        if (buttonName == "GiftButton")
        {
            gameover = GameObject.FindGameObjectWithTag("GameOver");
            gtemp    = (GameObject)Instantiate(gift, new Vector2(gift.transform.position.x, gift.transform.position.y), Quaternion.identity);
            gtemp.SetActive(true);


            Text giftText = GameObject.FindGameObjectWithTag("GiftCoin").GetComponent <Text> ();

            val           = Random.Range(50, 100);
            giftText.text = val.ToString();

            timerIcon         = GameObject.FindGameObjectWithTag("GreenStripeTimer").GetComponent <Image> ();
            timerIcon.enabled = false;

            minute = GameObject.FindGameObjectWithTag("GreenStripeMinute").GetComponent <Text> ();

            Text textObject = GameObject.FindGameObjectWithTag("FreeGiftText").GetComponent <Text> ();
            textObject.text = "FREE GIFT IN";

            /*Image label = GameObject.FindGameObjectWithTag ("FreeGiftIn_Label").GetComponent<Image> ();
             * label.enabled = true;*/

            timerIcon.enabled = true;
            minute.text       = "6:00";

            GameObject     gcc = GameObject.FindGameObjectWithTag("GameController");
            GameController gc  = gcc.GetComponent <GameController>();
            gc.resetGiftTimer();
            timeLeft = TotalTime;
            int sc = PlayerPrefs.GetInt("Score");
            sc = sc + val;
            PlayerPrefs.SetInt("Score", sc);

            GameObject giftButton = GameObject.FindGameObjectWithTag("GreenStripeButton");
            giftButton.SetActive(false);
            //GameOverVisibility(false);

            GameOverScript go_script = GameObject.FindGameObjectWithTag("GameOver").GetComponent <GameOverScript>();
            go_script.calculateTotalCoins();
        }

        if (buttonName == "Restart")
        {
            GameObject.FindGameObjectWithTag("ButtonCountDown").GetComponent <Animator>().SetBool("isStart", true);
            GameObject.FindGameObjectWithTag("CoinObject").GetComponent <Animator>().SetBool("isStart", true);
            GameObject.FindGameObjectWithTag("ButtonCountDown").GetComponent <Animator>().SetBool("isEnd", false);
            GameObject.FindGameObjectWithTag("CoinObject").GetComponent <Animator>().SetBool("isEnd", false);
            GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController> ().activeCoinCanvas();
            //sg.deactiveCanvas();
            restartLevel();
        }

        if (buttonName == "Menu")
        {
            Application.LoadLevel(0);
        }

        if (buttonName == "VideoButton")
        {
            VideoAds gamecontroller = GameObject.FindGameObjectWithTag("GameController").GetComponent <VideoAds>();
            //gamecontroller.loadAd();
        }

        if (buttonName == "RestartLevel")
        {
            Application.LoadLevel("MainScene");
        }

        if (buttonName == "MoveLeft")
        {
            GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().buttonClick("left");

            /*if(isRight)
             * {
             *      isRight = false;
             *      GameObject.FindGameObjectWithTag("Player").GetComponent<PirateMovement>().Flip();
             * }
             * direction = -1;*/
        }

        if (buttonName == "MoveRight")
        {
            if (GameObject.FindGameObjectWithTag("Player") != null)
            {
                GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().buttonClick("right");
            }

            /*if(!isRight)
             * {
             *      isRight = true;
             *      GameObject.FindGameObjectWithTag("Player").GetComponent<PirateMovement>().Flip();
             * }
             * direction = 1;*/
        }

        if (buttonName == "SeeUp")
        {
            if (GameObject.FindGameObjectWithTag("Player") != null)
            {
                GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().buttonClick("up");
            }

            /*if(!isRight)
             * {
             *      isRight = true;
             *      GameObject.FindGameObjectWithTag("Player").GetComponent<PirateMovement>().Flip();
             * }
             * direction = 1;*/
        }

        if (buttonName == "Still")
        {
            //direction = 0;
            if (GameObject.FindGameObjectWithTag("Player") != null)
            {
                GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().standStill();
            }
        }

        if (buttonName == "Fire")
        {
            GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerFireScript>().InitiateFire();
        }

        if (buttonName == "Jump" && GameObject.FindGameObjectWithTag("Player") != null)
        {
            if (GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().grounded)
            {
                GameObject.FindGameObjectWithTag("Player").GetComponent <PirateMovement>().isgrounded = false;
                //GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 900f));
                GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().activateJump();
            }
        }
    }
Ejemplo n.º 12
0
    void OnMouseUp()
    {
        //Destroy the hunter
        GameObject hunt = GameObject.FindGameObjectWithTag("Player");

        Destroy(hunt);

        //Destroy the bullets which are on the ground.
        GameObject[] bullets = GameObject.FindGameObjectsWithTag("Bullet");
        foreach (GameObject b in bullets)
        {
            Destroy(b);
        }

        //Destroy the bomber bird explosion.
        GameObject[] bbExplosion = GameObject.FindGameObjectsWithTag("BomberBirdExplosion");
        if (bbExplosion != null)
        {
            foreach (GameObject exp in bbExplosion)
            {
                Destroy(exp);
            }
        }

        //Destroy GameOver object.
        GameObject[] go = GameObject.FindGameObjectsWithTag("GameOver");
        for (int i = 0; i < go.Length; i++)
        {
            Destroy(go [i].gameObject);
        }
        //hRestart.setScoreToZero ();

        //Destroy the glassBreak which appears when user(hunter) is idle.
        GameObject glassBreak = GameObject.FindGameObjectWithTag("Glass Break");

        if (glassBreak != null)
        {
            Destroy(glassBreak);
        }

        //Destroy any sandhillCrane object.
        GameObject shc = GameObject.FindGameObjectWithTag("SandhillCrane");

        if (shc != null)
        {
            Destroy(shc);
        }

        //Destroy all the pelicans
        GameObject[] be = GameObject.FindGameObjectsWithTag("Bird2D");
        for (int i = 0; i < be.Length; i++)
        {
            Destroy(be[i]);
        }

        //Destroy the enemy birds (bird with the bomb).
        GameObject[] birds = GameObject.FindGameObjectsWithTag("BirdEnemy2D");
        for (int i = 0; i < birds.Length; i++)
        {
            Destroy(birds[i]);
        }

        GameObject playhand = GameObject.FindGameObjectWithTag("PlayHand");
        //Destroy (playhand);

        //Get Gamecontroller object and set the values to zero.
        GameObject     gcc = GameObject.FindGameObjectWithTag("GameController");
        GameController gc  = gcc.GetComponent <GameController> ();

        gc.setScoreToZero();

        //GameObject ph = (GameObject)Instantiate(playHandPrefab, new Vector3(11f, 11f, 0.02769041f), Quaternion.identity);
        StartGame sg = playhand.GetComponent <StartGame>();

        sg.initBird(3);

        GameObject h = (GameObject)Instantiate(hunter, new Vector3(8.15f, -2.15f, 0.02769041f), Quaternion.identity);
        //gameObject.GetComponent<Collider2D>().name = "StartButton";

        HunterMovement hRestart = h.GetComponent <HunterMovement> ();

        hRestart.letStart();

        /*sg.initEmenyBird();
         * if(birds.Length == 2)
         * {
         *      sg.initBird(1);
         * }
         * else if(birds.Length == 1){
         *      sg.initBird(2);
         * }*/
    }
Ejemplo n.º 13
0
    private void Start()
    {
        start = this.transform.position;

        HunterMovement = Hunter.GetComponent <HunterMovement>();
    }