|
|
@ -17,13 +17,18 @@ namespace SemiColinGames { |
|
|
|
private const int jumpSpeed = -600; |
|
|
|
private const int gravity = 2400; |
|
|
|
|
|
|
|
// Details of the sprite image.
|
|
|
|
private const int spriteSize = 48; |
|
|
|
// TODO: rename to spriteHalfWidth / spriteHalfHeight.
|
|
|
|
private const int spriteWidth = 7; |
|
|
|
private const int spriteHeight = 13; |
|
|
|
private const int spriteCenterYOffset = 5; |
|
|
|
private readonly Texture2D texture; |
|
|
|
|
|
|
|
private Point position = new Point(64, 16 * 10); |
|
|
|
// Details of the actual Player model.
|
|
|
|
|
|
|
|
// Position is tracked at the Player's center. The Player's bounding box is a rectangle
|
|
|
|
// centered at that point and extending out by halfSize.X and halfSize.Y.
|
|
|
|
private Point position = new Point(64, 16 * 13); |
|
|
|
private Vector2 halfSize = new Vector2(7, 14); |
|
|
|
|
|
|
|
private int jumps = 0; |
|
|
|
private Facing facing = Facing.Right; |
|
|
|
private Pose pose = Pose.Jumping; |
|
|
@ -39,8 +44,7 @@ namespace SemiColinGames { |
|
|
|
|
|
|
|
public void Update(float modelTime, History<Input> input, Aabb[] collisionTargets) { |
|
|
|
Aabb BoxOffset(Point position, int yOffset) { |
|
|
|
return new Aabb(new Vector2(position.X, position.Y - 7 + spriteHeight + yOffset), |
|
|
|
new Vector2(spriteWidth, spriteHeight)); |
|
|
|
return new Aabb(new Vector2(position.X, position.Y + yOffset), halfSize); |
|
|
|
} |
|
|
|
|
|
|
|
Aabb Box(Point position) { |
|
|
@ -54,8 +58,8 @@ namespace SemiColinGames { |
|
|
|
// TODO: This is strictly larger than it needs to be. We could expand only in the actual
|
|
|
|
// direction of movement.
|
|
|
|
Aabb largeBox = new Aabb( |
|
|
|
new Vector2(position.X, position.Y - 7 + spriteHeight), // current player position
|
|
|
|
new Vector2(spriteWidth + Math.Abs(movement.X), spriteHeight + Math.Abs(movement.Y))); |
|
|
|
new Vector2(position.X, position.Y), // current player position
|
|
|
|
new Vector2(halfSize.X + Math.Abs(movement.X), halfSize.Y + Math.Abs(movement.Y))); |
|
|
|
foreach (var box in collisionTargets) { |
|
|
|
if (box.Intersect(largeBox) != null) { |
|
|
|
Debug.AddRect(box, Color.Green); |
|
|
@ -195,7 +199,7 @@ namespace SemiColinGames { |
|
|
|
public void Draw(SpriteBatch spriteBatch, Camera camera) { |
|
|
|
int index = SpriteIndex(pose); |
|
|
|
Rectangle textureSource = new Rectangle(index * spriteSize, 0, spriteSize, spriteSize); |
|
|
|
Vector2 spriteCenter = new Vector2(spriteSize / 2, spriteSize / 2); |
|
|
|
Vector2 spriteCenter = new Vector2(spriteSize / 2, spriteSize / 2 + spriteCenterYOffset); |
|
|
|
SpriteEffects effect = facing == Facing.Right ? |
|
|
|
SpriteEffects.FlipHorizontally : SpriteEffects.None; |
|
|
|
Vector2 drawPos = new Vector2(position.X - camera.Left, position.Y); |
|
|
|