adding basic wave tracking and enemy spawning - needs some more work done
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
[System.Serializable]
|
||||
public class Wave
|
||||
{
|
||||
public List<Enemy> enemies;
|
||||
}
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
[Header("Stats")]
|
||||
@@ -19,10 +26,17 @@ public class GameManager : MonoBehaviour
|
||||
public float pickupDelay;
|
||||
public float scoreMultiplier;
|
||||
|
||||
public List<Wave> waves;
|
||||
public GameObject enemyHolder;
|
||||
private Wave currentWave;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
|
||||
|
||||
StartWave();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -31,13 +45,48 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
public void StartWave()
|
||||
{
|
||||
Wave current = waves[wave];
|
||||
if (current != null)
|
||||
{
|
||||
// remove old enemies
|
||||
foreach(Transform child in enemyHolder.transform)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
enemiesConsumed = 0;
|
||||
|
||||
// spawn the enemies
|
||||
currentWave = current;
|
||||
|
||||
for (int i = 0; i < currentWave.enemies.Count; i++)
|
||||
{
|
||||
// spawn enemies in random positions
|
||||
// TODO: do we really want to do this?
|
||||
float spawnZ = Random.Range(Camera.main.ScreenToWorldPoint(new Vector2(0, 0)).z, Camera.main.ScreenToWorldPoint(new Vector2(0, Screen.height)).z);
|
||||
float spawnX = Random.Range(Camera.main.ScreenToWorldPoint(new Vector2(0, 0)).x, Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, 0)).x);
|
||||
|
||||
Vector3 spawnPos = new Vector3(spawnX, player.gameObject.transform.position.y, spawnZ);
|
||||
|
||||
Instantiate(currentWave.enemies[i].gameObject, spawnPos, Quaternion.identity, enemyHolder.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EnemyConsumed(float multiplier = 0)
|
||||
{
|
||||
enemiesConsumed++;
|
||||
|
||||
float incMutliplier = (multiplier > 0) ? multiplier : scoreMultiplier;
|
||||
IncrementScore(10, multiplier);
|
||||
|
||||
score += Mathf.FloorToInt(50 * incMutliplier); // TODO: how do we want this to work exactly?
|
||||
if (enemiesConsumed == currentWave.enemies.Count)
|
||||
{
|
||||
// wave over... start next wave
|
||||
wave++;
|
||||
StartWave();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayerDed()
|
||||
@@ -50,9 +99,10 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
public void IncrementScore(int val)
|
||||
public void IncrementScore(int val, float multiplier = 0)
|
||||
{
|
||||
|
||||
float incMutliplier = (multiplier > 0) ? multiplier : scoreMultiplier;
|
||||
score += Mathf.FloorToInt(50 * incMutliplier); // TODO: how do we want this to work exactly?
|
||||
}
|
||||
|
||||
public void RestartGame()
|
||||
|
||||
@@ -9,6 +9,7 @@ public class UIManager : MonoBehaviour
|
||||
public TextMeshProUGUI playerHealthLabel;
|
||||
public TextMeshProUGUI gameOverLabel;
|
||||
public TextMeshProUGUI scoreLabel;
|
||||
public TextMeshProUGUI waveLabel;
|
||||
|
||||
public Button restartButton;
|
||||
private GameManager gameManager;
|
||||
@@ -27,6 +28,8 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
scoreLabel.text = "Score: " + Mathf.Round(gameManager.score).ToString();
|
||||
|
||||
waveLabel.text = "Wave: " + (gameManager.wave + 1).ToString();
|
||||
|
||||
if (gameManager.player.health <= 0)
|
||||
{
|
||||
gameOverLabel.gameObject.SetActive(true);
|
||||
|
||||
Reference in New Issue
Block a user