Esempio n. 1
0
    void eventHandler(BirdController.birdStates newState)
    {
        //switch on the newEvent
                /*switch (newState)
                {

                    //

                }*/
    }
    public void BirdCantMoveOffGridUp()
    {
        mockBird = new GameObject();

        birdController = mockBird.AddComponent <BirdController>();

        birdController.grid = mockBird.AddComponent <Grid>();

        birdController.gridY = birdController.grid.gridHeight - 1;

        birdController.updateGridPosition(1f, 0f);

        Assert.IsTrue(birdController.gridY == birdController.grid.gridHeight - 1);
    }
    public void BirdCantMoveOffGridDown()
    {
        mockBird = new GameObject();

        birdController = mockBird.AddComponent <BirdController>();

        birdController.grid = mockBird.AddComponent <Grid>();

        birdController.gridY = 0;

        birdController.updateGridPosition(-1f, 0f);

        Assert.IsTrue(birdController.gridY == 0);
    }
    public void BirdCantMoveOffGridRight()
    {
        mockBird = new GameObject();

        birdController = mockBird.AddComponent <BirdController>();

        birdController.grid = mockBird.AddComponent <Grid>();

        birdController.gridX = birdController.grid.gridWidth - 1;

        birdController.updateGridPosition(0f, 1f);

        Assert.IsTrue(birdController.gridX == birdController.grid.gridWidth - 1);
    }
    // Use this for initialization
    void Start()
    {
        isRunning = false;

        menu        = GameObject.Find("Canvas/StartMenu").GetComponent <MenuView>();
        scorePanel  = GameObject.Find("Canvas/ScorePanel").GetComponent <ScoreView>();
        gameSummary = GameObject.Find("Canvas/GameSummary").GetComponent <GameSummaryView>();

        bird                 = Camera.main.transform.Find("Bird").GetComponent <BirdController>();
        obstacleManager      = GameObject.Find("ObstacleManager").GetComponent <ObstacleManager>();
        backgroundController = GameObject.Find("Background").GetComponent <BackgroundController>();

        menu.Activate();
    }
Esempio n. 6
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Coin")
        {
            Player.Instance.Points += 5;
        }
        else if (other.gameObject.tag == "Bird")
        {
            //Update health
            Player.Instance.Health = Player.Instance.Health - 20;

            BirdController sp =
                other.gameObject.GetComponent <BirdController> ();
        }
    }
    public void BirdMovesUpWithPositiveVerticalInput()
    {
        mockBird = new GameObject();

        birdController = mockBird.AddComponent <BirdController>();

        birdController.grid = mockBird.AddComponent <Grid>();

        birdController.gridY = 0;

        int gridY = birdController.gridY;

        birdController.updateGridPosition(1f, 0f);

        Assert.IsTrue(birdController.gridY > gridY);
    }
    public void BirdMovesDownWithNegativeVerticalInput()
    {
        mockBird = new GameObject();

        birdController = mockBird.AddComponent <BirdController>();

        birdController.grid = mockBird.AddComponent <Grid>();

        birdController.gridY = birdController.grid.gridHeight - 1;

        int gridY = birdController.gridY;

        birdController.updateGridPosition(-1f, 0f);

        Assert.IsTrue(birdController.gridY < gridY);
    }
    public void BirdMovesLeftWithNegativeHorizontalInput()
    {
        mockBird = new GameObject();

        birdController = mockBird.AddComponent <BirdController>();

        birdController.grid = mockBird.AddComponent <Grid>();

        birdController.gridX = birdController.grid.gridWidth - 1;

        int gridX = birdController.gridX;

        birdController.updateGridPosition(0f, -1f);

        Assert.IsTrue(birdController.gridX < gridX);
    }
    public void BirdMovesRightWithPositiveHorizontalInput()
    {
        mockBird = new GameObject();

        birdController = mockBird.AddComponent <BirdController>();

        birdController.grid = mockBird.AddComponent <Grid>();

        birdController.gridX = 0;

        int gridX = birdController.gridX;

        birdController.updateGridPosition(0f, 1f);

        Assert.IsTrue(birdController.gridX > gridX);
    }
Esempio n. 11
0
    /// <summary>
    /// Inverts the X axis of this player instance
    /// </summary>
    public void invertXAxis()
    {
        BearInputController _bearController = GameObject.Find("GroundPlatformer(Clone)").GetComponent <BearInputController> ();

        if (_bearController)
        {
            _bearController.invertX = _XAxis.isOn;
        }


        BirdController _birdController = GameObject.Find("AirDrawer(Clone)").GetComponent <BirdController> ();

        if (_birdController)
        {
            _birdController.invertX = _XAxis.isOn;
        }
    }
