move Draw() into Player & Shot

This commit is contained in:
Colin McMillen 2020-11-30 16:23:35 -05:00
parent b5853828bd
commit d8f3d940ef
2 changed files with 17 additions and 9 deletions

View File

@ -45,17 +45,11 @@ namespace SemiColinGames {
SamplerState.PointClamp, DepthStencilState.Default,
RasterizerState.CullNone);
// Draw player.
Texture2D playerTexture = world.Player.Texture.Get;
Vector2 spriteCenter = new Vector2(playerTexture.Width / 2, playerTexture.Height / 2);
Vector2 drawPos = Vector2.Floor(Vector2.Subtract(world.Player.Position, spriteCenter));
spriteBatch.Draw(playerTexture, drawPos, Color.White);
// Draw player, then shots.
world.Player.Draw(spriteBatch);
// Draw shots.
foreach (ShmupWorld.Shot s in world.Shots) {
Texture2D texture = s.Texture.Get;
Vector2 center = new Vector2(texture.Width / 2, texture.Height / 2);
spriteBatch.Draw(texture, Vector2.Floor(Vector2.Subtract(s.Position, center)), Color.White);
s.Draw(spriteBatch);
}
// Finish drawing sprites.

View File

@ -9,6 +9,7 @@ namespace SemiColinGames {
public TextureRef Texture = Textures.Yellow2;
// Center of player sprite.
public Vector2 Position = new Vector2(48, 1080 / 8);
// TODO: use a bounds rect instead of HalfSize.
public Vector2 HalfSize = new Vector2(16, 10);
private float speed = 150f;
@ -36,6 +37,13 @@ namespace SemiColinGames {
}
return shots;
}
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, Color.White);
}
}
public class Shot {
@ -68,6 +76,12 @@ namespace SemiColinGames {
(int) HalfSize.X * 2,
(int) HalfSize.Y * 2);
}
public void Draw(SpriteBatch spriteBatch) {
Texture2D texture = Texture.Get;
Vector2 center = new Vector2(texture.Width / 2, texture.Height / 2);
spriteBatch.Draw(texture, Vector2.Floor(Vector2.Subtract(Position, center)), Color.White);
}
}
public readonly Rectangle Bounds;