From ff30178f505c69bc70b0770a3220ebd6d4706c74 Mon Sep 17 00:00:00 2001 From: aldrikboy Date: Thu, 14 Dec 2017 16:39:16 +0100 Subject: dab --- Penguloon/Content/Content.mgcb | 43 ++++++++++----- Penguloon/Content/Fonts/GWENT/12.spritefont | 60 +++++++++++++++++++++ Penguloon/Content/UI/border-horizontal.png | Bin 0 -> 997 bytes Penguloon/Content/UI/border.png | Bin 973 -> 985 bytes Penguloon/ContentPathManager.cs | 2 + Penguloon/Enemies/EnemyBase.cs | 6 +++ Penguloon/Enemies/RedBalloon.cs | 2 +- Penguloon/Levels/IceLevel.cs | 9 +++- Penguloon/Levels/LevelBase.cs | 2 + Penguloon/Levels/Map.cs | 23 ++++++-- Penguloon/Levels/WaveManager.cs | 2 +- Penguloon/Objects/ObjectBase.cs | 78 ++++++++++++++++++++++++++++ Penguloon/Objects/PenguinObject.cs | 16 ++++++ Penguloon/Penguloon.csproj | 2 + Penguloon/Scenes/GameScene.cs | 42 ++++++++++++--- Penguloon/StaticUIValues.cs | 10 +++- 16 files changed, 271 insertions(+), 26 deletions(-) create mode 100644 Penguloon/Content/Fonts/GWENT/12.spritefont create mode 100644 Penguloon/Content/UI/border-horizontal.png create mode 100644 Penguloon/Objects/ObjectBase.cs create mode 100644 Penguloon/Objects/PenguinObject.cs diff --git a/Penguloon/Content/Content.mgcb b/Penguloon/Content/Content.mgcb index bf5a08e..71c3b4f 100644 --- a/Penguloon/Content/Content.mgcb +++ b/Penguloon/Content/Content.mgcb @@ -243,18 +243,6 @@ /processorParam:TextureFormat=Color /build:UI/progressbar.png -#begin UI/red.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:UI/red.png - #begin Enemies/blue.png /importer:TextureImporter /processor:TextureProcessor @@ -406,6 +394,25 @@ /processorParam:TextureFormat=Color /build:SplashArt/1.png +#begin Fonts/GWENT/12.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:Fonts/GWENT/12.spritefont + +#begin UI/red.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:UI/red.png + #begin UI/border.png /importer:TextureImporter /processor:TextureProcessor @@ -418,3 +425,15 @@ /processorParam:TextureFormat=Color /build:UI/border.png +#begin UI/border-horizontal.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:UI/border-horizontal.png + diff --git a/Penguloon/Content/Fonts/GWENT/12.spritefont b/Penguloon/Content/Fonts/GWENT/12.spritefont new file mode 100644 index 0000000..8b3d4bb --- /dev/null +++ b/Penguloon/Content/Fonts/GWENT/12.spritefont @@ -0,0 +1,60 @@ + + + + + + + GWENT.ttf + + + 12 + + + 0 + + + true + + + + + + + + + + + + ~ + + + + diff --git a/Penguloon/Content/UI/border-horizontal.png b/Penguloon/Content/UI/border-horizontal.png new file mode 100644 index 0000000..1a36c50 Binary files /dev/null and b/Penguloon/Content/UI/border-horizontal.png differ diff --git a/Penguloon/Content/UI/border.png b/Penguloon/Content/UI/border.png index 4208fff..535c39b 100644 Binary files a/Penguloon/Content/UI/border.png and b/Penguloon/Content/UI/border.png differ diff --git a/Penguloon/ContentPathManager.cs b/Penguloon/ContentPathManager.cs index 4040e50..f3a7ff3 100644 --- a/Penguloon/ContentPathManager.cs +++ b/Penguloon/ContentPathManager.cs @@ -35,6 +35,7 @@ namespace Penguloon "UI/btnIdle", "UI/btnPressed", "UI/border", + "UI/border-horizontal", "SplashArt/1", @@ -50,6 +51,7 @@ namespace Penguloon public static List FontPaths { get; set; } = new List() { + "Fonts/GWENT/12", "Fonts/GWENT/16", "Fonts/GWENT/24", "Fonts/GWENT/36", diff --git a/Penguloon/Enemies/EnemyBase.cs b/Penguloon/Enemies/EnemyBase.cs index 2179e58..d9413b4 100644 --- a/Penguloon/Enemies/EnemyBase.cs +++ b/Penguloon/Enemies/EnemyBase.cs @@ -22,6 +22,8 @@ namespace Penguloon.Enemies public Type ChildObject { get; set; } + public Rectangle Box { get; set; } + public EnemyBase(Map map) { this.Map = map; @@ -32,6 +34,8 @@ namespace Penguloon.Enemies public void Update(float deltaTime) { + Box = new Rectangle(Position.ToPoint(), new Point(Map.TileWidth, Map.TileHeight)); + int tileX = (int)(TargetPosition.X + 2) / Map.TileWidth; int tileY = (int)(TargetPosition.Y + 2) / Map.TileHeight; @@ -63,6 +67,8 @@ namespace Penguloon.Enemies private void ReachEnd() { + Map.Level.Health--; + Map.Enemies.Remove(this); } diff --git a/Penguloon/Enemies/RedBalloon.cs b/Penguloon/Enemies/RedBalloon.cs index cfe9caf..01a3b41 100644 --- a/Penguloon/Enemies/RedBalloon.cs +++ b/Penguloon/Enemies/RedBalloon.cs @@ -7,7 +7,7 @@ namespace Penguloon.Enemies public RedBalloon(Map map) : base(map) { this.Texture = ContentManager.GetTexture("Enemies/red"); - this.Speed = 135f; + this.Speed = 15f; this.Health = 1; this.ChildObject = null; } diff --git a/Penguloon/Levels/IceLevel.cs b/Penguloon/Levels/IceLevel.cs index 47569a8..ad34c0b 100644 --- a/Penguloon/Levels/IceLevel.cs +++ b/Penguloon/Levels/IceLevel.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input.Touch; using Penguloon.Enemies; +using Penguloon.Objects; using Penguloon.Scenes; namespace Penguloon.Levels @@ -10,6 +11,9 @@ namespace Penguloon.Levels public IceLevel() : base() { this.SplashArt = ContentManager.GetTexture("SplashArt/1"); + this.Money = 350; + this.Health = 200; + this.ID = 1; } public override void DrawUnique(float deltaTime) @@ -24,7 +28,7 @@ namespace Penguloon.Levels public override void CreateMap() { - Map = new Map(ParentScene); + Map = new Map(ParentScene, this); 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); @@ -59,6 +63,9 @@ namespace Penguloon.Levels { OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO }, { OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO,OO }, }; + + Map.Objects.Add(new PenguinObject(new Vector2(0, 0), Map)); + Map.Objects.Add(new PenguinObject(new Vector2(Map.TileWidth * 2, 0), Map)); } } } \ No newline at end of file diff --git a/Penguloon/Levels/LevelBase.cs b/Penguloon/Levels/LevelBase.cs index 7e88cb7..f4c45a8 100644 --- a/Penguloon/Levels/LevelBase.cs +++ b/Penguloon/Levels/LevelBase.cs @@ -16,6 +16,8 @@ namespace Penguloon.Levels public int Money { get; set; } + public int ID { get; set; } + public LevelBase() { diff --git a/Penguloon/Levels/Map.cs b/Penguloon/Levels/Map.cs index 19fd7c0..2ffcea0 100644 --- a/Penguloon/Levels/Map.cs +++ b/Penguloon/Levels/Map.cs @@ -4,6 +4,7 @@ using Penguloon.Enemies; using Penguloon.Scenes; using System.Collections.Generic; using System; +using Penguloon.Objects; namespace Penguloon.Levels { @@ -21,6 +22,7 @@ namespace Penguloon.Levels public SceneBase ParentScene { get; set; } public List Enemies { get; set; } = new List(); + public List Objects { get; set; } = new List(); public Vector2 SpawnPoint { get; set; } public Vector2 SpawnPointTargetPos { get; set; } @@ -28,9 +30,12 @@ namespace Penguloon.Levels public WaveManager WaveManager { get; set; } - public Map(SceneBase parentScene) + public LevelBase Level { get; set; } + + public Map(SceneBase parentScene, LevelBase level) { this.ParentScene = parentScene; + this.Level = level; MapWidth = (int)(StaticUIValues.ScreenViewport.X - StaticUIValues.IngameUIWidth); MapHeight = (int)(StaticUIValues.ScreenViewport.Y); @@ -45,7 +50,7 @@ namespace Penguloon.Levels public void Draw(float deltaTime) { - for(int y = 0; y < TileMap.GetLength(0); y++) + for (int y = 0; y < TileMap.GetLength(0); y++) { for (int x = 0; x < TileMap.GetLength(1); x++) { @@ -60,14 +65,26 @@ namespace Penguloon.Levels { 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)); + destinationRectangle: Enemies[i].Box); + } + + for (int i = 0; i < Objects.Count; i++) + { + Objects[i].Draw(deltaTime); } } public void Update(float deltaTime) { for (int i = 0; i < Enemies.Count; i++) + { Enemies[i].Update(deltaTime); + } + + for (int i = 0; i < Objects.Count; i++) + { + Objects[i].Update(deltaTime); + } CheckIfRoundCompleted(); } diff --git a/Penguloon/Levels/WaveManager.cs b/Penguloon/Levels/WaveManager.cs index 1a425a1..d3d27d6 100644 --- a/Penguloon/Levels/WaveManager.cs +++ b/Penguloon/Levels/WaveManager.cs @@ -26,7 +26,7 @@ namespace Penguloon.Levels private void CreateWaves() { - Waves.Add(new Wave(new List>() { new Tuple(typeof(RedBalloon), 5) }, 500)); + Waves.Add(new Wave(new List>() { new Tuple(typeof(RedBalloon), 1) }, 500)); } public void StartSpawningEnemies() diff --git a/Penguloon/Objects/ObjectBase.cs b/Penguloon/Objects/ObjectBase.cs new file mode 100644 index 0000000..9834b39 --- /dev/null +++ b/Penguloon/Objects/ObjectBase.cs @@ -0,0 +1,78 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Penguloon.Levels; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Penguloon.Objects +{ + public abstract class ObjectBase + { + public int AttackSpeedMS { get; set; } + public DateTime LastAttack { get; set; } + + public float Range { get; set; } + + public Texture2D Texture { get; set; } + public float Rotation { get; set; } + + public Vector2 Position { get; set; } + public Vector2 Center { get; set; } + public int TileSpanX { get; set; } + public int TileSpanY { get; set; } + + public Map Map { get; set; } + + public ObjectBase(Vector2 position, Map map) + { + this.Map = map; + this.Position = position; + } + + public void Update(float deltaTime) + { + this.Center = new Vector2(Position.X + ((TileSpanX * Map.TileWidth) / 2), Position.Y + ((TileSpanY * Map.TileHeight) / 2)); + + for (int i = 0; i < Map.Enemies.Count; i++) + { + if (Contains(Map.Enemies[i].Box.Location.ToVector2())) + { + Rotation = (float)GetRotation(Map.Enemies[i].Box.Center.ToVector2()); + return; + } + } + } + + public void Draw(float deltaTime) + { + float rotation = ((Rotation)); + + Rectangle rec = new Rectangle( + (int)Position.X + ((int)(Map.TileWidth * TileSpanX)) / 2, + (int)Position.Y + ((int)(Map.TileHeight * TileSpanY)) / 2, + Map.TileWidth * TileSpanX, + Map.TileHeight * TileSpanY); + + Map.ParentScene.Main.SpriteBatch.Draw(Texture, + destinationRectangle: rec, + rotation: rotation, + origin: new Vector2(Texture.Width / 2, Texture.Height / 2)); + + Map.ParentScene.Main.SpriteBatch.DrawString(ContentManager.GetFont("Fonts/GWENT/24"), Rotation.ToString(), rec.Location.ToVector2(), Color.Red); + } + + private double GetRotation(Vector2 enemyPos) + { + double radians = Math.Atan2(enemyPos.Y - Center.Y, enemyPos.X - Center.X); + + return (radians / MathHelper.PiOver2) * MathHelper.Pi; + } + + // The concise version... + private bool Contains(Vector2 point) + { + return ((point - Center).Length() <= Range); + } + } +} \ No newline at end of file diff --git a/Penguloon/Objects/PenguinObject.cs b/Penguloon/Objects/PenguinObject.cs new file mode 100644 index 0000000..e035f70 --- /dev/null +++ b/Penguloon/Objects/PenguinObject.cs @@ -0,0 +1,16 @@ +using Microsoft.Xna.Framework; +using Penguloon.Levels; + +namespace Penguloon.Objects +{ + class PenguinObject : ObjectBase + { + public PenguinObject(Vector2 position, Map map) : base(position, map) + { + this.Texture = ContentManager.GetTexture("Objects/penguin1"); + this.TileSpanX = 1; + this.TileSpanY = 1; + this.Range = Map.TileWidth * 2; + } + } +} \ No newline at end of file diff --git a/Penguloon/Penguloon.csproj b/Penguloon/Penguloon.csproj index c06358a..f353077 100644 --- a/Penguloon/Penguloon.csproj +++ b/Penguloon/Penguloon.csproj @@ -69,6 +69,8 @@ + + diff --git a/Penguloon/Scenes/GameScene.cs b/Penguloon/Scenes/GameScene.cs index 14c2d96..ac8ea9f 100644 --- a/Penguloon/Scenes/GameScene.cs +++ b/Penguloon/Scenes/GameScene.cs @@ -18,8 +18,8 @@ namespace Penguloon.Scenes this.Level.Initialize(this); StartRoundBtn = new Button(this, - new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, StaticUIValues.ScreenViewport.Y - 120), - new Vector2(StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth), 120), "Start"); + new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUIPlayButtonHeight), + new Vector2(StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth), StaticUIValues.IngameUIPlayButtonHeight), "Start"); StartRoundBtn.OnClick += StartRoundBtn_OnClick; } @@ -44,23 +44,51 @@ namespace Penguloon.Scenes base.Draw(deltaTime); - StartRoundBtn.Draw(deltaTime); - this.Level.Draw(deltaTime); DrawUI(deltaTime); + + StartRoundBtn.Draw(deltaTime); } private void DrawUI(float deltaTime) { + //background + Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/red"), + destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth, + 0, StaticUIValues.IngameUIWidth, (int)StaticUIValues.ScreenViewport.Y)); + + //border Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border"), destinationRectangle: new Rectangle(Level.Map.MapWidth, 0, StaticUIValues.BorderWidth, (int)StaticUIValues.ScreenViewport.Y)); - DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), "Wave: " + Level.Map.WaveManager.CurrentWave.ToString(), - new Vector2(StaticUIValues.ScreenViewport.X - StaticUIValues.IngameUIWidth, 10), - new Vector2(StaticUIValues.IngameUIWidth, 200), + + //border under text + Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border-horizontal"), + destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth - 4, + StaticUIValues.IngameUITextAreaHeight, StaticUIValues.IngameUIWidth, StaticUIValues.BorderWidth)); + + //border above button + Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border-horizontal"), + destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth - 4, + (int)StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUIPlayButtonHeight - StaticUIValues.BorderWidth, + StaticUIValues.IngameUIWidth, StaticUIValues.BorderWidth)); + + DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), "Gold: " + Level.Money, + new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, 10), + new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), TextAllignment.CenterTop, Color.White, Color.Black, 2); + + DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), "Wave: " + Level.Map.WaveManager.CurrentWave.ToString(), + new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, 0), + new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), + TextAllignment.CenterMiddle, Color.White, Color.Black, 2); + + DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), "Health: " + Level.Health, + new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, 0), + new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), + TextAllignment.CenterBottom, Color.White, Color.Black, 2); } public override void Update(float deltaTime, TouchLocation[] touchLocations) diff --git a/Penguloon/StaticUIValues.cs b/Penguloon/StaticUIValues.cs index 69a845e..015ffc0 100644 --- a/Penguloon/StaticUIValues.cs +++ b/Penguloon/StaticUIValues.cs @@ -20,11 +20,16 @@ namespace Penguloon public static string MenuFont { get; set; } public static string IngameFont { get; set; } + public static string IngameFontSmall { get; set; } public static int IngameUIWidth { get; set; } public static int BorderWidth { get; set; } = 20; + public static int IngameUITextAreaHeight { get; set; } + + public static int IngameUIPlayButtonHeight { get; set; } + public static void Initialize(Main main) { ScreenViewport = main.GraphicsDevice.Viewport.Bounds.Size.ToVector2(); @@ -58,13 +63,16 @@ namespace Penguloon MenuFont = "Fonts/GWENT/48"; } - IngameFont = "Fonts/GWENT/36"; + IngameFont = "Fonts/GWENT/24"; + IngameFontSmall = "Fonts/GWENT/16"; LoadingProgressbarPosition = new Vector2((ScreenViewport.X - LoadingProgressbarSize.X) / 2, ScreenViewport.Y - LoadingProgressbarSize.Y - 200); LoadingProgressbarValuePosition = new Vector2(LoadingProgressbarPosition.X + 5, LoadingProgressbarPosition.Y + 5); IngameUIWidth = 250; SnowflakeSize = 100; + IngameUITextAreaHeight = 120; + IngameUIPlayButtonHeight = 120; } } } \ No newline at end of file -- cgit v1.2.3-70-g09d2