diff options
Diffstat (limited to 'Penguloon/Levels/Map.cs')
| -rw-r--r-- | Penguloon/Levels/Map.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Penguloon/Levels/Map.cs b/Penguloon/Levels/Map.cs index 699d9eb..19fd7c0 100644 --- a/Penguloon/Levels/Map.cs +++ b/Penguloon/Levels/Map.cs @@ -1,6 +1,9 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Penguloon.Enemies; using Penguloon.Scenes; +using System.Collections.Generic; +using System; namespace Penguloon.Levels { @@ -17,6 +20,14 @@ namespace Penguloon.Levels public SceneBase ParentScene { get; set; } + public List<EnemyBase> Enemies { get; set; } = new List<EnemyBase>(); + + public Vector2 SpawnPoint { get; set; } + public Vector2 SpawnPointTargetPos { get; set; } + public Vector2 FinishPoint { get; set; } + + public WaveManager WaveManager { get; set; } + public Map(SceneBase parentScene) { this.ParentScene = parentScene; @@ -28,6 +39,8 @@ namespace Penguloon.Levels TileHeight = MapHeight / 13; MapWidth = TileWidth * 18; + + WaveManager = new WaveManager(this); } public void Draw(float deltaTime) @@ -42,11 +55,49 @@ namespace Penguloon.Levels destinationRectangle: new Rectangle(x * TileWidth, y * TileHeight, TileWidth, TileHeight)); } } + + for (int i = 0; i < Enemies.Count; i++) + { + if (Enemies[i].Texture != null) + ParentScene.Main.SpriteBatch.Draw(Enemies[i].Texture, + destinationRectangle: new Rectangle((int)Enemies[i].Position.X, (int)Enemies[i].Position.Y, TileWidth, TileHeight)); + } } public void Update(float deltaTime) { + for (int i = 0; i < Enemies.Count; i++) + Enemies[i].Update(deltaTime); + + CheckIfRoundCompleted(); + } + private void CheckIfRoundCompleted() + { + if(Enemies.Count == 0 && WaveManager.DoneSpawning && WaveManager.RoundActive) + { + WaveManager.RoundActive = false; + } + } + + public void SpawnEnemy(Type childObject, Vector2 position, Vector2 targetPosition) + { + AddEnemyToList(position, targetPosition, childObject); + } + + public void SpawnEnemy(Type childObject) + { + AddEnemyToList(SpawnPoint, SpawnPointTargetPos, childObject); + } + + private void AddEnemyToList(Vector2 pos, Vector2 target, Type type) + { + if (type == typeof(RedBalloon)) + { + var b = new RedBalloon(this); + b.Position = pos; b.TargetPosition = target; + Enemies.Add(b); + } } } |
