From 893160bc3047aa14321943fa52fcd20330d804db Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Tue, 17 Oct 2017 22:05:53 +0200 Subject: Added paycheck-system, player gets payed after wave is finished --- td/.idea/.idea.td/.idea/workspace.xml | 910 +++++++++++++++++++--------------- td/Assets/Scripts/Enemy.cs | 1 + td/Assets/Scripts/Projectile.cs | 1 + td/Assets/Scripts/player.cs | 14 + td/Assets/Scripts/waveSpawner.cs | 32 +- td/Assets/Scripts/waveSpawner.cs.meta | 2 +- 6 files changed, 556 insertions(+), 404 deletions(-) (limited to 'td') diff --git a/td/.idea/.idea.td/.idea/workspace.xml b/td/.idea/.idea.td/.idea/workspace.xml index c304f2f..5934d93 100644 --- a/td/.idea/.idea.td/.idea/workspace.xml +++ b/td/.idea/.idea.td/.idea/workspace.xml @@ -2,8 +2,8 @@ - + - - + + - - + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -157,6 +100,7 @@ toggle + spawnRa @@ -176,25 +120,23 @@ - - - - - - + + + + + - - + + - + @@ -234,7 +179,6 @@ - @@ -247,47 +191,16 @@ - - - - - - - - - - - - - - - - - - + - + @@ -373,7 +286,7 @@ false - + @@ -401,11 +314,15 @@ + + + + - @@ -427,7 +344,7 @@ - + @@ -488,146 +405,380 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + + - - + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + - - + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + - - - + + + @@ -635,71 +786,49 @@ - + - - - - - - - - - - - - - - - - - - - - - - - + - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -708,25 +837,24 @@ - - + - + - + @@ -744,32 +872,31 @@ - - + - + - + - + @@ -783,146 +910,125 @@ - + - + - + - - + + - + - - + + - + - - + + - + + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - + + - + - - - + + - + - - + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + 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().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; } @@ -95,6 +102,29 @@ public class WaveSpawner : MonoBehaviour { yield return new WaitForSeconds(1f / 100f); } + 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++; } 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 -- cgit v1.2.3