diff options
Diffstat (limited to 'Penguloon/Levels/LevelBase.cs')
| -rw-r--r-- | Penguloon/Levels/LevelBase.cs | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/Penguloon/Levels/LevelBase.cs b/Penguloon/Levels/LevelBase.cs index 5698cfa..7fc1f76 100644 --- a/Penguloon/Levels/LevelBase.cs +++ b/Penguloon/Levels/LevelBase.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input.Touch; using Penguloon.Scenes; @@ -6,7 +7,7 @@ namespace Penguloon.Levels { public abstract class LevelBase { - public SceneBase ParentScene { get; set; } + public GameScene ParentScene { get; set; } public Texture2D SplashArt { get; set; } @@ -29,7 +30,7 @@ namespace Penguloon.Levels public abstract void CreateMap(); - public virtual void Initialize(SceneBase sceneBase) + public virtual void Initialize(GameScene sceneBase) { this.ParentScene = sceneBase; CreateMap(); @@ -52,6 +53,41 @@ namespace Penguloon.Levels } 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) |
