├── README.md ├── ProjectSettings ├── ProjectVersion.txt ├── TagManager.asset ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── TimeManager.asset ├── DynamicsManager.asset ├── EditorSettings.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── GraphicsSettings.asset ├── Physics2DSettings.asset └── EditorBuildSettings.asset ├── Assets ├── UnityVS │ ├── Editor │ │ ├── SyntaxTree.VisualStudio.Unity.Bridge.dll.meta │ │ ├── SyntaxTree.VisualStudio.Unity.Messaging.dll.meta │ │ ├── UnityVS.VersionSpecific.dll │ │ ├── SyntaxTree.VisualStudio.Unity.Bridge.dll │ │ ├── SyntaxTree.VisualStudio.Unity.Messaging.dll │ │ └── UnityVS.VersionSpecific.dll.meta │ └── Editor.meta ├── Scenes │ ├── Play.unity │ └── Play.unity.meta ├── Prefabs │ ├── Pipe.prefab │ ├── Ground.prefab │ ├── Background.prefab │ ├── Pipe.prefab.meta │ ├── Ground.prefab.meta │ └── Background.prefab.meta ├── Animations │ ├── BirdDead.anim │ ├── Bird.controller │ ├── BirdMoving.anim │ ├── BirdDead.anim.meta │ ├── Bird.controller.meta │ └── BirdMoving.anim.meta ├── Audio │ ├── Cat-meows-sounds.wav │ └── Cat-meows-sounds.wav.meta ├── Sprites │ ├── clony_bird_sprites.png │ └── clony_bird_sprites.png.meta ├── Audio.meta ├── Prefabs.meta ├── Scenes.meta ├── Scripts.meta ├── Sprites.meta ├── UnityVS.meta ├── Animations.meta └── Scripts │ ├── BirdController.cs.meta │ ├── LoopController.cs.meta │ ├── BackgroundCollideController.cs.meta │ ├── LoopController.cs │ ├── BackgroundCollideController.cs │ └── BirdController.cs ├── .gitignore └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # Flappy-Bird-Unity-3D 2 | -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.0.0f4 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Bridge.dll.meta: -------------------------------------------------------------------------------- 1 | guid: 38d405c119fcc7c4e83d4a478a40ff2f 2 | -------------------------------------------------------------------------------- /Assets/Scenes/Play.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/Scenes/Play.unity -------------------------------------------------------------------------------- /Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Messaging.dll.meta: -------------------------------------------------------------------------------- 1 | guid: 4ad02dc83da735c4e8d945332b9202f6 2 | -------------------------------------------------------------------------------- /Assets/Prefabs/Pipe.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/Prefabs/Pipe.prefab -------------------------------------------------------------------------------- /Assets/Prefabs/Ground.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/Prefabs/Ground.prefab -------------------------------------------------------------------------------- /Assets/Animations/BirdDead.anim: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/Animations/BirdDead.anim -------------------------------------------------------------------------------- /Assets/Prefabs/Background.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/Prefabs/Background.prefab -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /Assets/Animations/Bird.controller: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/Animations/Bird.controller -------------------------------------------------------------------------------- /Assets/Animations/BirdMoving.anim: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/Animations/BirdMoving.anim -------------------------------------------------------------------------------- /Assets/Audio/Cat-meows-sounds.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/Audio/Cat-meows-sounds.wav -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Assets/Sprites/clony_bird_sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/Sprites/clony_bird_sprites.png -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Assets/UnityVS/Editor/UnityVS.VersionSpecific.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/UnityVS/Editor/UnityVS.VersionSpecific.dll -------------------------------------------------------------------------------- /Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Bridge.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Bridge.dll -------------------------------------------------------------------------------- /Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Messaging.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/Flappy-Bird-Unity-3D/HEAD/Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Messaging.dll -------------------------------------------------------------------------------- /Assets/Scenes/Play.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d8361a6ec352cc49b6ad0a5dcf07548 3 | timeCreated: 1430381878 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Prefabs/Pipe.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4de17c258fdd7f942b12fc194e2d9a61 3 | timeCreated: 1430392516 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Animations/BirdDead.anim.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b8340e2dc32af1043aa5797511a69a7b 3 | timeCreated: 1430391731 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Prefabs/Ground.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 989dc7d13203bd747ac8f72df9a49300 3 | timeCreated: 1430382091 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Animations/Bird.controller.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c962e026dbfb0e14fa26fc70332b373d 3 | timeCreated: 1430391624 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Animations/BirdMoving.anim.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1a98d7e2b143394bb7ea5736c729228 3 | timeCreated: 1430391624 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Prefabs/Background.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db6c484658cc8464983b6ddfb4f2258c 3 | timeCreated: 1430382076 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Audio.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 206b125436e59a344ad153f501ec7405 3 | folderAsset: yes 4 | timeCreated: 1430398920 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d52f47d46dd9ce4891be9df1b6839e6 3 | folderAsset: yes 4 | timeCreated: 1430382070 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 06ba1623a44de46488342a475bbf7af7 3 | folderAsset: yes 4 | timeCreated: 1430381878 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e9f93d07fe67e04bb2f54a2561afba6 3 | folderAsset: yes 4 | timeCreated: 1430381096 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Sprites.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4d4b4c044a6086c45a162f1267ced58b 3 | folderAsset: yes 4 | timeCreated: 1430380550 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UnityVS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02fe78e962405814a83b8ba6c9471d32 3 | folderAsset: yes 4 | timeCreated: 1430381151 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Animations.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1724290d19073c41a3fb2c9a00ee2e8 3 | folderAsset: yes 4 | timeCreated: 1430391707 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/UnityVS/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e71a3e2fb5854e43823a9da25b68e21 3 | folderAsset: yes 4 | timeCreated: 1430381151 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/BirdController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d0efe40a080cebe419bb6b6d593fb3bb 3 | timeCreated: 1430381101 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/LoopController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 197f92043cd670b46867a2f31f2c01c0 3 | timeCreated: 1430383068 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/BackgroundCollideController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 24da207c6e4d16c4eaa58e82e51f9756 3 | timeCreated: 1430383884 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | 6 | # Autogenerated VS/MD solution and project files 7 | *.csproj 8 | *.unityproj 9 | *.sln 10 | *.suo 11 | *.tmp 12 | *.user 13 | *.userprefs 14 | *.pidb 15 | *.booproj 16 | 17 | # Unity3D generated meta files 18 | *.pidb.meta 19 | 20 | # Unity3D Generated File On Crash Reports 21 | sysinfo.txt 22 | -------------------------------------------------------------------------------- /Assets/UnityVS/Editor/UnityVS.VersionSpecific.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0dbf438744afa864781f46fa46d21de0 3 | timeCreated: 1430381155 4 | licenseType: Free 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 0 13 | settings: {} 14 | Editor: 15 | enabled: 1 16 | settings: 17 | DefaultValueInitialized: true 18 | userData: 19 | assetBundleName: 20 | assetBundleVariant: 21 | -------------------------------------------------------------------------------- /Assets/Audio/Cat-meows-sounds.wav.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: acf4649bad0e4534aa7a58579e6b0e07 3 | timeCreated: 1430398928 4 | licenseType: Free 5 | AudioImporter: 6 | serializedVersion: 6 7 | defaultSettings: 8 | loadType: 0 9 | sampleRateSetting: 0 10 | sampleRateOverride: 0 11 | compressionFormat: 1 12 | quality: 1 13 | conversionMode: 0 14 | platformSettingOverrides: {} 15 | forceToMono: 0 16 | preloadAudioData: 1 17 | loadInBackground: 0 18 | 3D: 1 19 | userData: 20 | assetBundleName: 21 | assetBundleVariant: 22 | -------------------------------------------------------------------------------- /Assets/Scripts/LoopController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class LoopController : MonoBehaviour 4 | { 5 | public GameObject player; 6 | 7 | private float offsetX; 8 | 9 | public void Start() 10 | { 11 | this.offsetX = this.transform.position.x 12 | - this.player.transform.position.x; 13 | } 14 | 15 | public void Update() 16 | { 17 | var position = this.transform.position; 18 | position.x = this.player.transform.position.x + offsetX; 19 | this.transform.position = position; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ivaylo Kenov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Assets/Scripts/BackgroundCollideController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class BackgroundCollideController : MonoBehaviour 4 | { 5 | private int numberOfBackgrounds; 6 | private float distanceBetweenBackgrounds; 7 | 8 | private int numberOfGrounds; 9 | private float distanceBetweenGrounds; 10 | 11 | private int numberOfPipes; 12 | private float distanceBetweenPipes; 13 | 14 | private bool upperPipe; 15 | 16 | public void Start() 17 | { 18 | var backgrounds = GameObject.FindGameObjectsWithTag("Background"); 19 | var grounds = GameObject.FindGameObjectsWithTag("Ground"); 20 | var pipes = GameObject.FindGameObjectsWithTag("Pipe"); 21 | 22 | RandomizePipes(pipes); 23 | 24 | this.numberOfBackgrounds = backgrounds.Length; 25 | this.numberOfGrounds = grounds.Length; 26 | this.numberOfPipes = pipes.Length; 27 | 28 | if (this.numberOfBackgrounds < 2 29 | || this.numberOfGrounds < 2 30 | || this.numberOfPipes < 2) 31 | { 32 | throw new System.InvalidOperationException("You must have at least two backgrounds or grounds or pipes in your scene!"); 33 | } 34 | 35 | this.distanceBetweenBackgrounds = this.DistanceBetweenObjects(backgrounds); 36 | this.distanceBetweenGrounds = this.DistanceBetweenObjects(grounds); 37 | this.distanceBetweenPipes = this.DistanceBetweenObjects(pipes); 38 | } 39 | 40 | public void OnTriggerEnter2D(Collider2D collider) 41 | { 42 | if (collider.CompareTag("Background") 43 | || collider.CompareTag("Ground") 44 | || collider.CompareTag("Pipe")) 45 | { 46 | var go = collider.gameObject; 47 | var originalPosition = go.transform.position; 48 | 49 | if (collider.CompareTag("Background")) 50 | { 51 | originalPosition.x += 52 | this.numberOfBackgrounds 53 | * this.distanceBetweenBackgrounds; 54 | } 55 | else if (collider.CompareTag("Ground")) 56 | { 57 | originalPosition.x += 58 | this.numberOfGrounds 59 | * this.distanceBetweenGrounds; 60 | } 61 | else 62 | { 63 | originalPosition.x += 64 | this.numberOfPipes 65 | * this.distanceBetweenPipes; 66 | 67 | float randomY; 68 | if (this.upperPipe) 69 | { 70 | randomY = Random.Range(1.5f, 3); 71 | } 72 | else 73 | { 74 | randomY = Random.Range(-1, 0.5f); 75 | } 76 | originalPosition.y = randomY; 77 | 78 | this.upperPipe = !this.upperPipe; 79 | } 80 | 81 | go.transform.position = originalPosition; 82 | } 83 | } 84 | 85 | private float DistanceBetweenObjects(GameObject[] gameObjects) 86 | { 87 | float minDistance = float.MaxValue; 88 | 89 | for (int i = 1; i < gameObjects.Length; i++) 90 | { 91 | var currentDistance = Mathf.Abs( 92 | gameObjects[i - 1].transform.position.x 93 | - gameObjects[i].transform.position.x); 94 | 95 | if (currentDistance < minDistance) 96 | { 97 | minDistance = currentDistance; 98 | } 99 | } 100 | 101 | return minDistance; 102 | } 103 | 104 | private void RandomizePipes(GameObject[] pipes) 105 | { 106 | int count = 0; 107 | 108 | for (int i = 1; i < pipes.Length; i++) 109 | { 110 | count++; 111 | var currentPipe = pipes[i]; 112 | float randomY; 113 | if (count % 2 == 0) // upper pipe 114 | { 115 | randomY = Random.Range(1.5f, 3); 116 | } 117 | else // down pipe 118 | { 119 | randomY = Random.Range(-1, 0.5f); 120 | } 121 | 122 | var pipePosition = currentPipe.transform.position; 123 | pipePosition.y = randomY; 124 | currentPipe.transform.position = pipePosition; 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Assets/Scripts/BirdController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class BirdController : MonoBehaviour 4 | { 5 | public float flapSpeed = 1000f; 6 | public float maxFlapSpeed = 100f; 7 | public float forwardSpeed = 100f; 8 | 9 | public AudioClip flapSound; 10 | 11 | private Rigidbody2D rb; 12 | private Animator animator; 13 | private AudioSource audioSource; 14 | 15 | private bool didFlap; 16 | private bool isDead; 17 | 18 | private bool gameStarted; 19 | 20 | private Vector2 originalPosition; 21 | 22 | private GameObject startButton; 23 | 24 | private int score = 0; 25 | 26 | public void Start() 27 | { 28 | this.rb = this.GetComponent(); 29 | this.animator = this.GetComponent(); 30 | this.audioSource = this.GetComponent(); 31 | 32 | this.startButton = GameObject.Find("StartButton"); 33 | this.originalPosition = new Vector2( 34 | this.transform.position.x, 35 | this.transform.position.y); 36 | 37 | this.rb.gravityScale = 0; 38 | this.forwardSpeed = 0; 39 | this.animator.enabled = false; 40 | } 41 | 42 | // read input, change graphics 43 | public void Update() 44 | { 45 | if (Input.GetButtonDown("Fire1")) 46 | { 47 | if (!isDead) 48 | { 49 | if (!this.gameStarted) 50 | { 51 | var renderer = startButton.GetComponent(); 52 | renderer.enabled = false; 53 | this.forwardSpeed = 5; 54 | this.rb.gravityScale = 1; 55 | this.animator.enabled = true; 56 | } 57 | 58 | this.didFlap = true; 59 | this.audioSource.PlayOneShot(this.flapSound); 60 | } 61 | else 62 | { 63 | Application.LoadLevel("Play"); 64 | } 65 | } 66 | } 67 | 68 | // apply physics 69 | public void FixedUpdate() 70 | { 71 | var velocity = this.rb.velocity; 72 | velocity.x = this.forwardSpeed; 73 | this.rb.velocity = velocity; 74 | 75 | if (this.rb.velocity.y > 0) 76 | { 77 | this.rb.MoveRotation(30); 78 | } 79 | else if (!isDead) 80 | { 81 | var angle = velocity.y * 8; 82 | if (angle < -90) 83 | { 84 | angle = -90; 85 | } 86 | this.rb.MoveRotation(angle); 87 | } 88 | 89 | if (didFlap) 90 | { 91 | didFlap = false; 92 | this.rb.AddForce(new Vector2(0, flapSpeed), ForceMode2D.Impulse); 93 | 94 | var updatedVelocity = this.rb.velocity; 95 | if (updatedVelocity.y > this.maxFlapSpeed) 96 | { 97 | updatedVelocity.y = this.maxFlapSpeed; 98 | this.rb.velocity = updatedVelocity; 99 | } 100 | } 101 | } 102 | 103 | public void OnCollisionEnter2D(Collision2D collider) 104 | { 105 | if (collider.gameObject.CompareTag("Floor") || collider.gameObject.CompareTag("PipeCollision")) 106 | { 107 | this.isDead = true; 108 | this.animator.SetBool("BirdDead", true); 109 | this.forwardSpeed = 0; 110 | 111 | var currentHighScore = PlayerPrefs.GetInt("HighScore", 0); 112 | 113 | if (this.score > currentHighScore) 114 | { 115 | PlayerPrefs.SetInt("HighScore", this.score); 116 | } 117 | 118 | var renderer = startButton.GetComponent(); 119 | renderer.enabled = true; 120 | 121 | var startButtonX = Camera.main.transform.position.x; 122 | var startButtonY = Camera.main.transform.position.y; 123 | 124 | var startButtonPosition = this.startButton.transform.position; 125 | startButtonPosition.x = startButtonX; 126 | startButtonPosition.y = startButtonY; 127 | this.startButton.transform.position = startButtonPosition; 128 | } 129 | } 130 | 131 | public void OnTriggerEnter2D(Collider2D collision) 132 | { 133 | if (collision.CompareTag("Pipe")) 134 | { 135 | this.score++; 136 | Debug.Log(score); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Assets/Sprites/clony_bird_sprites.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4d0faeea39af5b642b3ba4314dd00601 3 | timeCreated: 1430380671 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: 7 | 21300000: clony_bird_sprites_0 8 | 21300002: clony_bird_sprites_1 9 | 21300004: clony_bird_sprites_2 10 | 21300006: clony_bird_sprites_3 11 | 21300008: clony_bird_sprites_4 12 | 21300010: clony_bird_sprites_5 13 | 21300012: clony_bird_sprites_6 14 | 21300014: clony_bird_sprites_7 15 | 21300016: clony_bird_sprites_8 16 | 21300018: clony_bird_sprites_9 17 | 21300020: clony_bird_sprites_10 18 | 21300022: clony_bird_sprites_11 19 | 21300024: clony_bird_sprites_12 20 | 21300026: clony_bird_sprites_13 21 | 21300028: clony_bird_sprites_14 22 | 21300030: clony_bird_sprites_15 23 | 21300032: clony_bird_sprites_16 24 | 21300034: clony_bird_sprites_17 25 | 21300036: clony_bird_sprites_18 26 | 21300038: clony_bird_sprites_19 27 | 21300040: clony_bird_sprites_20 28 | 21300042: clony_bird_sprites_21 29 | 21300044: clony_bird_sprites_22 30 | 21300046: clony_bird_sprites_23 31 | 21300048: clony_bird_sprites_24 32 | 21300050: clony_bird_sprites_25 33 | 21300052: clony_bird_sprites_26 34 | 21300054: clony_bird_sprites_27 35 | 21300056: clony_bird_sprites_28 36 | 21300058: clony_bird_sprites_29 37 | 21300060: clony_bird_sprites_30 38 | 21300062: clony_bird_sprites_31 39 | serializedVersion: 2 40 | mipmaps: 41 | mipMapMode: 0 42 | enableMipMap: 1 43 | linearTexture: 0 44 | correctGamma: 0 45 | fadeOut: 0 46 | borderMipMap: 0 47 | mipMapFadeDistanceStart: 1 48 | mipMapFadeDistanceEnd: 3 49 | bumpmap: 50 | convertToNormalMap: 0 51 | externalNormalMap: 0 52 | heightScale: .25 53 | normalMapFilter: 0 54 | isReadable: 0 55 | grayScaleToAlpha: 0 56 | generateCubemap: 0 57 | cubemapConvolution: 0 58 | cubemapConvolutionSteps: 8 59 | cubemapConvolutionExponent: 1.5 60 | seamlessCubemap: 0 61 | textureFormat: -1 62 | maxTextureSize: 2048 63 | textureSettings: 64 | filterMode: -1 65 | aniso: 16 66 | mipBias: -1 67 | wrapMode: 1 68 | nPOTScale: 0 69 | lightmap: 0 70 | rGBM: 0 71 | compressionQuality: 50 72 | spriteMode: 2 73 | spriteExtrude: 1 74 | spriteMeshType: 1 75 | alignment: 0 76 | spritePivot: {x: .5, y: .5} 77 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 78 | spritePixelsToUnits: 10 79 | alphaIsTransparency: 1 80 | textureType: 8 81 | buildTargetSettings: [] 82 | spriteSheet: 83 | sprites: 84 | - name: clony_bird_sprites_0 85 | rect: 86 | serializedVersion: 2 87 | x: 13 88 | y: 79 89 | width: 145 90 | height: 256 91 | alignment: 6 92 | pivot: {x: 0, y: 0} 93 | border: {x: 0, y: 0, z: 0, w: 0} 94 | - name: clony_bird_sprites_1 95 | rect: 96 | serializedVersion: 2 97 | x: 159 98 | y: 279 99 | width: 154 100 | height: 56 101 | alignment: 1 102 | pivot: {x: 0, y: 1} 103 | border: {x: 0, y: 0, z: 0, w: 0} 104 | - name: clony_bird_sprites_2 105 | rect: 106 | serializedVersion: 2 107 | x: 329 108 | y: 314 109 | width: 47 110 | height: 15 111 | alignment: 0 112 | pivot: {x: .5, y: .5} 113 | border: {x: 0, y: 0, z: 0, w: 0} 114 | - name: clony_bird_sprites_3 115 | rect: 116 | serializedVersion: 2 117 | x: 377 118 | y: 314 119 | width: 13 120 | height: 13 121 | alignment: 0 122 | pivot: {x: 0, y: 0} 123 | border: {x: 0, y: 0, z: 0, w: 0} 124 | - name: clony_bird_sprites_4 125 | rect: 126 | serializedVersion: 2 127 | x: 395 128 | y: 314 129 | width: 12 130 | height: 15 131 | alignment: 0 132 | pivot: {x: .5, y: .5} 133 | border: {x: 0, y: 0, z: 0, w: 0} 134 | - name: clony_bird_sprites_5 135 | rect: 136 | serializedVersion: 2 137 | x: 409 138 | y: 314 139 | width: 17 140 | height: 13 141 | alignment: 0 142 | pivot: {x: .5, y: .5} 143 | border: {x: 0, y: 0, z: 0, w: 0} 144 | - name: clony_bird_sprites_6 145 | rect: 146 | serializedVersion: 2 147 | x: 427 148 | y: 314 149 | width: 12 150 | height: 13 151 | alignment: 0 152 | pivot: {x: .5, y: .5} 153 | border: {x: 0, y: 0, z: 0, w: 0} 154 | - name: clony_bird_sprites_7 155 | rect: 156 | serializedVersion: 2 157 | x: 319 158 | y: 289 159 | width: 34 160 | height: 16 161 | alignment: 0 162 | pivot: {x: .5, y: .5} 163 | border: {x: 0, y: 0, z: 0, w: 0} 164 | - name: clony_bird_sprites_8 165 | rect: 166 | serializedVersion: 2 167 | x: 361 168 | y: 290 169 | width: 25 170 | height: 13 171 | alignment: 0 172 | pivot: {x: .5, y: .5} 173 | border: {x: 0, y: 0, z: 0, w: 0} 174 | - name: clony_bird_sprites_9 175 | rect: 176 | serializedVersion: 2 177 | x: 392 178 | y: 290 179 | width: 13 180 | height: 15 181 | alignment: 0 182 | pivot: {x: .5, y: .5} 183 | border: {x: 0, y: 0, z: 0, w: 0} 184 | - name: clony_bird_sprites_10 185 | rect: 186 | serializedVersion: 2 187 | x: 418 188 | y: 290 189 | width: 25 190 | height: 13 191 | alignment: 0 192 | pivot: {x: .5, y: .5} 193 | border: {x: 0, y: 0, z: 0, w: 0} 194 | - name: clony_bird_sprites_11 195 | rect: 196 | serializedVersion: 2 197 | x: 443 198 | y: 290 199 | width: 10 200 | height: 13 201 | alignment: 0 202 | pivot: {x: 0, y: 0} 203 | border: {x: 0, y: 0, z: 0, w: 0} 204 | - name: clony_bird_sprites_12 205 | rect: 206 | serializedVersion: 2 207 | x: 160 208 | y: 264 209 | width: 17 210 | height: 12 211 | alignment: 0 212 | pivot: {x: .5, y: .5} 213 | border: {x: 0, y: 0, z: 0, w: 0} 214 | - name: clony_bird_sprites_13 215 | rect: 216 | serializedVersion: 2 217 | x: 231 218 | y: 134 219 | width: 26 220 | height: 135 221 | alignment: 0 222 | pivot: {x: .5, y: .5} 223 | border: {x: 0, y: 0, z: 0, w: 0} 224 | - name: clony_bird_sprites_14 225 | rect: 226 | serializedVersion: 2 227 | x: 259 228 | y: 148 229 | width: 26 230 | height: 121 231 | alignment: 0 232 | pivot: {x: .5, y: .5} 233 | border: {x: 0, y: 0, z: 0, w: 0} 234 | - name: clony_bird_sprites_15 235 | rect: 236 | serializedVersion: 2 237 | x: 331 238 | y: 266 239 | width: 14 240 | height: 15 241 | alignment: 0 242 | pivot: {x: .5, y: .5} 243 | border: {x: 0, y: 0, z: 0, w: 0} 244 | - name: clony_bird_sprites_16 245 | rect: 246 | serializedVersion: 2 247 | x: 346 248 | y: 266 249 | width: 37 250 | height: 13 251 | alignment: 0 252 | pivot: {x: .5, y: .5} 253 | border: {x: 0, y: 0, z: 0, w: 0} 254 | - name: clony_bird_sprites_17 255 | rect: 256 | serializedVersion: 2 257 | x: 387 258 | y: 266 259 | width: 50 260 | height: 15 261 | alignment: 0 262 | pivot: {x: .5, y: .5} 263 | border: {x: 0, y: 0, z: 0, w: 0} 264 | - name: clony_bird_sprites_18 265 | rect: 266 | serializedVersion: 2 267 | x: 160 268 | y: 246 269 | width: 17 270 | height: 12 271 | alignment: 0 272 | pivot: {x: .5, y: .5} 273 | border: {x: 0, y: 0, z: 0, w: 0} 274 | - name: clony_bird_sprites_19 275 | rect: 276 | serializedVersion: 2 277 | x: 325 278 | y: 241 279 | width: 9 280 | height: 11 281 | alignment: 0 282 | pivot: {x: .5, y: .5} 283 | border: {x: 0, y: 0, z: 0, w: 0} 284 | - name: clony_bird_sprites_20 285 | rect: 286 | serializedVersion: 2 287 | x: 337 288 | y: 241 289 | width: 9 290 | height: 11 291 | alignment: 0 292 | pivot: {x: .5, y: .5} 293 | border: {x: 0, y: 0, z: 0, w: 0} 294 | - name: clony_bird_sprites_21 295 | rect: 296 | serializedVersion: 2 297 | x: 349 298 | y: 241 299 | width: 10 300 | height: 12 301 | alignment: 0 302 | pivot: {x: .5, y: .5} 303 | border: {x: 0, y: 0, z: 0, w: 0} 304 | - name: clony_bird_sprites_22 305 | rect: 306 | serializedVersion: 2 307 | x: 362 308 | y: 241 309 | width: 10 310 | height: 12 311 | alignment: 0 312 | pivot: {x: .5, y: .5} 313 | border: {x: 0, y: 0, z: 0, w: 0} 314 | - name: clony_bird_sprites_23 315 | rect: 316 | serializedVersion: 2 317 | x: 374 318 | y: 241 319 | width: 10 320 | height: 12 321 | alignment: 0 322 | pivot: {x: .5, y: .5} 323 | border: {x: 0, y: 0, z: 0, w: 0} 324 | - name: clony_bird_sprites_24 325 | rect: 326 | serializedVersion: 2 327 | x: 387 328 | y: 241 329 | width: 11 330 | height: 11 331 | alignment: 0 332 | pivot: {x: .5, y: .5} 333 | border: {x: 0, y: 0, z: 0, w: 0} 334 | - name: clony_bird_sprites_25 335 | rect: 336 | serializedVersion: 2 337 | x: 401 338 | y: 241 339 | width: 9 340 | height: 11 341 | alignment: 0 342 | pivot: {x: .5, y: .5} 343 | border: {x: 0, y: 0, z: 0, w: 0} 344 | - name: clony_bird_sprites_26 345 | rect: 346 | serializedVersion: 2 347 | x: 413 348 | y: 241 349 | width: 10 350 | height: 11 351 | alignment: 0 352 | pivot: {x: .5, y: .5} 353 | border: {x: 0, y: 0, z: 0, w: 0} 354 | - name: clony_bird_sprites_27 355 | rect: 356 | serializedVersion: 2 357 | x: 425 358 | y: 241 359 | width: 10 360 | height: 11 361 | alignment: 0 362 | pivot: {x: .5, y: .5} 363 | border: {x: 0, y: 0, z: 0, w: 0} 364 | - name: clony_bird_sprites_28 365 | rect: 366 | serializedVersion: 2 367 | x: 438 368 | y: 241 369 | width: 10 370 | height: 11 371 | alignment: 0 372 | pivot: {x: .5, y: .5} 373 | border: {x: 0, y: 0, z: 0, w: 0} 374 | - name: clony_bird_sprites_29 375 | rect: 376 | serializedVersion: 2 377 | x: 160 378 | y: 230 379 | width: 17 380 | height: 12 381 | alignment: 0 382 | pivot: {x: .5, y: .5} 383 | border: {x: 0, y: 0, z: 0, w: 0} 384 | - name: clony_bird_sprites_30 385 | rect: 386 | serializedVersion: 2 387 | x: 161 388 | y: 214 389 | width: 17 390 | height: 12 391 | alignment: 0 392 | pivot: {x: .5, y: .5} 393 | border: {x: 0, y: 0, z: 0, w: 0} 394 | - name: clony_bird_sprites_31 395 | rect: 396 | serializedVersion: 2 397 | x: 305 398 | y: 154 399 | width: 123 400 | height: 59 401 | alignment: 0 402 | pivot: {x: .5, y: .5} 403 | border: {x: 0, y: 0, z: 0, w: 0} 404 | spritePackingTag: 405 | userData: 406 | assetBundleName: 407 | assetBundleVariant: 408 | --------------------------------------------------------------------------------