Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy16823 committed Jul 15, 2024
1 parent d2b505c commit 00475e2
Show file tree
Hide file tree
Showing 76 changed files with 27,958 additions and 2 deletions.
27 changes: 27 additions & 0 deletions Source/Genesis/Core/Behaviors/AnimationBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using static Genesis.Graphics.AnimationCallback;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;

namespace Genesis.Core.Behaviors
Expand Down Expand Up @@ -46,6 +47,11 @@ public class AnimationBehavior : IGameBehavior
/// </summary>
public Animation SelectedAnimation { get; set; }

/// <summary>
/// Gets or sets the callbacks for the animation
/// </summary>
public List<AnimationCallback> Callbacks { get; set; }

private bool run;
private Sprite sprite;
private long lastFrame;
Expand All @@ -57,6 +63,7 @@ public class AnimationBehavior : IGameBehavior
public AnimationBehavior()
{
this.Animations = new List<Animation>();
this.Callbacks = new List<AnimationCallback>();
}

/// <summary>
Expand All @@ -73,6 +80,7 @@ public AnimationBehavior(float cells, float rows, long frameTime, Texture animat
this.Rows = rows;
this.FrameTime = frameTime;
this.AnimationSheet = animationSheet;
this.Callbacks = new List<AnimationCallback>();
}


Expand Down Expand Up @@ -180,6 +188,14 @@ public override void OnUpdate(Game game, GameElement parent)
sprite.TexCoords.BottomLeft.X = (float)currentCell * colVal;
sprite.TexCoords.BottomLeft.Y = (float)SelectedAnimation.Row * rowVal + rowVal;

foreach (var animationCallback in this.Callbacks)
{
if (animationCallback.AnimationName.Equals(SelectedAnimation.Name) && currentCell == animationCallback.Frame)
{
animationCallback.Callback(game, parent);
}
}

currentCell++;
if (currentCell >= SelectedAnimation.Cell + SelectedAnimation.Frames)
{
Expand All @@ -189,5 +205,16 @@ public override void OnUpdate(Game game, GameElement parent)
}
}
}

/// <summary>
/// Adds an new animation callback to the animation behavior
/// </summary>
/// <param name="animation">The name from the animation</param>
/// <param name="frame">The frame when the callback gets rised</param>
/// <param name="animationEvent">The animation event</param>
public void AddCallback(String animation, int frame, AnimationEvent animationEvent)
{
this.Callbacks.Add(new AnimationCallback(animation, frame, animationEvent));
}
}
}
1 change: 1 addition & 0 deletions Source/Genesis/Genesis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<Compile Include="Graphics\Animation3D\Animator.cs" />
<Compile Include="Graphics\Animation3D\Bone.cs" />
<Compile Include="Graphics\Animation3D\ModelMesh.cs" />
<Compile Include="Graphics\AnimationCallback.cs" />
<Compile Include="Graphics\Face.cs" />
<Compile Include="Graphics\Font.cs" />
<Compile Include="Graphics\Framebuffer.cs" />
Expand Down
58 changes: 58 additions & 0 deletions Source/Genesis/Graphics/AnimationCallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Genesis.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Genesis.Graphics
{
/// <summary>
/// Represents a callback for a specific frame in an animation.
/// </summary>
public class AnimationCallback
{
/// <summary>
/// Delegate for the animation event callback.
/// </summary>
/// <param name="game">The game instance triggering the event.</param>
/// <param name="element">The game element associated with the event.</param>
public delegate void AnimationEvent(Game game, GameElement element);

/// <summary>
/// Gets or sets the name of the animation.
/// </summary>
public String AnimationName { get; set; }

/// <summary>
/// Gets or sets the frame number at which the callback is triggered.
/// </summary>
public int Frame { get; set; }

/// <summary>
/// Gets or sets the callback method to be invoked.
/// </summary>
public AnimationEvent Callback { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="AnimationCallback"/> class.
/// </summary>
public AnimationCallback()
{

}

/// <summary>
/// Initializes a new instance of the <see cref="AnimationCallback"/> class with specified animation name, frame, and callback.
/// </summary>
/// <param name="animationName">The name of the animation.</param>
/// <param name="frame">The frame number at which the callback is triggered.</param>
/// <param name="callback">The callback method to be invoked.</param>
public AnimationCallback(String animationName, int frame, AnimationEvent callback)
{
this.AnimationName = animationName;
this.Frame = frame;
this.Callback = callback;
}
}
}
53 changes: 53 additions & 0 deletions Source/Genesis/bin/Debug/Genesis.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions Source/Genesis/bin/Release/Genesis.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Source/Genesis/bin/x64/Debug/Genesis.dll
Binary file not shown.
Binary file modified Source/Genesis/bin/x64/Debug/Genesis.pdb
Binary file not shown.
53 changes: 53 additions & 0 deletions Source/Genesis/bin/x64/Debug/Genesis.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Source/Genesis/bin/x64/Release/Genesis.dll
Binary file not shown.
Binary file modified Source/Genesis/bin/x64/Release/Genesis.pdb
Binary file not shown.
Loading

0 comments on commit 00475e2

Please sign in to comment.