add basic Enemy skeleton

This commit is contained in:
Colin McMillen 2020-11-30 17:12:09 -05:00
parent d8f3d940ef
commit 9c289bd132
2 changed files with 32 additions and 2 deletions

View File

@ -45,7 +45,11 @@ namespace SemiColinGames {
SamplerState.PointClamp, DepthStencilState.Default, SamplerState.PointClamp, DepthStencilState.Default,
RasterizerState.CullNone); 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); world.Player.Draw(spriteBatch);
foreach (ShmupWorld.Shot s in world.Shots) { foreach (ShmupWorld.Shot s in world.Shots) {

View File

@ -53,6 +53,7 @@ namespace SemiColinGames {
public Vector2 HalfSize = new Vector2(11, 4); public Vector2 HalfSize = new Vector2(11, 4);
public Rectangle Bounds; public Rectangle Bounds;
public Vector2 Velocity; public Vector2 Velocity;
public Shot(Vector2 position, Vector2 velocity) { public Shot(Vector2 position, Vector2 velocity) {
Texture = (color % 5) switch { Texture = (color % 5) switch {
0 => Textures.Projectile1, 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 Rectangle Bounds;
public readonly ShmupPlayer Player; public readonly ShmupPlayer Player;
public readonly ProfilingList<Enemy> Enemies;
public readonly ProfilingList<Shot> Shots; public readonly ProfilingList<Shot> Shots;
public ShmupWorld() { public ShmupWorld() {
Bounds = new Rectangle(0, 0, 1920 / 4, 1080 / 4); Bounds = new Rectangle(0, 0, 1920 / 4, 1080 / 4);
Player = new ShmupPlayer(); Player = new ShmupPlayer();
Enemies = new ProfilingList<Enemy>(100, "enemies");
Enemies.Add(new Enemy());
Shots = new ProfilingList<Shot>(100, "shots"); Shots = new ProfilingList<Shot>(100, "shots");
} }
@ -103,8 +126,11 @@ namespace SemiColinGames {
} }
public void Update(float modelTime, History<Input> input) { public void Update(float modelTime, History<Input> input) {
// Update player & shots. // Update player, enemies, & shots.
ProfilingList<Shot> newPlayerShots = Player.Update(modelTime, input, Bounds); ProfilingList<Shot> newPlayerShots = Player.Update(modelTime, input, Bounds);
foreach (Enemy enemy in Enemies) {
enemy.Update(modelTime);
}
foreach (Shot shot in Shots) { foreach (Shot shot in Shots) {
shot.Update(modelTime); shot.Update(modelTime);
} }