diff options
| author | aldrikboy <aldrikboy@gmail.com> | 2017-12-14 16:39:16 +0100 |
|---|---|---|
| committer | aldrikboy <aldrikboy@gmail.com> | 2017-12-14 16:39:16 +0100 |
| commit | ff30178f505c69bc70b0770a3220ebd6d4706c74 (patch) | |
| tree | f51c85aa9b7728af5e79c26abd9de47228d888fa | |
| parent | 60e8e48047e774a711fee35dfc58a7be993c3d88 (diff) | |
dab
| -rw-r--r-- | Penguloon/Content/Content.mgcb | 43 | ||||
| -rw-r--r-- | Penguloon/Content/Fonts/GWENT/12.spritefont | 60 | ||||
| -rw-r--r-- | Penguloon/Content/UI/border-horizontal.png | bin | 0 -> 997 bytes | |||
| -rw-r--r-- | Penguloon/Content/UI/border.png | bin | 973 -> 985 bytes | |||
| -rw-r--r-- | Penguloon/ContentPathManager.cs | 2 | ||||
| -rw-r--r-- | Penguloon/Enemies/EnemyBase.cs | 6 | ||||
| -rw-r--r-- | Penguloon/Enemies/RedBalloon.cs | 2 | ||||
| -rw-r--r-- | Penguloon/Levels/IceLevel.cs | 9 | ||||
| -rw-r--r-- | Penguloon/Levels/LevelBase.cs | 2 | ||||
| -rw-r--r-- | Penguloon/Levels/Map.cs | 23 | ||||
| -rw-r--r-- | Penguloon/Levels/WaveManager.cs | 2 | ||||
| -rw-r--r-- | Penguloon/Objects/ObjectBase.cs | 78 | ||||
| -rw-r--r-- | Penguloon/Objects/PenguinObject.cs | 16 | ||||
| -rw-r--r-- | Penguloon/Penguloon.csproj | 2 | ||||
| -rw-r--r-- | Penguloon/Scenes/GameScene.cs | 42 | ||||
| -rw-r--r-- | Penguloon/StaticUIValues.cs | 10 |
16 files changed, 271 insertions, 26 deletions
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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +This file contains an xml description of a font, and will be read by the XNA +Framework Content Pipeline. Follow the comments to customize the appearance +of the font in your game, and to change the characters which are available to draw +with. +--> +<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics"> + <Asset Type="Graphics:FontDescription"> + + <!-- + Modify this string to change the font that will be imported. + --> + <FontName>GWENT.ttf</FontName> + + <!-- + Size is a float value, measured in points. Modify this value to change + the size of the font. + --> + <Size>12</Size> + + <!-- + Spacing is a float value, measured in pixels. Modify this value to change + the amount of spacing in between characters. + --> + <Spacing>0</Spacing> + + <!-- + UseKerning controls the layout of the font. If this value is true, kerning information + will be used when placing characters. + --> + <UseKerning>true</UseKerning> + + <!-- + Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic", + and "Bold, Italic", and are case sensitive. + --> + <Style>Regular</Style> + + <!-- + If you uncomment this line, the default character will be substituted if you draw + or measure text that contains characters which were not included in the font. + --> + <!-- <DefaultCharacter>*</DefaultCharacter> --> + + <!-- + CharacterRegions control what letters are available in the font. Every + character from Start to End will be built and made available for drawing. The + default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin + character set. The characters are ordered according to the Unicode standard. + See the documentation for more information. + --> + <CharacterRegions> + <CharacterRegion> + <Start> </Start> + <End>~</End> + </CharacterRegion> + </CharacterRegions> + </Asset> +</XnaContent> diff --git a/Penguloon/Content/UI/border-horizontal.png b/Penguloon/Content/UI/border-horizontal.png Binary files differnew file mode 100644 index 0000000..1a36c50 --- /dev/null +++ b/Penguloon/Content/UI/border-horizontal.png diff --git a/Penguloon/Content/UI/border.png b/Penguloon/Content/UI/border.png Binary files differindex 4208fff..535c39b 100644 --- a/Penguloon/Content/UI/border.png +++ b/Penguloon/Content/UI/border.png 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<string> FontPaths { get; set; } = new List<string>() { + "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<EnemyBase> Enemies { get; set; } = new List<EnemyBase>(); + public List<ObjectBase> Objects { get; set; } = new List<ObjectBase>(); 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<Tuple<Type, int>>() { new Tuple<Type, int>(typeof(RedBalloon), 5) }, 500)); + Waves.Add(new Wave(new List<Tuple<Type, int>>() { new Tuple<Type, int>(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 @@ <Compile Include="Enemies\EnemyBase.cs" /> <Compile Include="Enemies\RedBalloon.cs" /> <Compile Include="Levels\WaveManager.cs" /> + <Compile Include="Objects\ObjectBase.cs" /> + <Compile Include="Objects\PenguinObject.cs" /> <Compile Include="Scenes\GameScene.cs" /> <Compile Include="Controls\LevelSelector.cs" /> <Compile Include="Enums.cs" /> 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 |
