Skip to content

Commit

Permalink
Add placeholder player animation
Browse files Browse the repository at this point in the history
  • Loading branch information
swoolcock committed Jun 5, 2020
1 parent 87d688f commit ebaecfa
Show file tree
Hide file tree
Showing 61 changed files with 117 additions and 27 deletions.
4 changes: 1 addition & 3 deletions osu.Game.Rulesets.Rush/Beatmaps/RushBeatmapConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ protected override IEnumerable<RushHitObject> ConvertHitObject(HitObject origina
const float ground_position_cutoff = 220f;
const double etna_cutoff = 200d;
const double repeat_cutoff = 100d;
const double sawblade_cutoff = 0.9f;
const double airsawblade_cutoff = 0.95f;

var sampleLane = original.Samples.Any(s => s.Name == HitSampleInfo.HIT_CLAP || s.Name == HitSampleInfo.HIT_WHISTLE) ? LanedHitLane.Air : LanedHitLane.Ground;
LanedHitLane? positionLane = null, sawbladeLane = null;
LanedHitLane? positionLane = null;
HitObjectType hitObjectType = HitObjectType.Minion;
bool bothLanes = false;

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
140 changes: 116 additions & 24 deletions osu.Game.Rulesets.Rush/UI/RushPlayerSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Textures;
using osu.Framework.Utils;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Rush.Objects;
using osu.Game.Rulesets.Rush.Objects.Drawables;
using osuTK;

namespace osu.Game.Rulesets.Rush.UI
{
Expand All @@ -25,8 +24,11 @@ public class RushPlayerSprite : CompositeDrawable
private const float fall_delay = 300f;
private const float fall_duration = 150f;
private const float travel_duration = 150f;
private const float run_reset_delay = 200f;

private readonly TextureAnimation runningAnimation;
private readonly Dictionary<PlayerAnimation, TextureAnimation> textureAnimations = new Dictionary<PlayerAnimation, TextureAnimation>();

private double runResetTime;

private PlayerTargetLane target;

Expand All @@ -35,6 +37,9 @@ public PlayerTargetLane Target
get => target;
set
{
if (value == PlayerTargetLane.MiniBoss)
playAnimation(PlayerAnimation.AirAttack);

if (value == target)
return;

Expand All @@ -47,29 +52,44 @@ public PlayerTargetLane Target
break;

case PlayerTargetLane.HoldAir:
easeToAir();
playAnimation(PlayerAnimation.Hold);
break;

case PlayerTargetLane.AttackAir:
easeToAir();
playAnimation(PlayerAnimation.AirAttack);
break;

case PlayerTargetLane.HoldGround:
easeToGround();
playAnimation(PlayerAnimation.Hold);
break;

case PlayerTargetLane.AttackGround:
easeToGround();
playAnimation(PlayerAnimation.GroundAttack);
break;

case PlayerTargetLane.HoldBoth:
easeToCentre();
playAnimation(PlayerAnimation.Hold);
break;

case PlayerTargetLane.AttackBoth:
case PlayerTargetLane.MiniBoss:
easeToCentre();
playAnimation(PlayerAnimation.AirAttack);
break;

case PlayerTargetLane.GhostAir:
easeToGround();
// TODO: show ghost player
// showGhost(LanedHitLane.Air);
break;

case PlayerTargetLane.GhostGround:
easeToAir();
// TODO: show ghost player
// showGhost(LanedHitLane.Ground);
break;
}

Expand All @@ -85,28 +105,33 @@ public RushPlayerSprite(float groundY, float airY)
this.groundY = groundY;
this.airY = airY;

InternalChildren = new Drawable[]
AddRangeInternal(Enum.GetValues(typeof(PlayerAnimation)).Cast<PlayerAnimation>().Select(createTextureAnimation));
}

private TextureAnimation createTextureAnimation(PlayerAnimation animation) =>
textureAnimations[animation] = new TextureAnimation
{
new Circle
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(100f)
}
// runningAnimation = new TextureAnimation
// {
// Origin = Anchor.Centre,
// Anchor = Anchor.Centre,
// DefaultFrameLength = 50,
// Scale = new Vector2(1)
// },
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
DefaultFrameLength = 1000f / 16f,
Loop = false,
Alpha = 0,
};
}

