summaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorMarvin Borner2018-05-23 17:39:17 +0200
committerMarvin Borner2018-05-23 17:39:17 +0200
commit47c3a3275c5eb110c10933bc3dceb5eb3b89eb72 (patch)
treef74d8562441d7bcbf5c5d8f39d8eed3578161426 /Assets/Scripts
Added basic jumping and background moving
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Bird.cs41
-rw-r--r--Assets/Scripts/Bird.cs.meta11
-rw-r--r--Assets/Scripts/GameControl.cs39
-rw-r--r--Assets/Scripts/GameControl.cs.meta11
-rw-r--r--Assets/Scripts/ScrollingObject.cs23
-rw-r--r--Assets/Scripts/ScrollingObject.cs.meta11
6 files changed, 136 insertions, 0 deletions
diff --git a/Assets/Scripts/Bird.cs b/Assets/Scripts/Bird.cs
new file mode 100644
index 0000000..3f1aab4
--- /dev/null
+++ b/Assets/Scripts/Bird.cs
@@ -0,0 +1,41 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Bird : MonoBehaviour {
+
+ public float upForce = 200f;
+
+ private bool isDead = false;
+ private Rigidbody2D rb2d;
+ private Animator anim;
+
+ // Use this for initialization
+ void Start ()
+ {
+ rb2d = GetComponent<Rigidbody2D>();
+ anim = GetComponent<Animator>();
+ }
+
+ // Update is called once per frame
+ void Update ()
+ {
+ if (isDead == false)
+ {
+ if (Input.GetMouseButtonDown(0)) // Left click
+ {
+ rb2d.velocity = Vector2.zero;
+ rb2d.AddForce(new Vector2(0, upForce));
+ anim.SetTrigger("Flap");
+ }
+ }
+ }
+
+ void OnCollisionEnter2D(Collision2D collision)
+ {
+ rb2d.velocity = Vector2.zero;
+ isDead = true;
+ anim.SetTrigger("Die");
+ GameControl.instance.BirdDied();
+ }
+}
diff --git a/Assets/Scripts/Bird.cs.meta b/Assets/Scripts/Bird.cs.meta
new file mode 100644
index 0000000..1da3c7e
--- /dev/null
+++ b/Assets/Scripts/Bird.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: a9e5ca9caff891845a74ec9dd69b716b
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/GameControl.cs b/Assets/Scripts/GameControl.cs
new file mode 100644
index 0000000..afd79b7
--- /dev/null
+++ b/Assets/Scripts/GameControl.cs
@@ -0,0 +1,39 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.SceneManagement;
+
+public class GameControl : MonoBehaviour {
+
+ public static GameControl instance;
+ public GameObject gameOverText;
+ public bool gameOver = false;
+ public float scrollSpeed = -1.5f;
+
+ // Use this for initialization
+ void Awake ()
+ {
+ if (instance == null)
+ {
+ instance = this;
+ } else if (instance != this)
+ {
+ Destroy(gameObject);
+ }
+ }
+
+ // Update is called once per frame
+ void Update ()
+ {
+ if (gameOver == true && Input.GetMouseButtonDown(0)) // True and Leftclick
+ {
+ SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); // Reload currently active scene
+ }
+ }
+
+ public void BirdDied()
+ {
+ gameOverText.SetActive(true);
+ gameOver = true;
+ }
+}
diff --git a/Assets/Scripts/GameControl.cs.meta b/Assets/Scripts/GameControl.cs.meta
new file mode 100644
index 0000000..ea6e843
--- /dev/null
+++ b/Assets/Scripts/GameControl.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: cbd6dfc63ace2b542919bb50612614a7
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/ScrollingObject.cs b/Assets/Scripts/ScrollingObject.cs
new file mode 100644
index 0000000..e2b51e5
--- /dev/null
+++ b/Assets/Scripts/ScrollingObject.cs
@@ -0,0 +1,23 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class ScrollingObject : MonoBehaviour {
+
+ private Rigidbody2D rb2d;
+
+ // Use this for initialization
+ void Start ()
+ {
+ rb2d = GetComponent<Rigidbody2D>();
+ rb2d.velocity = new Vector2(GameControl.instance.scrollSpeed, 0);
+ }
+
+ // Update is called once per frame
+ void Update () {
+ if (GameControl.instance.gameOver == true)
+ {
+ rb2d.velocity = Vector2.zero;
+ }
+ }
+}
diff --git a/Assets/Scripts/ScrollingObject.cs.meta b/Assets/Scripts/ScrollingObject.cs.meta
new file mode 100644
index 0000000..63be434
--- /dev/null
+++ b/Assets/Scripts/ScrollingObject.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5912db75c1bb467498e47dee365735ab
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: