aboutsummaryrefslogtreecommitdiff
path: root/td/Assets
diff options
context:
space:
mode:
Diffstat (limited to 'td/Assets')
-rw-r--r--td/Assets/Prefabs/Enemies/Enemy.prefabbin7968 -> 7968 bytes
-rw-r--r--td/Assets/Scenes/Level 1.unitybin122396 -> 123228 bytes
-rw-r--r--td/Assets/Scripts/Enemy.cs2
-rw-r--r--td/Assets/Scripts/EnemySpawner.cs49
-rw-r--r--td/Assets/Scripts/EnemySpawner.cs.meta12
-rw-r--r--td/Assets/Scripts/Projectile.cs1
-rw-r--r--td/Assets/Scripts/tower.cs1
-rw-r--r--td/Assets/Scripts/waveSpawner.cs92
8 files changed, 84 insertions, 73 deletions
diff --git a/td/Assets/Prefabs/Enemies/Enemy.prefab b/td/Assets/Prefabs/Enemies/Enemy.prefab
index ed40756..38900d3 100644
--- a/td/Assets/Prefabs/Enemies/Enemy.prefab
+++ b/td/Assets/Prefabs/Enemies/Enemy.prefab
Binary files differ
diff --git a/td/Assets/Scenes/Level 1.unity b/td/Assets/Scenes/Level 1.unity
index e93598e..23478b5 100644
--- a/td/Assets/Scenes/Level 1.unity
+++ b/td/Assets/Scenes/Level 1.unity
Binary files differ
diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs
index 20436db..4d15b64 100644
--- a/td/Assets/Scripts/Enemy.cs
+++ b/td/Assets/Scripts/Enemy.cs
@@ -10,6 +10,7 @@ public class Enemy : MonoBehaviour {
public int InitialHp; // HealthPoints
public int Damage;
public List<Vector3> Waypoints; // Pathway waypoints, should be set by the spawner
+
[Header("Scripting vars")]
public Player Player; // Reference to the player object, should be set when instantiating
@@ -29,6 +30,7 @@ public class Enemy : MonoBehaviour {
// Selfdestruct if object reached the end
if (_waypointNum + 1 >= Waypoints.Count) {
+ WaveSpawner.EnemiesAlive--;
Player.DecreaseHealth (Damage);
Destroy (gameObject);
return;
diff --git a/td/Assets/Scripts/EnemySpawner.cs b/td/Assets/Scripts/EnemySpawner.cs
deleted file mode 100644
index a1a6b1f..0000000
--- a/td/Assets/Scripts/EnemySpawner.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class EnemySpawner : MonoBehaviour {
- /* This is a class that spawns an enemy with a random interval
- * it is not very good, but is what it needs to be for testing purposes */
- // TODO Add wave system with increasing difficulty
- public Enemy EnemyPrefab;
- public Transform PathWay;
- [Header("Scripting vars")]
- public Player Player; // Reference to the player object, should be set in designer
-
- private Transform _parentObject;
-
- private List<Vector3> _waypoints = new List<Vector3>();
- private int _next = 1;
- private int _n = 0;
-
- void Awake() {
- foreach (Transform child in PathWay) {
- _waypoints.Add (child.position);
- }
- }
-
- void Start() {
- _parentObject = transform.Find ("enemies").gameObject.GetComponent <Transform> ();
- }
-
- void Update () {
- if (Player.GameIsPaused()) { return; } // This ensures that the game stays paused
- _n++;
-
- if (_n == _next) {
- _n = 0;
- _next = (int)Random.Range (50, 400);
-
- Enemy newEnemy = Instantiate (EnemyPrefab, new Vector3(0, 0, 0), Quaternion.identity, _parentObject);
- Enemy script = newEnemy.GetComponent <Enemy> ();
- Transform transform = newEnemy.GetComponent <Transform>();
-
- script.Waypoints = _waypoints;
- script.Speed = Random.Range (0.3f, 1.2f);
- script.Player = Player;
- transform.position = new Vector3 (0.93f, 0.483f, 0f);
- }
-
- }
-}
diff --git a/td/Assets/Scripts/EnemySpawner.cs.meta b/td/Assets/Scripts/EnemySpawner.cs.meta
deleted file mode 100644
index 3fe504e..0000000
--- a/td/Assets/Scripts/EnemySpawner.cs.meta
+++ /dev/null
@@ -1,12 +0,0 @@
-fileFormatVersion: 2
-guid: 3e57c25f0405b40cab5c30b2c92671ae
-timeCreated: 1506633566
-licenseType: Free
-MonoImporter:
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/td/Assets/Scripts/Projectile.cs b/td/Assets/Scripts/Projectile.cs
index 0cdef16..3b02763 100644
--- a/td/Assets/Scripts/Projectile.cs
+++ b/td/Assets/Scripts/Projectile.cs
@@ -34,6 +34,7 @@ public class Projectile : MonoBehaviour {
}
void HitTarget() {
+ WaveSpawner.EnemiesAlive--;
Player.ScoreAdd (PointsPerHit);
Destroy (_target.gameObject);
Destroy (gameObject);
diff --git a/td/Assets/Scripts/tower.cs b/td/Assets/Scripts/tower.cs
index d99f937..004605b 100644
--- a/td/Assets/Scripts/tower.cs
+++ b/td/Assets/Scripts/tower.cs
@@ -89,7 +89,6 @@ public class Tower : MonoBehaviour {
_fireCountdown -= Time.deltaTime;
-
}
void Shoot() {
diff --git a/td/Assets/Scripts/waveSpawner.cs b/td/Assets/Scripts/waveSpawner.cs
index 73c0bc3..3a6d7d4 100644
--- a/td/Assets/Scripts/waveSpawner.cs
+++ b/td/Assets/Scripts/waveSpawner.cs
@@ -6,16 +6,38 @@ using UnityEngine.UI;
public class WaveSpawner : MonoBehaviour {
+ [Header("Attributes")]
+ public float TimeBetweenWaves;
+ public float SpawnRate;
+
+ [Header("Objects")]
public Transform SpawnPoint;
+ public Transform PathWay;
public Text WaveCountdownText;
- public float TimeBetweenWaves = 5f;
+
+ [Header("Every possible enemy")]
+ public EnemyType[] Enemies;
+
[Header("Scripting vars")]
public Player Player; // Reference to the player object, should be set in designer
+ private Transform _parentObject;
+ private List<Vector3> _waypoints = new List<Vector3>();
+
public static int EnemiesAlive = 0;
private float _countdown = 2f;
private int _waveIndex = 0;
+ void Awake() {
+ foreach (Transform child in PathWay) {
+ _waypoints.Add (child.position);
+ }
+ }
+
+ void Start() {
+ _parentObject = transform.Find ("enemies").gameObject.GetComponent <Transform> ();
+ }
+
void Update () {
if (EnemiesAlive > 0) {
return;
@@ -32,24 +54,72 @@ public class WaveSpawner : MonoBehaviour {
//waveCountdownText.text = string.Format("{0:00.00}", countdown);
}
+ private int WaveEnemyCount(int waveNum) {
+ // 10.64 * e^0,57x
+ float pow = (float) Math.Pow( Math.E, 0.57f * waveNum);
+ return (int) Math.Floor(10.64f * pow);
+ }
+
+ private float EnemyAmountThing(int currentEnemy, int maxTypes) {
+ // TODO Change the for loop into a faster method
+ float rest = 1;
+
+ for (int i=1; i <= maxTypes; i++) {
+ if (i != maxTypes) { rest = rest / 2; }
+ if (i == currentEnemy + 1) { return rest; }
+ }
+
+ return 0;
+ }
+
IEnumerator SpawnWave () {
- int waveNum = 1;
- int gdshj = Mathf.FloorToInt(10.64 * (Math.Pow(Math.E, (0.57 * waveNum)))));
+ int enemiesToSpawn = WaveEnemyCount(_waveIndex);
+ EnemiesAlive = enemiesToSpawn;
+ List<WaveElement> wave = new List<WaveElement>();
+
+ for (int i = 0; i < Enemies.Length; i++) {
+ EnemyType enemy = Enemies[i];
- EnemiesAlive = wave.Count;
+ float amount = enemiesToSpawn * EnemyAmountThing(i, Enemies.Length);
+ if (amount >= 1) {
+ wave.Add(new WaveElement {Prefab = enemy.Enemy, Amount = (int)Math.Floor(amount)} );
+ }
+
+ }
- for (int i = 0; i < wave.Count; i++)
- {
- SpawnEnemy(wave.Enemy);
- yield return new WaitForSeconds(1f / wave.Rate);
+ foreach (var enemyType in wave) {
+ for (int i = 0; i < enemyType.Amount; i++) {
+ SpawnEnemy(enemyType.Prefab);
+ yield return new WaitForSeconds(1f / SpawnRate);
+ }
+ yield return new WaitForSeconds(1f / 100f);
}
+ SpawnRate = SpawnRate * 2;
_waveIndex++;
}
- void SpawnEnemy (GameObject enemy)
- {
- Instantiate(enemy, SpawnPoint.position, SpawnPoint.rotation);
+ void SpawnEnemy (GameObject enemyPrefab) {
+ GameObject newEnemy = Instantiate (enemyPrefab, new Vector3(0, 0, 0), Quaternion.identity, _parentObject);
+ Enemy script = newEnemy.GetComponent <Enemy> ();
+ Transform transform = newEnemy.GetComponent <Transform>();
+
+ script.Waypoints = _waypoints;
+ script.Player = Player;
+ transform.position = new Vector3 (0.93f, 0.483f, 0f);
+ }
+
+ [System.Serializable]
+ public class EnemyType {
+ public string Name;
+ public GameObject Enemy;
+ [Range(0, 1)]
+ public float Percentage;
}
+ public class WaveElement {
+ public GameObject Prefab { get; set; }
+ public int Amount { get; set; }
+ }
+
} \ No newline at end of file