Esempio n. 12
0
    void Start()
    {
        foreach (var bird in birds)
        {
            bird.OnBirdDestroyed += ChangeBird;
            bird.OnBirdShoot     += AssignTrail;
        }

        foreach (var enemy in enemies)
        {
            enemy.OnEnemyDestroyed += CheckGameEnd;
        }

        tapCollider.enabled = false;
        slingShot.InitiateBird(birds[0]);
        _shotBird = birds[0];
    }
Esempio n. 13
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }

        if (Input.GetMouseButtonDown((int)MouseButton.LeftMouse))
        {
            isMouseDown  = true;
            releasedBird = null; // kinda jank // this stops camera to interp to release bird
        }

        if (Input.GetMouseButtonUp((int)MouseButton.LeftMouse))
        {
            rb.isKinematic = false;
            isMouseDown    = false;

            // Release
            if (HoldBird)
            {
                StartCoroutine(Release(releaseTime));
            }
            HoldBird = false;
        }

        if (isMouseDown && HoldBird)
        {
            Vector2 mouseWorldPos           = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 connectedAnchorWorldPos = anchor.position;// transform.TransformPoint(springJoint.connectedAnchor);
            Debug.Log(connectedAnchorWorldPos);
            Vector2 mouseDir    = (mouseWorldPos - connectedAnchorWorldPos).normalized;
            float   mouseLength = Mathf.Abs(Vector2.Distance(mouseWorldPos, connectedAnchorWorldPos));//springJoint.distance;//

            Vector2 movePoint = mouseLength <= MAX_DISTANCE ?
                                mouseWorldPos :
                                connectedAnchorWorldPos + mouseDir * MAX_DISTANCE;

            //Debug.DrawLine(connectedAnchorWorldPos, movePoint, Color.cyan, 1);

            rb.MovePosition(movePoint);
            rb.isKinematic = true;
        }
    }
Esempio n. 14
0
    private IEnumerator Release(float time)
    {
        currentBird.Release();
        yield return(new WaitForSeconds(time));

        springJoint.enabled = false;
        releasedBird        = currentBird;

        //this.enabled = false;
        yield return(new WaitForSeconds(1f));

        if (index < birds.Length)
        {
            currentBird = birds[index++];
            currentBird.transform.position = anchor.position;
            rb          = currentBird.RB;
            springJoint = currentBird.SpringJoint;
        }
    }
Esempio n. 15
0
    // Update is called once per frame
    void Update()
    {
        allBirdsDead = true;
        for (int i = 0; i < birds.Length; i++)
        {
            if (!birds[i].dead)
            {
                allBirdsDead = false;
            }
            //Debug.Log("Bird " + i + ": " + birds[i].brain.fitness);
        }

        if (allBirdsDead)
        {
            birds = birds.ToList().OrderBy(o => o.brain.fitness).ToArray();
            for (int i = 0; i < 10; i++)
            {
                //Debug.Log(birds.Length);
                BirdController bird1 = birds[chooseBird()];
                BirdController bird2 = birds[chooseBird()];

                /*BirdController bird1 = birds[Random.Range(0, 3)];
                *  BirdController bird2 = birds[Random.Range(0, 3)];*/
                var            child       = Instantiate(birdPrefab, initialBirdLocation, Quaternion.identity);
                BirdController childScript = child.GetComponent <BirdController>();
                childScript.brain = NeuralNetwork.CrossOver(bird1.brain, bird2.brain);
                if (Random.Range(0.0f, 1.0f) <= 0.1)
                {
                    childScript.brain.Mutate();
                }
                childScript.gameObject.transform.parent = this.gameObject.transform;
            }


            for (int i = 0; i < birds.Length; i++)
            {
                DestroyImmediate(birds[i].gameObject);
            }
            birds = GetComponentsInChildren <BirdController>();
            //Debug.Log(birds.Length);
        }
    }
