setting up enemy consumption and increasing score - maybe change?

This commit is contained in:
Amaan Shawkath
2022-04-19 21:43:27 +01:00
parent 209470d610
commit e2511e2d53
7 changed files with 6779 additions and 10 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c3c99fe455db51e41bed31b035a387f5
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -21,10 +21,12 @@ public class BulletManager : MonoBehaviour
public List<PatternMap> PatternMap = new List<PatternMap>();
public Pattern[] activePatterns;
private GameManager gameManager;
// Start is called before the first frame update
void Start()
{
gameManager = FindObjectOfType<GameManager>();
}
// Update is called once per frame
@@ -33,6 +35,11 @@ public class BulletManager : MonoBehaviour
}
public void EnemyConsumed(float multiplier)
{
gameManager.EnemyConsumed(multiplier);
}
public void SpawnPattern(PatternTypes pattern, Enemy enemy)
{
GameObject patternObject = Instantiate(PatternMap.Find(x => x.patternType == pattern).pattern, enemy.transform.position, Quaternion.identity);

View File

@@ -31,9 +31,13 @@ public class GameManager : MonoBehaviour
}
public void EnemyConsumed()
public void EnemyConsumed(float multiplier = 0)
{
enemiesConsumed++;
float incMutliplier = (multiplier > 0) ? multiplier : scoreMultiplier;
score += Mathf.FloorToInt(50 * incMutliplier); // TODO: how do we want this to work exactly?
}
public void PlayerDed()

View File

@@ -20,7 +20,7 @@ public class Pattern : MonoBehaviour
{
OnPatternUpdate();
duration -= Time.deltaTime;
if (duration <= 0)
if (duration <= 0 || enemy.IsDead)
{
//find all particle systems in children and stop them
foreach (ParticleSystem ps in GetComponentsInChildren<ParticleSystem>())

View File

@@ -8,6 +8,8 @@ public class UIManager : MonoBehaviour
{
public TextMeshProUGUI playerHealthLabel;
public TextMeshProUGUI gameOverLabel;
public TextMeshProUGUI scoreLabel;
public Button restartButton;
private GameManager gameManager;
@@ -23,11 +25,12 @@ public class UIManager : MonoBehaviour
//round player health
playerHealthLabel.text = "Health: " + Mathf.Round(gameManager.player.health).ToString();
scoreLabel.text = "Score: " + Mathf.Round(gameManager.score).ToString();
if (gameManager.player.health <= 0)
{
gameOverLabel.gameObject.SetActive(true);
restartButton.gameObject.SetActive(true);
}
}
}

View File

@@ -7,6 +7,10 @@ public class Enemy : MonoBehaviour
public int baseScore;
public PatternTypes[] patterns;
public int CurrentPattern = 0;
public float scoreMultiplier = 0;
public bool IsDead { get; private set; }
private BulletManager bulletManager;
// Start is called before the first frame update
@@ -24,23 +28,39 @@ public class Enemy : MonoBehaviour
private void Attack()
{
bulletManager.SpawnPattern(patterns[CurrentPattern], this);
bulletManager.SpawnPattern(patterns[CurrentPattern], this);
}
public void Consumed()
{
gameObject.SetActive(false); // TODO: some sort of effect
// once the enemy dies it should stop emitting bullets but keep any active bullets running
IsDead = true;
bulletManager.EnemyConsumed(scoreMultiplier);
}
public void OnPatternFinished()
{
CurrentPattern++;
if (CurrentPattern >= patterns.Length)
if (gameObject.activeSelf)
{
//Destroy(gameObject);
CurrentPattern++;
if (CurrentPattern >= patterns.Length)
{
//Destroy(gameObject);
}
Attack();
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<Player>())
{
// okay.. player hit so we're being consumed
Consumed();
}
Attack();
}
}