Browse Source

enemy now moves

main
Colin McMillen 9 months ago
parent
commit
123ea724d0
  1. 23
      Shared/ShmupWorld.cs

23
Shared/ShmupWorld.cs

@ -82,14 +82,34 @@ namespace SemiColinGames {
}
}
public interface IMoveBehavior {
public Vector2 Velocity(float modelTime);
}
public class MoveLeft : IMoveBehavior {
public Vector2 Velocity(float modelTime) {
return new Vector2(-100, 0);
}
}
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 Rectangle Bounds;
private IMoveBehavior moveBehavior = new MoveLeft();
public void Update(float modelTime) {
Vector2 velocity = moveBehavior.Velocity(modelTime);
Position = Vector2.Add(Position, Vector2.Multiply(velocity, modelTime));
Bounds = new Rectangle(
(int) (Position.X - HalfSize.X),
(int) (Position.Y - HalfSize.Y),
(int) HalfSize.X * 2,
(int) HalfSize.Y * 2);
}
public void Draw(SpriteBatch spriteBatch) {
@ -142,8 +162,9 @@ namespace SemiColinGames {
Rectangle paddedBounds = Bounds;
paddedBounds.Inflate(16, 16);
Shots.RemoveAll(shot => !paddedBounds.Intersects(shot.Bounds));
Enemies.RemoveAll(enemy => !paddedBounds.Intersects(enemy.Bounds));
Debug.AddToast("shots: " + Shots.Count);
Debug.AddToast("shots: " + Shots.Count + " enemies: " + Enemies.Count);
}
}
}
Loading…
Cancel
Save