summaryrefslogtreecommitdiff
path: root/Penguloon/Levels
diff options
context:
space:
mode:
Diffstat (limited to 'Penguloon/Levels')
-rw-r--r--Penguloon/Levels/IceLevel.cs7
-rw-r--r--Penguloon/Levels/LevelBase.cs4
-rw-r--r--Penguloon/Levels/Map.cs51
-rw-r--r--Penguloon/Levels/WaveManager.cs77
4 files changed, 138 insertions, 1 deletions
diff --git a/Penguloon/Levels/IceLevel.cs b/Penguloon/Levels/IceLevel.cs
index 5f8b4c7..47569a8 100644
--- a/Penguloon/Levels/IceLevel.cs
+++ b/Penguloon/Levels/IceLevel.cs
@@ -1,4 +1,6 @@
-using Microsoft.Xna.Framework.Input.Touch;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Input.Touch;
+using Penguloon.Enemies;
using Penguloon.Scenes;
namespace Penguloon.Levels
@@ -23,6 +25,9 @@ namespace Penguloon.Levels
public override void CreateMap()
{
Map = new Map(ParentScene);
+ Map.SpawnPoint = new Vector2(1 * Map.TileWidth, -1 * Map.TileHeight);
+ Map.SpawnPointTargetPos = new Vector2(1 * Map.TileWidth, 0 * Map.TileHeight);
+ Map.FinishPoint = new Vector2(18 * Map.TileWidth, 2 * Map.TileHeight);
Tile OO = new Tile(0, Direction.None);
diff --git a/Penguloon/Levels/LevelBase.cs b/Penguloon/Levels/LevelBase.cs
index de17caf..7e88cb7 100644
--- a/Penguloon/Levels/LevelBase.cs
+++ b/Penguloon/Levels/LevelBase.cs
@@ -12,6 +12,10 @@ namespace Penguloon.Levels
public Map Map { get; set; }
+ public int Health { get; set; }
+
+ public int Money { get; set; }
+
public LevelBase()
{
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);
+ }
}
}
diff --git a/Penguloon/Levels/WaveManager.cs b/Penguloon/Levels/WaveManager.cs
new file mode 100644
index 0000000..1a425a1
--- /dev/null
+++ b/Penguloon/Levels/WaveManager.cs
@@ -0,0 +1,77 @@
+using Penguloon.Enemies;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+
+namespace Penguloon.Levels
+{
+ public class WaveManager
+ {
+ public List<Wave> Waves { get; set; } = new List<Wave>();
+
+ public Map Map { get; set; }
+
+ public int CurrentWave { get; set; } = 1;
+
+ public bool RoundActive { get; set; }
+
+ public bool DoneSpawning { get; set; } = false;
+
+ public WaveManager(Map map)
+ {
+ this.Map = map;
+
+ CreateWaves();
+ }
+
+ private void CreateWaves()
+ {
+ Waves.Add(new Wave(new List<Tuple<Type, int>>() { new Tuple<Type, int>(typeof(RedBalloon), 5) }, 500));
+ }
+
+ public void StartSpawningEnemies()
+ {
+ RoundActive = true;
+ DoneSpawning = false;
+
+ new Thread(() =>
+ {
+ Thread.CurrentThread.IsBackground = true;
+
+ int waveToSpawn = CurrentWave - 1;
+
+ if (waveToSpawn >= Waves.Count)
+ waveToSpawn = Waves.Count - 1;
+
+ for (int i = 0; i < Waves[waveToSpawn].EnemiesToSpawn.Count; i++)
+ {
+ for(int x = 0; x < Waves[waveToSpawn].EnemiesToSpawn[i].Item2; x++)
+ {
+ Map.SpawnEnemy(Waves[waveToSpawn].EnemiesToSpawn[i].Item1);
+ Thread.Sleep(Waves[waveToSpawn].SpawnDelayMS);
+ }
+ }
+
+ DoneSpawning = true;
+
+ }).Start();
+ }
+
+ internal void FinishRound()
+ {
+ CurrentWave++;
+ }
+ }
+
+ public class Wave
+ {
+ public int SpawnDelayMS { get; set; }
+ public List<Tuple<Type, int>> EnemiesToSpawn { get; set; } = new List<Tuple<Type, int>>();
+
+ public Wave(List<Tuple<Type, int>> EnemiesToSpawn, int SpawnDelayMS)
+ {
+ this.SpawnDelayMS = SpawnDelayMS;
+ this.EnemiesToSpawn = EnemiesToSpawn;
+ }
+ }
+} \ No newline at end of file