Skip to content

Commit

Permalink
Added ability to assign platformer animations based on input device
Browse files Browse the repository at this point in the history
Added ability to set platformer animation speed based on input.
  • Loading branch information
vchelaru committed Dec 23, 2023
1 parent 3f0cebd commit a51ee7c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public override ICodeBlock GenerateInitialize(ICodeBlock codeBlock, IElement ele
variableAssignmentBlock.Line($"MaxXVelocityAbsolute={CodeParser.ConvertValueToCodeString(entry.MaxXVelocityAbsolute)} ,");
variableAssignmentBlock.Line($"MinYVelocity={CodeParser.ConvertValueToCodeString(entry.MinYVelocity)} ,");
variableAssignmentBlock.Line($"MaxYVelocity={CodeParser.ConvertValueToCodeString(entry.MaxYVelocity)} ,");
variableAssignmentBlock.Line($"MinHorizontalInputAbsolute={CodeParser.ConvertValueToCodeString(entry.MinHorizontalInputAbsolute)} ,");
variableAssignmentBlock.Line($"MaxHorizontalInputAbsolute={CodeParser.ConvertValueToCodeString(entry.MaxHorizontalInputAbsolute)} ,");
variableAssignmentBlock.Line($"AbsoluteXVelocityAnimationSpeedMultiplier={CodeParser.ConvertValueToCodeString(entry.AbsoluteXVelocityAnimationSpeedMultiplier)} ,");
variableAssignmentBlock.Line($"AbsoluteYVelocityAnimationSpeedMultiplier={CodeParser.ConvertValueToCodeString(entry.AbsoluteYVelocityAnimationSpeedMultiplier)} ,");
variableAssignmentBlock.Line($"MaxSpeedXRatioMultiplier={CodeParser.ConvertValueToCodeString(entry.MaxSpeedXRatioMultiplier)} ,");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public interface IPlatformer : FlatRedBall.Math.IPositionable
string CurrentMovementName {{ get; }}
float MaxAbsoluteXVelocity {{ get; }}
float MaxAbsoluteYVelocity {{ get; }}
global::FlatRedBall.Input.I1DInput HorizontalInput {{get;}}
}}
}}";
return toReturn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public enum AnimationSpeedAssignment
ForceTo1,
NoAssignment,
BasedOnVelocityMultiplier,
BasedOnMaxSpeedRatioMultiplier
BasedOnMaxSpeedRatioMultiplier,
BasedOnHorizontalInputMultiplier
}
public class PlatformerAnimationConfiguration
Expand All @@ -75,6 +77,9 @@ public class PlatformerAnimationConfiguration
public float? AbsoluteXVelocityAnimationSpeedMultiplier { get; set; }
public float? AbsoluteYVelocityAnimationSpeedMultiplier { get; set; }
public float? MinHorizontalInputAbsolute { get; set; }
public float? MaxHorizontalInputAbsolute { get; set; }
public float? MaxSpeedXRatioMultiplier { get; set; }
public float? MaxSpeedYRatioMultiplier { get; set; }
Expand Down Expand Up @@ -139,6 +144,7 @@ public void AddLayer(PlatformerAnimationConfiguration configuration)
}
bool shouldSet = true;
var absoluteXVelocity = System.Math.Abs(PlatformerEntity.XVelocity);
var absoluteInput = System.Math.Abs(PlatformerEntity.HorizontalInput.Value);
var yVelocity = PlatformerEntity.YVelocity;
if(shouldSet && !string.IsNullOrEmpty( configuration.MovementName))
{
Expand All @@ -149,6 +155,8 @@ public void AddLayer(PlatformerAnimationConfiguration configuration)
shouldSet = shouldSet && (yVelocity < configuration.MinYVelocity) == false;
shouldSet = shouldSet && (absoluteXVelocity > configuration.MaxXVelocityAbsolute) == false;
shouldSet = shouldSet && (yVelocity > configuration.MaxYVelocity) == false;
shouldSet = shouldSet && (absoluteInput < configuration.MinHorizontalInputAbsolute) == false;
shouldSet = shouldSet && (absoluteInput > configuration.MaxHorizontalInputAbsolute) == false;
shouldSet = shouldSet &&
(configuration.OnGroundRequirement == null || PlatformerEntity.IsOnGround == configuration.OnGroundRequirement);
Expand Down Expand Up @@ -220,6 +228,15 @@ public void AddLayer(PlatformerAnimationConfiguration configuration)
}
}
break;
case AnimationSpeedAssignment.BasedOnHorizontalInputMultiplier:
{
var asSprite = this.AnimatedObject as FlatRedBall.Sprite;
if (asSprite != null)
{
asSprite.AnimationSpeed = PlatformerEntity.HorizontalInput.Value;
}
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ private static void InitializeInstanceMembers(DataUiGrid dataUiGrid, AnimationRo
dataUiGrid.MoveMemberToCategory(nameof(AnimationRowViewModel.MaxXVelocityAbsolute), Localization.Texts.Velocity);

dataUiGrid.MoveMemberToCategory(nameof(AnimationRowViewModel.MinYVelocity), Localization.Texts.Velocity);
dataUiGrid.MoveMemberToCategory(nameof(AnimationRowViewModel.MaxYVelocity),Localization.Texts.Velocity);
dataUiGrid.MoveMemberToCategory(nameof(AnimationRowViewModel.MaxYVelocity), Localization.Texts.Velocity);

dataUiGrid.MoveMemberToCategory(nameof(AnimationRowViewModel.MinHorizontalInputAbsolute), "Input");
dataUiGrid.MoveMemberToCategory(nameof(AnimationRowViewModel.MaxHorizontalInputAbsolute), "Input");

var velocityFirstGridLength = new GridLength(150);
dataUiGrid.GetInstanceMember(nameof(AnimationRowViewModel.MinXVelocityAbsolute)).FirstGridLength = velocityFirstGridLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ public enum AnimationSpeedAssignment
ForceTo1,
NoAssignment,
BasedOnVelocityMultiplier,
BasedOnMaxSpeedRatioMultiplier
BasedOnMaxSpeedRatioMultiplier,
BasedOnHorizontalInputMultiplier

}

public class AllPlatformerAnimationValues
{
public List<IndividualPlatformerAnimationValues> Values { get; set; } = new List<IndividualPlatformerAnimationValues>();
Expand All @@ -29,6 +31,9 @@ public class IndividualPlatformerAnimationValues
public float? MinYVelocity { get; set; }
public float? MaxYVelocity { get; set; }

public float? MinHorizontalInputAbsolute { get; set; }
public float? MaxHorizontalInputAbsolute { get; set; }

public float? AbsoluteXVelocityAnimationSpeedMultiplier { get; set; }
public float? AbsoluteYVelocityAnimationSpeedMultiplier { get; set; }

Expand Down
18 changes: 18 additions & 0 deletions FRBDK/Glue/PlatformerPlugin/ViewModels/AnimationRowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public float? MaxYVelocity
set => Set(value);
}

public float? MinHorizontalInputAbsolute
{
get => Get<float?>();
set => Set(value);
}
public float? MaxHorizontalInputAbsolute
{
get => Get<float?>();
set => Set(value);
}

public float? AbsoluteXVelocityAnimationSpeedMultiplier
{
get => Get<float?>();
Expand Down Expand Up @@ -148,6 +159,10 @@ public void ApplyTo(IndividualPlatformerAnimationValues model)
model.MinYVelocity = MinYVelocity;
model.MaxYVelocity = MaxYVelocity;

model.MinHorizontalInputAbsolute = MinHorizontalInputAbsolute;
model.MaxHorizontalInputAbsolute = MaxHorizontalInputAbsolute;


model.AbsoluteXVelocityAnimationSpeedMultiplier = AbsoluteXVelocityAnimationSpeedMultiplier;
model.AbsoluteYVelocityAnimationSpeedMultiplier = AbsoluteYVelocityAnimationSpeedMultiplier;

Expand Down Expand Up @@ -176,6 +191,9 @@ public void SetFrom(IndividualPlatformerAnimationValues model)
this.MinYVelocity = model.MinYVelocity;
this.MaxYVelocity = model.MaxYVelocity;

this.MinHorizontalInputAbsolute = model.MinHorizontalInputAbsolute;
this.MaxHorizontalInputAbsolute = model.MaxHorizontalInputAbsolute;

this.AbsoluteXVelocityAnimationSpeedMultiplier = model.AbsoluteXVelocityAnimationSpeedMultiplier;
this.AbsoluteYVelocityAnimationSpeedMultiplier = model.AbsoluteYVelocityAnimationSpeedMultiplier;

Expand Down

0 comments on commit a51ee7c

Please sign in to comment.