using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Penguloon.Enemies; using Penguloon.Scenes; using System.Collections.Generic; using System; namespace Penguloon.Levels { public class Map { // 18 x 12 public Tile[,] TileMap { get; set; } public int MapWidth { get; private set; } public int MapHeight { get; private set; } public int TileWidth { get; private set; } public int TileHeight { get; private set; } public SceneBase ParentScene { get; set; } public List Enemies { get; set; } = new List(); 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; MapWidth = (int)(StaticUIValues.ScreenViewport.X - StaticUIValues.IngameUIWidth); MapHeight = (int)(StaticUIValues.ScreenViewport.Y); TileWidth = MapWidth / 18; TileHeight = MapHeight / 13; MapWidth = TileWidth * 18; WaveManager = new WaveManager(this); } public void Draw(float deltaTime) { for(int y = 0; y < TileMap.GetLength(0); y++) { for (int x = 0; x < TileMap.GetLength(1); x++) { Texture2D tileTexture = ContentManager.GetTileTextureByType(TileMap[y, x].Type); ParentScene.Main.SpriteBatch.Draw(tileTexture, 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); } } } public class Tile { public int Type { get; set; } public Direction Direction { get; set; } public Tile(int type, Direction direction) { this.Type = type; this.Direction = direction; } } }