コード例 #1
0
 private void Awake()
 {
     instance = this;
     GetComponent <Rigidbody2D>().gravityScale = 1f;
     GetComponent <Rigidbody2D>().bodyType     = RigidbodyType2D.Static;
     state = State.WaitingToStart;
     audio = GetComponent <AudioSource>();
 }
コード例 #2
0
        public void UpdateState()
        {
            for (var i = 0; i < CountWallsInStage; i++)
            {
                var currentWall = Walls.Dequeue();
                currentWall.Location -= Velocity;

                if (currentWall.Location < -Setting.WidthWall)
                {
                    var lastWall    = Walls.Last();
                    var startWindow = random.Next(Setting.HeightWindowOfWall + 10, HeightWindow - 10);
                    var newWall     = new Wall(lastWall.Location + IntervalBetweenWalls, startWindow);
                    Walls.Enqueue(newWall);
                }
                else
                {
                    Walls.Enqueue(currentWall);
                }
            }

            FlappyBird.UpdatePosition();
            UpdateScore();

            if (FlappyBird.LocationY >= HeightWindow - Setting.HeightBird)
            {
                FlappyBird.UpdatePosition(Setting.StartPosition, HeightWindow - Setting.HeightBird - 5);
                StateChanged?.Invoke(true);
                IsGameOver = true;
                return;
            }

            foreach (var wall in Walls)
            {
                if (IsСollisionBirdInWall(wall))
                {
                    var pointCollision = GetPointCollision(wall);
                    FlappyBird.UpdatePosition(pointCollision.X, pointCollision.Y);
                    StateChanged?.Invoke(true);
                    IsGameOver = true;
                    return;
                }
            }

            StateChanged?.Invoke(false);
        }
コード例 #3
0
    // Use this for initialization
    void Start()
    {
        mainCam             = Camera.main;
        m_LastSpawnBlock    = m_FirstSpawnBlock;
        blockLength         = m_LastSpawnBlock.GetComponent <BoxCollider2D>().size.x;
        m_FlappyBird        = FindObjectOfType <FlappyBird>();
        cameraBirdDistanceX = m_FlappyBird.transform.position.x - mainCam.transform.position.x;
        startCameraPosX     = mainCam.transform.position.x;
        startBirdPos        = m_FlappyBird.transform.position;
        startFogPos         = m_Fog.transform.position;
        fogBirdDistanceX    = m_FlappyBird.transform.position.x - m_Fog.transform.position.x;

        m_RestartButton.SetActive(false);
        m_ContinueText.SetActive(false);
        listBirds.Add(m_FlappyBird.gameObject);

        curScore            = 0;
        curHighScore        = PlayerPrefs.GetInt(HIGH_SCORE_KEY, 0);
        m_ScoreTxt.text     = "Score: " + curScore;
        m_HighScoreTxt.text = "Best: " + curHighScore;
    }
コード例 #4
0
    public void NewBird()
    {
        isGameOver = false;
        m_RestartButton.SetActive(false);
        m_ContinueText.SetActive(false);

        curScore        = 0;
        m_ScoreTxt.text = "Score: " + curScore;

        var prefabs = m_DesignData.birdPrefabs;
        var newBird = Instantiate(prefabs[Random.Range(0, prefabs.Length)]);

        m_FlappyBird = newBird.GetComponent <FlappyBird>();
        newBird.transform.position = startBirdPos;

        listBirds.Add(newBird);

        var camPos = mainCam.transform.position;

        camPos.x = startCameraPosX;
        mainCam.transform.position = camPos;

        var backgrounds = FindObjectsOfType <Background>();

        for (int i = 0; i < backgrounds.Length; i++)
        {
            backgrounds[i].Reset();
        }

        var fogPos = m_Fog.transform.position;

        fogPos.x = m_FlappyBird.transform.position.x - fogBirdDistanceX;
        if (m_Fog.transform.position.x > fogPos.x)
        {
            fogPos.x = Mathf.Lerp(fogPos.x, m_Fog.transform.position.x, 0.9f);
            m_Fog.transform.position = fogPos;
        }
    }
コード例 #5
0
ファイル: Level.cs プロジェクト: fahadthakur/Jumpy-Burb-Unity
 // Start is called before the first frame update
 void Start()
 {
     //createGapPipe(5f, 4f, 5f);
     FlappyBird.getInstance().OnDied           += Bird_OnDied;
     FlappyBird.getInstance().OnStartedPlaying += Bird_OnStartedPlaying;
 }
コード例 #6
0
 private void Start()
 {
     FlappyBird.getInstance().OnDied += Bird_OnDied;
     Hide();
 }
コード例 #7
0
 public FlappyBird SetFlappyBird(FlappyBird flappyBird)
 {
     this.flappyBird = flappyBird;
     return(this.flappyBird);
 }