Esempio n. 16
0
    // Update is called once per frame
    void Update()
    {
        // Get Player Transform/Position
        Transform playerTrans = Player.transform;
        Vector2   playerPos   = new Vector2(playerTrans.position.x, playerTrans.position.z);

        // Get Pillar Transform/Position
        Transform trans = transform;
        Vector2   pos   = new Vector2(trans.position.x, trans.position.z);

        // Compare the two distances
        var dist = Vector2.Distance(playerPos, pos);

        if (dist < 0.2)
        {
            BirdController birdScript = Player.GetComponent <BirdController>();

            //birdScript.SetSpeed(birdScript.GetSpeed() - 10);
        }
    }
Esempio n. 17
0
 public void BirdMove()
 {
     string[] BirdTag = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
     for (int i = 0; i < Birdnum && BirdliveNum > 0; i++)
     {
         Tm = GameObject.FindGameObjectWithTag(BirdTag[i]).GetComponent <BirdController>();
         if (Tm.BirdIslive)
         {
             Tm.Move();
         }
         else
         {
             if (Tm.flag)
             {
                 BirdliveNum--;
                 // Debug.Log(BirdliveNum);
                 Tm.flag = false;
             }
         }
     }
 }
Esempio n. 18
0
 public void PrepareTest()
 {
     CleanUpTest();
     if (GameManager._instance == null)
     {
         gameManager = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Prefab/GameManager"));
     }
     if (BirdManager._instance == null)
     {
         birdManager = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Prefab/BirdManager"));
     }
     if (ScoreManager._instance == null)
     {
         scoreManager = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Prefab/ScoreManager"));
     }
     if (InputManager._instance == null)
     {
         MonoBehaviour.Instantiate(Resources.Load <GameObject>("Prefab/InputManager"));
     }
     bird = BirdManager._instance.GetBird();
 }
Esempio n. 19
0
 public void FireMissile()
 {
     for (int i = 0; i < birdAmount; i++)
     {
         birdCon = bird.GetComponent<BirdController> ();
         if(birdArray[i].activeInHierarchy == false)
         {
             birdArray[i].transform.position = gameObject.transform.position;
             birdCon = birdArray[i].GetComponent<BirdController> ();
             birdCon.lifetime = 10f;
             //birdCon.missileVelocity = 4f;
             birdCon.startTime = Time.time;
             //homey.hit = false;
             birdArray[i].SetActive(true);
             birdCon.baconSpot = targetBacon;
             birdCon.playerHitZone = playerZone;
             birdCon.Fire();
             return;
         }
     }
 }
Esempio n. 20
0
    private void ChangeBird()
    {
        tapCollider.enabled = false;

        if (_isGameEnded)
        {
            return;
        }

        birds.RemoveAt(0);

        if (birds.Count > 0)
        {
            slingShot.InitiateBird(birds[0]);
            _shotBird = birds[0];
        }
        else
        {
            SceneManager.LoadScene("Lose");
        }
    }
Esempio n. 21
0
    /// <summary>
    /// Invers the Y axis of this player instance
    /// </summary>
    public void inverYAxis()
    {
        // If the Server (Bear) then inverse Bear controls

        BearInputController _bearController = GameObject.Find("GroundPlatformer(Clone)").GetComponent <BearInputController> ();

        if (_bearController)
        {
            _bearController.invertY = _YAxis.isOn;
        }


        // If the Client (Bird) then inverse Bird controls

        BirdController _birdController = GameObject.Find("AirDrawer(Clone)").GetComponent <BirdController> ();

        if (_birdController)
        {
            _birdController.invertY = _YAxis.isOn;
        }
    }
Esempio n. 22
0
 private void createPlayers()
 {
     birds = new List <BirdController>();
     if (runAi)
     {
         redBirds    = initBirds(redBirdPrefab, redBirdCount);
         greenBirds  = initBirds(greenBirdPrefab, greenBirdCount);
         blueBirds   = initBirds(blueBirdPrefab, blueBirdCount);
         orangeBirds = initBirds(orangeBirdPrefab, orangeBirdCount);
         if (weights != null)
         {
             yellowBird = initBirds(yellowBirdPrefab, 1, true, true)[0];
         }
         else
         {
             yellowBird = initBirds(yellowBirdPrefab, 1)[0];
         }
     }
     else
     {
         yellowBird = initBirds(yellowBirdPrefab, 1, false)[0];
     }
 }
