-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyManager.cs
91 lines (84 loc) · 3.22 KB
/
EnemyManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
namespace Typocalypse
{
public class EnemyManager:GameComponent
{
//TODO:Refactor magic numbers
private const int YPosition = -50;
private readonly Random randGenerator;
private const int generateInterval = 3000;
private TimeSpan lastTimeGenerated;
public static readonly List<Enemy> enemies = new List<Enemy>();
private readonly Player player;
public EnemyInputManager InputManager{ get; set;}
public bool IsActive { get; set; }
private readonly List<string> wordList;
public double DifficultyBias { get; set; }
private const int checkpointInterval = 10;
private int nextCheckpointScore;
private const double minBias = 0.01;
private const double maxBias = 0.99;
private const double biasInterval = 0.01;
public EnemyManager(Game game, Player player, List<string> wordList):base(game)
{
randGenerator = new Random();
this.player = player;
IsActive = true;
InputManager = new EnemyInputManager(wordList, game);
this.wordList = wordList;
DifficultyBias = maxBias;
nextCheckpointScore = checkpointInterval;
}
Enemy GenerateEnemy()
{
return new Enemy(Game, GeneratePosition(), MathHelper.ToRadians(0), 0.9f, "zombie", 0.5f, "dev",player);
}
Vector2 GeneratePosition()
{
return new Vector2(randGenerator.Next(Game.GraphicsDevice.PresentationParameters.BackBufferWidth), YPosition);
}
public override void Update(GameTime gameTime)
{
//TODO:refactor below if statements
if (!IsActive)
{
return;
}
if (lastTimeGenerated.TotalMilliseconds == 0)
{
lastTimeGenerated = gameTime.TotalGameTime;
}
if (gameTime.TotalGameTime.TotalMilliseconds - lastTimeGenerated.TotalMilliseconds < generateInterval)
{
return;
}
lastTimeGenerated = gameTime.TotalGameTime;
var newEnemy = GenerateEnemy();
newEnemy.TextBox = InputManager.RegisterEnemy(newEnemy, DifficultyBias);
wordList.Remove(newEnemy.TextBox.Text);
enemies.Add(newEnemy);
Game.Components.Add(newEnemy);
newEnemy.Dead += (s, e) =>
{
enemies.Remove((Enemy) s);
player.EnemyKilled(10);
};
if (player.Score >= nextCheckpointScore && DifficultyBias > minBias)
{
nextCheckpointScore += checkpointInterval;
DifficultyBias -= biasInterval;
}
base.Update(gameTime);
}
public void PlayerIsHit()
{
IsActive = false;
foreach (var enemy in enemies)
{
enemy.IsActive = false;
}
}
}
}