added climbing and jumping animations

This commit is contained in:
Ell 2021-03-13 16:59:36 +01:00
parent e0c1388328
commit c2acdd9fad
3 changed files with 27 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 487 B

After

Width:  |  Height:  |  Size: 772 B

View File

@ -18,7 +18,7 @@ using RectangleF = MLEM.Misc.RectangleF;
namespace GreatSpringGameJam {
public class Player : Entity {
private static readonly UniformTextureAtlas PlayerTexture = new(MlemGame.LoadContent<Texture2D>("Textures/Player"), 4, 1);
private static readonly UniformTextureAtlas PlayerTexture = new(MlemGame.LoadContent<Texture2D>("Textures/Player"), 4, 3);
public RectangleF Bounds => new(this.Position + new Vector2(4 / 16F, 0), new Vector2(9 / 16F, 1));
@ -35,8 +35,14 @@ namespace GreatSpringGameJam {
public Player(Map map, Vector2 position) : base(map, position) {
this.animations = new SpriteAnimationGroup();
this.animations.Add(new SpriteAnimation(0.15F, PlayerTexture[1], PlayerTexture[2], PlayerTexture[3], PlayerTexture[0]), () => this.walking);
// walking animations
this.animations.Add(new SpriteAnimation(1, PlayerTexture[0]), () => !this.walking);
this.animations.Add(new SpriteAnimation(0.15F, PlayerTexture[1], PlayerTexture[2], PlayerTexture[3], PlayerTexture[0]), () => this.walking);
// jumping animation
this.animations.Add(new SpriteAnimation(1, PlayerTexture[0, 1]), () => this.jumpTime > TimeSpan.Zero || !this.onGround, 1);
// climbing animations
this.animations.Add(new SpriteAnimation(1, PlayerTexture[0, 2]), () => this.climbingVine && !this.walking, 2);
this.animations.Add(new SpriteAnimation(0.18F, PlayerTexture[1, 2], PlayerTexture[2, 2], PlayerTexture[3, 2], PlayerTexture[0, 2]), () => this.climbingVine && this.walking, 2);
this.facingRight = true;
}
@ -140,22 +146,29 @@ namespace GreatSpringGameJam {
public override void Draw(GameTime time, SpriteBatch batch) {
if (this.invisible)
return;
var pos = this.Position * this.Map.TileSize;
void DrawHeldItem() {
var tex = this.heldItem switch {
HeldItem.SnowBlower => StuffTexture[0, 0],
HeldItem.WateringCan => StuffTexture[2, 0],
_ => null
};
var origin = new Vector2(tex.Width * 0.25F, tex.Height / 2);
var rot = this.GetHeldRotation();
var flip = rot >= MathHelper.PiOver2 && rot <= MathHelper.Pi * 1.5F ? SpriteEffects.FlipVertically : SpriteEffects.None;
batch.Draw(tex, pos + this.Map.TileSize / 2, Color.White, rot, origin, 1, flip, 0);
}
if(this.climbingVine)
DrawHeldItem();
// draw self
var pos = this.Position * this.Map.TileSize;
var effects = this.facingRight ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
batch.Draw(this.animations.CurrentRegion, pos, Color.White, 0, Vector2.Zero, 1, effects, 0);
// draw held item
var tex = this.heldItem switch {
HeldItem.SnowBlower => StuffTexture[0, 0],
HeldItem.WateringCan => StuffTexture[2, 0],
_ => null
};
var origin = new Vector2(tex.Width * 0.25F, tex.Height / 2);
var rot = this.GetHeldRotation();
var flip = rot >= MathHelper.PiOver2 && rot <= MathHelper.Pi * 1.5F ? SpriteEffects.FlipVertically : SpriteEffects.None;
batch.Draw(tex, pos + this.Map.TileSize / 2, Color.White, rot, origin, 1, flip, 0);
if(!this.climbingVine)
DrawHeldItem();
}
private float GetHeldRotation() {