Esempio n. 23
0
    private void CreateBirdBodies()
    {
        if (birdsList != null)
        {
            for (int i = 0; i < birdsList.Count; i++) //Destroy potential remaining birds
            {
                GameObject.Destroy(birdsList[i].gameObject);
            }
        }

        birdsList = new List <BirdController>();

        for (int i = 0; i < populationSize; i++)
        {
            //1. Instantiate bird prefab
            GameObject temp = ((GameObject)Instantiate(BirdPrefab, new Vector3(-3f, 2f, 0), BirdPrefab.transform.rotation));
            temp.layer = i + 8;
            BirdController bird = temp.GetComponent <BirdController>();

            bird.Init(nets[i]);
            birdsList.Add(bird);
        }
        birdsAlive = populationSize;
    }
Esempio n. 24
0
    void Awake()
    {
        WordText.text = "";

        _others = new List <GameObject>();
        _otherBirdControllers = new List <BirdController>();
        GameObject        colorPrefab  = null;
        List <GameObject> otherPrefabs = new List <GameObject>();

        // Spawn player, move to place only when the data is given
        switch (GameManager.Instance.PlayerColor)
        {
        case "Red":
            colorPrefab = RedBirdPrefab;
            otherPrefabs.Add(YellowBirdPrefab);
            otherPrefabs.Add(GreenBirdPrefab);
            otherPrefabs.Add(BlueBirdPrefab);
            break;

        case "Yellow":
            colorPrefab = YellowBirdPrefab;
            otherPrefabs.Add(RedBirdPrefab);
            otherPrefabs.Add(GreenBirdPrefab);
            otherPrefabs.Add(BlueBirdPrefab);
            break;

        case "Green":
            colorPrefab = GreenBirdPrefab;
            otherPrefabs.Add(RedBirdPrefab);
            otherPrefabs.Add(YellowBirdPrefab);
            otherPrefabs.Add(BlueBirdPrefab);
            break;

        case "Blue":
            colorPrefab = BlueBirdPrefab;
            otherPrefabs.Add(RedBirdPrefab);
            otherPrefabs.Add(YellowBirdPrefab);
            otherPrefabs.Add(GreenBirdPrefab);
            break;
        }

        _myBird = Instantiate(colorPrefab);
        var myIndex = GetHorizontalIndex(colorPrefab);

        _myBird.transform.position = SpawnAnchorsHorizontal[myIndex].position;
        _myBird.transform.position = new Vector3(_myBird.transform.position.x, -1000f, _myBird.transform.position.z);

        _myBird.transform.localScale = Vector3.one * 0.37f;

        _myBirdController                 = _myBird.GetComponent <BirdController>();
        _myBirdController.Color           = GameManager.Instance.PlayerColor;
        _myBirdController.HorizontalIndex = myIndex;

        GameManager.Instance.MyBirdController = _myBirdController;

        // Generate other birds
        foreach (var other in otherPrefabs)
        {
            var otherBird  = Instantiate(other);
            var otherIndex = GetHorizontalIndex(other);

            otherBird.transform.position = SpawnAnchorsHorizontal[otherIndex].position;
            otherBird.transform.position = new Vector3(otherBird.transform.position.x, -1000f, otherBird.transform.position.z);

            otherBird.transform.localScale = Vector3.one * 0.37f;

            var otherController = otherBird.GetComponent <BirdController>();

            otherController.Color           = GetColorFromPrefab(other);
            otherController.HorizontalIndex = otherIndex;

            _otherBirdControllers.Add(otherController);
            _others.Add(otherBird);
        }


        _gameLoop = StartCoroutine(GetGameInfo());
    }
 // Start is called before the first frame update
 void Start()
 {
     instant = this;
     birdList.Add(head.gameObject);
 }
Esempio n. 26
0
 // Start is called before the first frame update
 void Start()
 {
     show();
     BirdController.getInstance().onBirdStart += hide;
 }
