mirror of
https://github.com/tiennm99/flappy-bird.git
synced 2026-10-19 20:15:05 +00:00
Complete
This commit is contained in:
1 parent
8a77f67d6d
commit
c0872dfe9d
58 files changed
+4740
No files matched your search
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Bird : MonoBehaviour
|
||||
{
|
||||
public float flyPower;
|
||||
public AudioClip flySound;
|
||||
public AudioClip deadSound;
|
||||
private GameObject obj;
|
||||
private GameObject gameController;
|
||||
private AudioSource audioSource;
|
||||
private Animator anim;
|
||||
void Start()
|
||||
{
|
||||
obj = gameObject;
|
||||
flyPower = 300;
|
||||
gameController = GameObject.FindGameObjectWithTag("GameController");
|
||||
audioSource = obj.GetComponent<AudioSource>();
|
||||
audioSource.clip = flySound;
|
||||
anim = obj.GetComponent<Animator>();
|
||||
anim.SetBool("isDead", false);
|
||||
anim.SetFloat("flyPower", 0);
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
obj.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, flyPower));
|
||||
audioSource.Play();
|
||||
}
|
||||
anim.SetFloat("flyPower", obj.GetComponent<Rigidbody2D>().velocity.y);
|
||||
}
|
||||
private void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
anim.SetBool("isDead", true);
|
||||
audioSource.clip = deadSound;
|
||||
audioSource.Play();
|
||||
gameController.GetComponent<Control>().EndGame();
|
||||
}
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
gameController.GetComponent<Control>().GetPoint();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75d8973b994df4e47af930cfb2be7b54
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,86 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Control : MonoBehaviour
|
||||
{
|
||||
public Text txtPoint;
|
||||
public GameObject pnlStart;
|
||||
public Button btnStart;
|
||||
public GameObject pnlRestart;
|
||||
public Text txtRestart;
|
||||
public Button btnRestart;
|
||||
public Sprite btnRestartIdle;
|
||||
public Sprite btnRestartHover;
|
||||
public Sprite btnRestartClick;
|
||||
public Sprite btnStartIdle;
|
||||
public Sprite btnStartHover;
|
||||
public Sprite btnStartClick;
|
||||
public GameObject bird;
|
||||
public GameObject column;
|
||||
public GameObject sky;
|
||||
public GameObject grass;
|
||||
private int gamePoint;
|
||||
void Start()
|
||||
{
|
||||
gamePoint = 0;
|
||||
Time.timeScale = 0;
|
||||
pnlStart.SetActive(true);
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
/*
|
||||
*column.GetComponent<Column>().randRange = 3.0f;
|
||||
* sky.GetComponent<Move>().moveSpeed += 0.5f;
|
||||
* grass.GetComponent<Move>().moveSpeed += 0.5f;
|
||||
* bird.GetComponent<Bird>().flyPower += 10f;
|
||||
*/
|
||||
}
|
||||
public void RestartButtonIdle()
|
||||
{
|
||||
btnRestart.GetComponent<Image>().sprite = btnRestartIdle;
|
||||
}
|
||||
public void RestartButtonHover()
|
||||
{
|
||||
btnRestart.GetComponent<Image>().sprite = btnRestartHover;
|
||||
}
|
||||
public void RestartButtonClick()
|
||||
{
|
||||
btnRestart.GetComponent<Image>().sprite = btnRestartClick;
|
||||
}
|
||||
public void StartButtonIdle()
|
||||
{
|
||||
btnStart.GetComponent<Image>().sprite = btnStartIdle;
|
||||
}
|
||||
public void StartButtonHover()
|
||||
{
|
||||
btnStart.GetComponent<Image>().sprite = btnStartHover;
|
||||
}
|
||||
public void StartButtonClick()
|
||||
{
|
||||
btnStart.GetComponent<Image>().sprite = btnStartClick;
|
||||
}
|
||||
public void StartGame()
|
||||
{
|
||||
pnlStart.SetActive(false);
|
||||
pnlRestart.SetActive(false);
|
||||
Time.timeScale = 1;
|
||||
}
|
||||
public void GetPoint()
|
||||
{
|
||||
gamePoint++;
|
||||
txtPoint.text = "Point: " + gamePoint.ToString();
|
||||
}
|
||||
public void EndGame()
|
||||
{
|
||||
Time.timeScale = 0;
|
||||
txtRestart.text = "Your point:\n" + gamePoint.ToString();
|
||||
pnlRestart.SetActive(true);
|
||||
}
|
||||
public void Restart()
|
||||
{
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86304a10a8b60474ba57cbc78b6243d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Move : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed;
|
||||
public float moveRange;
|
||||
private GameObject obj;
|
||||
private Vector3 oldPosition;
|
||||
void Start()
|
||||
{
|
||||
obj = gameObject;
|
||||
oldPosition = obj.transform.position;
|
||||
moveSpeed = 5.0f;
|
||||
moveRange = 20f;
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
obj.transform.Translate(new Vector3(-Time.deltaTime * moveSpeed, 0, 0));
|
||||
if (oldPosition.x - obj.transform.position.x > moveRange)
|
||||
{
|
||||
obj.transform.position = oldPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a481d74acd03f9468d10c40aec546e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Wall : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed;
|
||||
public float moveRange;
|
||||
public float randRange;
|
||||
private GameObject obj;
|
||||
private Vector3 oldPosition;
|
||||
void Start()
|
||||
{
|
||||
obj = gameObject;
|
||||
oldPosition = obj.transform.position;
|
||||
moveSpeed = 5.0f;
|
||||
randRange = 3.0f;
|
||||
obj.transform.position = new Vector3(oldPosition.x, oldPosition.y + Random.Range(-randRange, randRange), oldPosition.z);
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
obj.transform.Translate(new Vector3(-Time.deltaTime * moveSpeed, 0, 0));
|
||||
if (obj.transform.position.x < -7)
|
||||
{
|
||||
obj.transform.position = new Vector3(24, oldPosition.y + Random.Range(-randRange, randRange), oldPosition.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eabc18103b6497e45b4c12b0e7950797
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user