[BackgroundDependencyLoader]
private void load(TextureStore store)
{
// runningAnimation.AddFrames(Enumerable.Range(1, 8).Select(i => store.Get($"Player/run_{i}")));
textureAnimations[PlayerAnimation.Run].AddFrames(Enumerable.Range(0, 10).Select(i => store.Get($"Player/Run__{i:D3}")));
textureAnimations[PlayerAnimation.Jump].AddFrames(Enumerable.Range(0, 10).Select(i => store.Get($"Player/Jump__{i:D3}")));
textureAnimations[PlayerAnimation.GroundAttack].AddFrames(Enumerable.Range(0, 10).Select(i => store.Get($"Player/Attack__{i:D3}")));
textureAnimations[PlayerAnimation.AirAttack].AddFrames(Enumerable.Range(0, 10).Select(i => store.Get($"Player/Jump_Attack__{i:D3}")));
textureAnimations[PlayerAnimation.Hold].AddFrames(Enumerable.Range(0, 10).Select(i => store.Get($"Player/Slide__{i:D3}")));
textureAnimations[PlayerAnimation.Hurt].AddFrame(store.Get("Player/Dead__000"));

textureAnimations[PlayerAnimation.Run].Loop = true;
textureAnimations[PlayerAnimation.Hold].Loop = true;

playAnimation(PlayerAnimation.Run);
}

public void StopAll() => InternalChildren.OfType<TextureAnimation>().ForEach(a =>
Expand All @@ -115,6 +140,52 @@ public void StopAll() => InternalChildren.OfType<TextureAnimation>().ForEach(a =
a.Hide();
});

// private void playRunning()
// {
// StopAll();
// textureAnimations[PlayerAnimation.Run].Show();
// textureAnimations[PlayerAnimation.Run].Restart();
// }
//
// private void playJumping()
// {
// StopAll();
//
// runResetTime = Time.Current + run_reset_delay;
//
// textureAnimations[PlayerAnimation.Jump].Show();
// textureAnimations[PlayerAnimation.Jump].Restart();
// }
//
// private void playHold()
// {
// StopAll();
// textureAnimations[PlayerAnimation.Hold].Show();
// textureAnimations[PlayerAnimation.Hold].Restart();
// }
//
// private void playAttack(LanedHitLane lane)
// {
// StopAll();
//
// runResetTime = Time.Current + run_reset_delay;
//
// var animation = lane == LanedHitLane.Air ? PlayerAnimation.AirAttack : PlayerAnimation.GroundAttack;
// textureAnimations[animation].Show();
// textureAnimations[animation].Restart();
// }

private void playAnimation(PlayerAnimation animation, bool delayNextRunAnimation = true)
{
StopAll();

if (delayNextRunAnimation && animation != PlayerAnimation.Run)
runResetTime = Time.Current + run_reset_delay;

textureAnimations[animation].Show();
textureAnimations[animation].Restart();
}

/// <summary>
/// Handles any leftover actions that were not consumed by hitobjects.
/// Allows the player to jump over sawblades or punch the ground.
Expand All @@ -137,15 +208,18 @@ public bool HandleAction(RushAction action)
private void jump()
{
ClearTransforms();
playAnimation(PlayerAnimation.Jump);
this.MoveToY(airY, jump_duration, Easing.Out)
.Then().Delay(fall_delay)
.Then().MoveToY(groundY, fall_duration, Easing.In);
.OnComplete(_ => fall());
}

private void fall(bool immediately = false)
{
using (BeginDelayedSequence(immediately ? 0 : fall_delay))
this.MoveToY(groundY, fall_duration, Easing.In);
{
this.MoveToY(groundY, fall_duration, Easing.In)
.OnComplete(_ => playAnimation(PlayerAnimation.Run));
}
}

private void easeTo(float y)
Expand Down Expand Up @@ -226,6 +300,14 @@ public bool CollidesWith(HitObject hitObject)

return false;
}

protected override void Update()
{
base.Update();

if (Target == PlayerTargetLane.None && !textureAnimations[PlayerAnimation.Run].IsPlaying && runResetTime <= Time.Current && Precision.AlmostEquals(Y, groundY))
playAnimation(PlayerAnimation.Run);
}
}

[Flags]
Expand All @@ -247,6 +329,16 @@ public enum PlayerTargetLane
MiniBoss = 1 << 4,
}

public enum PlayerAnimation
{
Run,
Jump,
GroundAttack,
AirAttack,
Hold,
Hurt
}

public static class PlayerTargetLaneExtensions
{
public static PlayerTargetLane WithHoldLane(this PlayerTargetLane current, LanedHitLane lane, bool held)
Expand Down

0 comments on commit ebaecfa

Please sign in to comment.