Browse Source

add basic Enemy skeleton

main
Colin McMillen 3 years ago
parent
commit
9c289bd132
  1. 6
      Shared/ShmupScene.cs
  2. 28
      Shared/ShmupWorld.cs

6
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) {

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

Loading…
Cancel
Save