From 9c289bd13294a9da774d4467ec61a18494effb13 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Mon, 30 Nov 2020 17:12:09 -0500 Subject: [PATCH] add basic Enemy skeleton --- Shared/ShmupScene.cs | 6 +++++- Shared/ShmupWorld.cs | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Shared/ShmupScene.cs b/Shared/ShmupScene.cs index 8c35cb2..c2c0259 100644 --- a/Shared/ShmupScene.cs +++ b/Shared/ShmupScene.cs @@ -45,7 +45,11 @@ namespace SemiColinGames { SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone); - // Draw player, then shots. + // Draw enemies, then player, then shots. + foreach (ShmupWorld.Enemy e in world.Enemies) { + e.Draw(spriteBatch); + } + world.Player.Draw(spriteBatch); foreach (ShmupWorld.Shot s in world.Shots) { diff --git a/Shared/ShmupWorld.cs b/Shared/ShmupWorld.cs index 946a681..e0b129e 100644 --- a/Shared/ShmupWorld.cs +++ b/Shared/ShmupWorld.cs @@ -53,6 +53,7 @@ namespace SemiColinGames { public Vector2 HalfSize = new Vector2(11, 4); public Rectangle Bounds; public Vector2 Velocity; + public Shot(Vector2 position, Vector2 velocity) { Texture = (color % 5) switch { 0 => Textures.Projectile1, @@ -84,13 +85,35 @@ namespace SemiColinGames { } } + public class Enemy { + public TextureRef Texture = Textures.Blue1; + // Center of sprite. + public Vector2 Position = new Vector2(1920 / 4 - 48, 1080 / 8); + // TODO: use a bounds rect instead of HalfSize. + public Vector2 HalfSize = new Vector2(16, 10); + + public void Update(float modelTime) { + } + + public void Draw(SpriteBatch spriteBatch) { + Texture2D texture = Texture.Get; + Vector2 spriteCenter = new Vector2(texture.Width / 2, texture.Height / 2); + Vector2 drawPos = Vector2.Floor(Vector2.Subtract(Position, spriteCenter)); + spriteBatch.Draw(texture, drawPos, null, Color.White, 0f, + spriteCenter, Vector2.One, SpriteEffects.FlipHorizontally, 0f); + } + } + public readonly Rectangle Bounds; public readonly ShmupPlayer Player; + public readonly ProfilingList Enemies; public readonly ProfilingList Shots; public ShmupWorld() { Bounds = new Rectangle(0, 0, 1920 / 4, 1080 / 4); Player = new ShmupPlayer(); + Enemies = new ProfilingList(100, "enemies"); + Enemies.Add(new Enemy()); Shots = new ProfilingList(100, "shots"); } @@ -103,8 +126,11 @@ namespace SemiColinGames { } public void Update(float modelTime, History input) { - // Update player & shots. + // Update player, enemies, & shots. ProfilingList newPlayerShots = Player.Update(modelTime, input, Bounds); + foreach (Enemy enemy in Enemies) { + enemy.Update(modelTime); + } foreach (Shot shot in Shots) { shot.Update(modelTime); }