summaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Column.cs13
-rw-r--r--Assets/Scripts/Column.cs.meta11
-rw-r--r--Assets/Scripts/ColumnPool.cs47
-rw-r--r--Assets/Scripts/ColumnPool.cs.meta11
-rw-r--r--Assets/Scripts/GameControl.cs14
-rw-r--r--Assets/Scripts/RepeatingBackground.cs30
-rw-r--r--Assets/Scripts/RepeatingBackground.cs.meta11
7 files changed, 137 insertions, 0 deletions
diff --git a/Assets/Scripts/Column.cs b/Assets/Scripts/Column.cs
new file mode 100644
index 0000000..2468c0b
--- /dev/null
+++ b/Assets/Scripts/Column.cs
@@ -0,0 +1,13 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Column : MonoBehaviour {
+ private void OnTriggerEnter2D(Collider2D other)
+ {
+ if (other.GetComponent<Bird>() != null)
+ {
+ GameControl.instance.BirdScored();
+ }
+ }
+}
diff --git a/Assets/Scripts/Column.cs.meta b/Assets/Scripts/Column.cs.meta
new file mode 100644
index 0000000..6d586c8
--- /dev/null
+++ b/Assets/Scripts/Column.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 507311850444501439bf73c415a849c4
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/ColumnPool.cs b/Assets/Scripts/ColumnPool.cs
new file mode 100644
index 0000000..34d10b8
--- /dev/null
+++ b/Assets/Scripts/ColumnPool.cs
@@ -0,0 +1,47 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class ColumnPool : MonoBehaviour {
+
+ public int columnPoolSize = 5;
+ public GameObject columnPrefab;
+ public float spawnRate = 4f;
+ public float columnMin = -1f;
+ public float columnMax = 3.5f;
+
+ private GameObject[] columns;
+ private Vector2 objectPoolPosition = new Vector2(-15f, 25f);
+ private float timeSinceLastSpawned;
+ private float spawnXPosition = 10f;
+ private int currentColumn = 0;
+
+
+ // Use this for initialization
+ void Start ()
+ {
+ columns = new GameObject[columnPoolSize];
+ for (int i = 0; i < columnPoolSize; i++)
+ {
+ columns[i] = (GameObject)Instantiate(columnPrefab, objectPoolPosition, Quaternion.identity);
+ }
+ }
+
+ // Update is called once per frame
+ void Update ()
+ {
+ timeSinceLastSpawned += Time.deltaTime;
+
+ if (GameControl.instance.gameOver == false && timeSinceLastSpawned >= spawnRate)
+ {
+ timeSinceLastSpawned = 0;
+ float spawnYPosition = Random.Range(columnMin, columnMax);
+ columns[currentColumn].transform.position = new Vector2(spawnXPosition, spawnYPosition);
+ currentColumn++;
+ if (currentColumn >= columnPoolSize)
+ {
+ currentColumn = 0;
+ }
+ }
+ }
+}
diff --git a/Assets/Scripts/ColumnPool.cs.meta b/Assets/Scripts/ColumnPool.cs.meta
new file mode 100644
index 0000000..9443cf7
--- /dev/null
+++ b/Assets/Scripts/ColumnPool.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 92bc843fdec1c82468ce24704bbbb884
+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
index afd79b7..77f58d7 100644
--- a/Assets/Scripts/GameControl.cs
+++ b/Assets/Scripts/GameControl.cs
@@ -2,14 +2,18 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
+using UnityEngine.UI;
public class GameControl : MonoBehaviour {
public static GameControl instance;
public GameObject gameOverText;
+ public Text scoreText;
public bool gameOver = false;
public float scrollSpeed = -1.5f;
+ private int score = 0;
+
// Use this for initialization
void Awake ()
{
@@ -31,6 +35,16 @@ public class GameControl : MonoBehaviour {
}
}
+ public void BirdScored()
+ {
+ if (gameOver)
+ {
+ return;
+ }
+ score++;
+ scoreText.text = "Score: " + score.ToString();
+ }
+
public void BirdDied()
{
gameOverText.SetActive(true);
diff --git a/Assets/Scripts/RepeatingBackground.cs b/Assets/Scripts/RepeatingBackground.cs
new file mode 100644
index 0000000..4722ec2
--- /dev/null
+++ b/Assets/Scripts/RepeatingBackground.cs
@@ -0,0 +1,30 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class RepeatingBackground : MonoBehaviour {
+
+ private BoxCollider2D groundCollider;
+ private float groundHorizontalLength;
+
+ // Use this for initialization
+ void Start ()
+ {
+ groundCollider = GetComponent<BoxCollider2D>();
+ groundHorizontalLength = groundCollider.size.x;
+ }
+
+ // Update is called once per frame
+ void Update () {
+ if (transform.position.x < -groundHorizontalLength)
+ {
+ RepositionBackground();
+ }
+ }
+
+ private void RepositionBackground()
+ {
+ Vector2 groundOffset = new Vector2(groundHorizontalLength * 2f, 0);
+ transform.position = (Vector2)transform.position + groundOffset;
+ }
+}
diff --git a/Assets/Scripts/RepeatingBackground.cs.meta b/Assets/Scripts/RepeatingBackground.cs.meta
new file mode 100644
index 0000000..4c10802
--- /dev/null
+++ b/Assets/Scripts/RepeatingBackground.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 556a9e4cdeae67a4abffedaf4c8030ff
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: