diff options
| author | aldrikboy <aldrikboy@gmail.com> | 2018-01-13 00:18:04 +0100 |
|---|---|---|
| committer | aldrikboy <aldrikboy@gmail.com> | 2018-01-13 00:18:04 +0100 |
| commit | 4ae069581351b8712fd4647e9b902da1e3c9dbe3 (patch) | |
| tree | 044e6a02a8836b725cf630feb597ef7d413cc951 /Penguloon/Levels | |
| parent | f93e133ede2a76be1aa20a33c9fcf01308cd6df8 (diff) | |
yikes
Diffstat (limited to 'Penguloon/Levels')
| -rw-r--r-- | Penguloon/Levels/LevelBase.cs | 76 | ||||
| -rw-r--r-- | Penguloon/Levels/Map.cs | 5 |
2 files changed, 77 insertions, 4 deletions
diff --git a/Penguloon/Levels/LevelBase.cs b/Penguloon/Levels/LevelBase.cs index eb34dae..31f94fa 100644 --- a/Penguloon/Levels/LevelBase.cs +++ b/Penguloon/Levels/LevelBase.cs @@ -5,6 +5,8 @@ using Microsoft.Xna.Framework.Input.Touch; using Penguloon.Scenes; using Penguloon.Controls; using System.Collections.Generic; +using Penguloon.Objects; +using Microsoft.Xna.Framework.Input; namespace Penguloon.Levels { @@ -32,6 +34,10 @@ namespace Penguloon.Levels public int MinimumLevel { get; set; } + public TouchLocation[] PrevTouchLocations { get; set; } + + public DateTime StartDate { get; set; } + public LevelBase() { @@ -41,6 +47,7 @@ namespace Penguloon.Levels public virtual void Initialize(GameScene sceneBase) { + StartDate = DateTime.Now; this.ParentScene = sceneBase; CreateMap(); @@ -52,6 +59,51 @@ namespace Penguloon.Levels Map.Draw(deltaTime); DrawUnique(deltaTime); + + DrawSelectedObject(); + + string time = (DateTime.Now - StartDate).ToString("hh':'mm':'ss"); + + ParentScene.DrawText(ContentManager.GetFont("Fonts/GWENT/36"), time, new Vector2(10, StaticUIValues.ScreenViewport.Y - ContentManager.GetFont("Fonts/GWENT/36").MeasureString("XD").Y - 10), + new Vector2(), TextAllignment.LeftTop, Color.White, Color.Black, 2); + } + + private void DrawSelectedObject() + { + if (ParentScene.ObjectSeletor.State == Controls.State.Idle || ParentScene.ObjectSeletor.SelectedObjectIndex == -1) return; + + for (int i = 0; i < PrevTouchLocations.Length; i++) + { + if (PrevTouchLocations[i].State != TouchLocationState.Moved && PrevTouchLocations[i].State != TouchLocationState.Pressed) continue; + + ObjectBase obj = ParentScene.ObjectSeletor.Objects[ParentScene.ObjectSeletor.SelectedObjectIndex].Item1; + + Point tilePos = PrevTouchLocations[i].Position.ToPoint(); + tilePos.X = (tilePos.X / Map.TileWidth) * Map.TileWidth; + tilePos.Y = (tilePos.Y / Map.TileHeight) * Map.TileHeight; + + int objWidth = Map.TileWidth * obj.TileSpanX; + int objHeight = Map.TileHeight * obj.TileSpanY; + + int rangeWidth = (int)(obj.Range * 2); + int rangeHeight = (int)(obj.Range * 2); + + Rectangle rangeCircleRec = new Rectangle(tilePos.X - ((rangeWidth - objWidth) / 2), tilePos.Y - ((rangeHeight - objHeight) / 2), rangeWidth, rangeHeight); + + if (obj.RangeCircle == null) + obj.RangeCircle = obj.CreateCircle((int)obj.Range * 2); + + if (obj.RangeCircle != null) + Map.ParentScene.Main.SpriteBatch.Draw(obj.RangeCircle, + destinationRectangle: rangeCircleRec); + + if (obj.TextureBase != null) + ParentScene.Main.SpriteBatch.Draw(obj.TextureBase, + destinationRectangle: new Rectangle(tilePos, new Point(objWidth, objHeight))); + + ParentScene.Main.SpriteBatch.Draw(obj.Texture, + destinationRectangle: new Rectangle(tilePos, new Point(objWidth, objHeight))); + } } public void Update(float deltaTime, TouchLocation[] touchLocations) @@ -67,6 +119,8 @@ namespace Penguloon.Levels CheckForObjectPlacement(touchLocations); CheckForLevelUp(); + + PrevTouchLocations = touchLocations; } int lastLevelCheck; @@ -98,7 +152,12 @@ namespace Penguloon.Levels 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; + if (Map.TileMap[tileY, tileX].Direction != Direction.None) + { + ParentScene.ObjectSeletor.State = Controls.State.Idle; + ParentScene.ObjectSeletor.SelectedObjectIndex = -1; + return; + } int posToSpawnX = tileX * Map.TileWidth; int posToSpawnY = tileY * Map.TileHeight; @@ -122,8 +181,12 @@ namespace Penguloon.Levels Vector2 posToCheck = Map.Objects[x].Position + new Vector2(px * Map.TileWidth, py * Map.TileHeight); for (int t = 0; t < spawnPosToCheck.Count; t++) - if (posToCheck == spawnPosToCheck[t]) - return; + if (posToCheck == spawnPosToCheck[t]) + { + ParentScene.ObjectSeletor.State = Controls.State.Idle; + ParentScene.ObjectSeletor.SelectedObjectIndex = -1; + return; + } } } } @@ -140,7 +203,12 @@ namespace Penguloon.Levels try { - if (Map.TileMap[ty, tx].Direction != Direction.None) return; + if (Map.TileMap[ty, tx].Direction != Direction.None) + { + ParentScene.ObjectSeletor.State = Controls.State.Idle; + ParentScene.ObjectSeletor.SelectedObjectIndex = -1; + return; + } } catch { return; } } diff --git a/Penguloon/Levels/Map.cs b/Penguloon/Levels/Map.cs index 806c8de..c4dadaf 100644 --- a/Penguloon/Levels/Map.cs +++ b/Penguloon/Levels/Map.cs @@ -264,6 +264,11 @@ namespace Penguloon.Levels var b = new MortarObject(pos, this); Objects.Add(b); } + if (type == typeof(KingPenguinObject)) + { + var b = new KingPenguinObject(pos, this); + Objects.Add(b); + } } } |
