using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input.Touch; using Penguloon.Scenes; namespace Penguloon.Levels { public abstract class LevelBase { public GameScene ParentScene { get; set; } public Texture2D SplashArt { get; set; } public Map Map { get; set; } public int Health { get; set; } public int Money { get; set; } = 0; public int ID { get; set; } public int Kills { get; set; } = 0; public bool Finished { get; set; } = false; public LevelBase() { } public abstract void CreateMap(); public virtual void Initialize(GameScene sceneBase) { this.ParentScene = sceneBase; CreateMap(); } public void Draw(float deltaTime) { Map.Draw(deltaTime); DrawUnique(deltaTime); } public void Update(float deltaTime, TouchLocation[] touchLocations) { Map.Update(deltaTime); if(Health <= 0) { Finished = true; } UpdateUnique(deltaTime, touchLocations); CheckForObjectPlacement(touchLocations); } private void CheckForObjectPlacement(TouchLocation[] touchLocations) { if (ParentScene.ObjectSeletor.State == Controls.State.Idle || ParentScene.ObjectSeletor.SelectedObjectIndex == -1) return; for(int i = 0; i < touchLocations.Length; i++) { if (touchLocations[i].Position.X > Map.MapWidth) return; if (touchLocations[i].Position.Y > Map.MapHeight) return; int tileX = (int)touchLocations[i].Position.X / Map.TileWidth; int tileY = (int)touchLocations[i].Position.Y / Map.TileHeight; if (Map.TileMap[tileY, tileX].Direction != Direction.None) return; int posToSpawnX = tileX * Map.TileWidth; int posToSpawnY = tileY * Map.TileHeight; // check if there isnt an object already for (int x = 0; x < Map.Objects.Count; x++) { if (Map.Objects[x].Position == new Vector2(posToSpawnX, posToSpawnY)) return; } Money -= ParentScene.ObjectSeletor.Objects[ParentScene.ObjectSeletor.SelectedObjectIndex].Item2; Map.SpawnObject(ParentScene.ObjectSeletor.Objects[ParentScene.ObjectSeletor.SelectedObjectIndex].Item1.GetType(), new Vector2(posToSpawnX, posToSpawnY)); ParentScene.ObjectSeletor.State = Controls.State.Idle; ParentScene.ObjectSeletor.SelectedObjectIndex = -1; } } public virtual void DrawUnique(float deltaTime) { } public virtual void UpdateUnique(float deltaTime, TouchLocation[] touchLocations) { } public void FinishGame() { // upload score here or something } } }