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 { namespace GreatSpringGameJam {
public class Player : Entity { 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)); 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) { public Player(Map map, Vector2 position) : base(map, position) {
this.animations = new SpriteAnimationGroup(); 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(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; this.facingRight = true;
} }
@ -140,13 +146,9 @@ namespace GreatSpringGameJam {
public override void Draw(GameTime time, SpriteBatch batch) { public override void Draw(GameTime time, SpriteBatch batch) {
if (this.invisible) if (this.invisible)
return; return;
// draw self
var pos = this.Position * this.Map.TileSize; 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 void DrawHeldItem() {
var tex = this.heldItem switch { var tex = this.heldItem switch {
HeldItem.SnowBlower => StuffTexture[0, 0], HeldItem.SnowBlower => StuffTexture[0, 0],
HeldItem.WateringCan => StuffTexture[2, 0], HeldItem.WateringCan => StuffTexture[2, 0],
@ -158,6 +160,17 @@ namespace GreatSpringGameJam {
batch.Draw(tex, pos + this.Map.TileSize / 2, Color.White, rot, origin, 1, flip, 0); batch.Draw(tex, pos + this.Map.TileSize / 2, Color.White, rot, origin, 1, flip, 0);
} }
if(this.climbingVine)
DrawHeldItem();
// draw self
var effects = this.facingRight ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
batch.Draw(this.animations.CurrentRegion, pos, Color.White, 0, Vector2.Zero, 1, effects, 0);
if(!this.climbingVine)
DrawHeldItem();
}
private float GetHeldRotation() { private float GetHeldRotation() {
var myPos = GameImpl.Instance.Camera.ToCameraPos((this.Position + Vector2.One / 2) * this.Map.TileSize); var myPos = GameImpl.Instance.Camera.ToCameraPos((this.Position + Vector2.One / 2) * this.Map.TileSize);
var mousePos = MlemGame.Input.MousePosition.ToVector2(); var mousePos = MlemGame.Input.MousePosition.ToVector2();