Esempio n. 27
0
    void FixedUpdate()
    {
        if (gameOver)
        {
            gameOverText.text = "GAME OVER";

            if(score > HighScore)
                HighScore = score;

            highScoreText.text = "High Score: " + Mathf.RoundToInt(HighScore);
        }
        else
        {
            if(isBossFight && !bird.useAI)
            {
                if(bossStage == StageStartMusic)
                {
                    bossMusic.Play();
                    bossStage = StageHidePipes;
                }
                if(bossStage == StageDisplayText)
                {
                    bossFightText.text = "BOSS FIGHT! Hit SPACE to fire!";

                    eagle = SpawnEagle();

                    eagle.manager = this;
                    eagle.enemy = bird;

                    eagle.healthBar = ((GameObject)Instantiate(eagle.healthBarPrefab, eagle.transform.position, eagle.healthBarPrefab.transform.rotation)).GetComponent<HealthBar>();
                    eagle.healthBar.owner = eagle;
                    eagle.healthBar.manager = this;
                    eagle.healthBar.transform.SetParent(GameObject.FindObjectOfType<Canvas>().transform);

                    bird.healthBar.display = true;
                    eagle.healthBar.display = true;

                    bossStage = StageMoveBird;
                }
                else if(bossStage == StageHidePipes)
                {
                    bool pipesHidden = true;
                    foreach(PipeController pipe in GameObject.FindObjectsOfType<PipeController>())
                    {
                        if(!pipe.hidden)
                        {
                            pipe.Hide ();
                            pipesHidden = false;
                            break;
                        }
                    }
                    if(pipesHidden)
                    {
                        bossStage = StageDisplayText;
                    }
                }
                else if(bossStage == StageMoveBird)
                {
                    if(bird.transform.position.x != bossBattleBirdPosition.x)
                    {
                        Vector3 newPos = Vector3.MoveTowards(bird.transform.position, bossBattleBirdPosition, .05f);
                        bird.transform.position = newPos;
                    }
                    else
                    {
                        bossStage = StageDispatchBoss;
                    }
                }
                else if(bossStage == StageDispatchBoss)
                {
                    if(eagle.transform.position.x != bossBattleEaglePosition.x)
                    {
                        Vector3 newPos = Vector3.MoveTowards(eagle.transform.position, bossBattleEaglePosition, .05f);
                        eagle.transform.position = newPos;
                    }
                    else
                    {
                        bossStage = StageInitFinish;
                    }
                }
            }
            else
            {
                if(score % bossTriggerInterval == 0 && bossStage == StageStartMusic)
                    isBossFight = true;

                if(bossStage == StageDisplayWin)
                {
                    bossFightText.text = "BOSS DEFEATED! You may return to your pointless life of inevitable doom!";

                    bossStage = StageStopMusic;
                }
                else if(bossStage == StageStopMusic)
                {
                    if(bossMusic.isPlaying)
                    {
                        //Fade the music out.
                        if(bossMusic.volume > .05f)
                            bossMusic.volume -= .002f;
                        else
                        {
                            bossMusic.Stop();
                            bossStage = StageMoveBirdBack;
                        }
                    }
                }
                else if(bossStage == StageMoveBirdBack)
                {
                    bird.healthBar.display = false;

                    if(bird.transform.position.x != normalBirdPosition.x)
                    {
                        Vector3 newPos = Vector3.MoveTowards(bird.transform.position, normalBirdPosition, .05f);
                        bird.transform.position = newPos;
                    }
                    else
                    {
                        bossStage = StageShowPipes;
                    }
                }
                else if(bossStage == StageShowPipes)
                {
                    bool pipesShown = true;
                    foreach(PipeController pipe in GameObject.FindObjectsOfType<PipeController>())
                    {
                        if(pipe.hidden)
                        {
                            pipe.Show ();
                            pipesShown = false;
                            break;
                        }
                    }
                    if(pipesShown)
                    {
                        bossStage = StageHideText;
                    }
                }
                else if(bossStage == StageHideText)
                {
                    bossFightText.text = "";
                    bossStage = StageStartMusic;
                }
            }

            //score += .05f;
            scoreText.text = "" + Mathf.RoundToInt(score);
        }
    }
Esempio n. 28
0
 private void AssignTrail(BirdController bird)
 {
     trailController.SetBird(bird);
     StartCoroutine(trailController.SpawnTrail());
     tapCollider.enabled = true;
 }
Esempio n. 29
0
 void Awake()
 {
     uiController   = GameObject.Find("UIController").GetComponent <UIController>();
     birdController = GameObject.Find("Bird").GetComponent <BirdController>();
 }
Esempio n. 30
0
 private void Awake()
 {
     // Gets current bird in the scene
     bird = GameObject.FindGameObjectWithTag("Player").GetComponent <BirdController>();
 }
Esempio n. 31
0
 // Start is called before the first frame update
 void Start()
 {
     currentBird = birds[index++];
     rb          = currentBird.RB;
     springJoint = currentBird.SpringJoint;
 }
Esempio n. 32
0
 public override void InitializeAgent()
 {
     birdController = GetComponent <BirdController>();
     birdRB         = GetComponent <Rigidbody2D>();
 }
Esempio n. 33
0
 private void Awake()
 {
     _birdController = new BirdController(this);
 }