Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
Added game object animator
Browse files Browse the repository at this point in the history
  • Loading branch information
craftersmine committed Mar 2, 2019
1 parent 0e27e31 commit 5bd3384
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion craftersmine.EtherEngine.Core/GameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ namespace craftersmine.EtherEngine.Core
/// </summary>
public class GameObject : IRenderable
{
private int _frameCounter = 0;
private int _currentAnimationFrame = 0;

/// <summary>
/// Gets or sets <see cref="Content.Texture"/> which being rendered
/// </summary>
public Texture Texture { get; set; }
/// <summary>
/// Gets or sets <see cref="Content.Animation"/> for object
/// </summary>
public Animation Animation { get; set; }
/// <summary>
/// Gets <see cref="Core.CollisionBox"/> which being used by <see cref="CollisionUpdater"/> to check collisions
/// </summary>
public CollisionBox CollisionBox { get; private set; }
Expand Down Expand Up @@ -53,6 +60,10 @@ public class GameObject : IRenderable
/// Gets or sets true if <see cref="CollisionUpdater"/> will check collisions for this object
/// </summary>
public bool Collidable { get; set; }
/// <summary>
/// Gets or sets true if object animation enabled, else false
/// </summary>
public bool IsAnimated { get; set; }

/// <summary>
/// Calls when <see cref="GameObject"/> being created
Expand Down Expand Up @@ -100,11 +111,34 @@ internal void InternalCollide(GameObject gameObject)
/// <param name="renderer"></param>
public virtual void OnRender(GLGDI renderer)
{
renderer.DrawImage(Texture.RenderableImage,
if (IsAnimated)
{
if (Animation != null)
{
if (_frameCounter == Animation.TicksPerFrame)
{
_frameCounter = 0;
_currentAnimationFrame++;
if (_currentAnimationFrame == Animation.FramesCount)
ResetAnimation();
}
renderer.DrawImage(Animation.AnimationFrames[_currentAnimationFrame].RenderableImage,
Transform.RendererX,
Transform.RendererY,
Width,
Height);
_frameCounter++;
}
else IsAnimated = false;
}
else
{
renderer.DrawImage(Texture.RenderableImage,
Transform.RendererX,
Transform.RendererY,
Width,
Height);
}
}

/// <summary>
Expand All @@ -122,5 +156,10 @@ internal void UpdateCollsionLocation()
int colliderY = CollisionBox.CollisionBoxBounds.Y + (int)this.Y;
CollisionBox.CollisionBoxBoundsOffsetted = new System.Drawing.Rectangle(colliderX, colliderY, CollisionBox.CollisionBoxBounds.Width, CollisionBox.CollisionBoxBounds.Height);
}

public void ResetAnimation()
{
_currentAnimationFrame = 0;
}
}
}

0 comments on commit 5bd3384

Please sign in to comment.