diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-17 22:05:53 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-17 22:05:53 +0200 |
commit | 893160bc3047aa14321943fa52fcd20330d804db (patch) | |
tree | c45502accbbfb75035f7da92dc7c787b462189af /td/Assets | |
parent | 0aff61a37fa8502521e760a78d8e51b614503773 (diff) | |
download | TD-893160bc3047aa14321943fa52fcd20330d804db.tar.gz TD-893160bc3047aa14321943fa52fcd20330d804db.zip |
Added paycheck-system, player gets payed after wave is finished
Diffstat (limited to 'td/Assets')
-rw-r--r-- | td/Assets/Scripts/Enemy.cs | 1 | ||||
-rw-r--r-- | td/Assets/Scripts/Projectile.cs | 1 | ||||
-rw-r--r-- | td/Assets/Scripts/player.cs | 14 | ||||
-rw-r--r-- | td/Assets/Scripts/waveSpawner.cs | 32 | ||||
-rw-r--r-- | td/Assets/Scripts/waveSpawner.cs.meta | 2 |
5 files changed, 48 insertions, 2 deletions
diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs index 4d15b64..931f301 100644 --- a/td/Assets/Scripts/Enemy.cs +++ b/td/Assets/Scripts/Enemy.cs @@ -6,6 +6,7 @@ public class Enemy : MonoBehaviour { * Currently it follows the pathway, and dies when reacing the end */ [Header("Attributes")] + public int HeadPrice; public float Speed; // Speed multiplier public int InitialHp; // HealthPoints public int Damage; diff --git a/td/Assets/Scripts/Projectile.cs b/td/Assets/Scripts/Projectile.cs index 3b02763..e8c427c 100644 --- a/td/Assets/Scripts/Projectile.cs +++ b/td/Assets/Scripts/Projectile.cs @@ -36,6 +36,7 @@ public class Projectile : MonoBehaviour { void HitTarget() { WaveSpawner.EnemiesAlive--; Player.ScoreAdd (PointsPerHit); + Player.PaycheckAdd(_target.GetComponent<Enemy>().HeadPrice); Destroy (_target.gameObject); Destroy (gameObject); } diff --git a/td/Assets/Scripts/player.cs b/td/Assets/Scripts/player.cs index cb55357..608d09c 100644 --- a/td/Assets/Scripts/player.cs +++ b/td/Assets/Scripts/player.cs @@ -9,6 +9,7 @@ public class Player : MonoBehaviour { private int _gameState; private GameObject[] _towers; private int _playerMoney; + private int _playerPaycheck; private int _playerScore; private int _playerHealth; @@ -41,6 +42,19 @@ public class Player : MonoBehaviour { _playerMoney -= sum; } + public int Paycheck() { + return _playerPaycheck; + } + + public void PaycheckAdd(int sum) { + _playerPaycheck += sum; + } + + public void Payday() { + _playerMoney += _playerPaycheck; + _playerPaycheck = 0; + } + public int Health() { return _playerHealth; } diff --git a/td/Assets/Scripts/waveSpawner.cs b/td/Assets/Scripts/waveSpawner.cs index 3a6d7d4..6444cfd 100644 --- a/td/Assets/Scripts/waveSpawner.cs +++ b/td/Assets/Scripts/waveSpawner.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; + public class WaveSpawner : MonoBehaviour { [Header("Attributes")] @@ -27,6 +28,7 @@ public class WaveSpawner : MonoBehaviour { public static int EnemiesAlive = 0; private float _countdown = 2f; private int _waveIndex = 0; + private bool _lastWavePayed; void Awake() { foreach (Transform child in PathWay) { @@ -43,8 +45,13 @@ public class WaveSpawner : MonoBehaviour { return; } + if (EnemiesAlive == 0 && !_lastWavePayed) { + Player.Payday(); + _lastWavePayed = true; + } + if (_countdown <= 0f) { - StartCoroutine(SpawnWave()); + StartCoroutine(SpawnWave()); // TODO Bytt ut denne med SpawnWaveRand (Gjør ferdig SpawnWaveRand) _countdown = TimeBetweenWaves; return; } @@ -97,6 +104,29 @@ public class WaveSpawner : MonoBehaviour { SpawnRate = SpawnRate * 2; _waveIndex++; + _lastWavePayed = false; + } + + IEnumerator SpawnWaveRand() { + int enemiesToSpawn = WaveEnemyCount(_waveIndex); + int[] waveEnemies = new int[Enemies.Length - 1]; + EnemiesAlive = enemiesToSpawn; + + for (int i = 1; i < enemiesToSpawn; i++) { + int currentEnemyInt = UnityEngine.Random.Range(0, Enemies.Length - 1); + EnemyType currentEnemy = Enemies[currentEnemyInt]; + + if (_waveIndex <= 1) { + } else if (_waveIndex <= 5) { + + } + + + yield return new WaitForSeconds(1f / SpawnRate); + } + + SpawnRate = SpawnRate * 2; + _waveIndex++; } void SpawnEnemy (GameObject enemyPrefab) { diff --git a/td/Assets/Scripts/waveSpawner.cs.meta b/td/Assets/Scripts/waveSpawner.cs.meta index 1f1e3cb..ed1c24d 100644 --- a/td/Assets/Scripts/waveSpawner.cs.meta +++ b/td/Assets/Scripts/waveSpawner.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: 9ea53d824cbfc4eb8a4eb4ee6a247bc7 -timeCreated: 1507241433 +timeCreated: 1508270424 licenseType: Free MonoImporter: serializedVersion: 2 |