Tracker fixes and debug methods. ComponentInterfaceAttribute removed, interface use is auto-detected. Scene actually calls update and draw methods

This commit is contained in:
Maddy Thorson
2021-02-06 23:13:02 -08:00
parent 5dde4ce375
commit 1fb4ed7c9b
9 changed files with 142 additions and 52 deletions

View File

@ -8,6 +8,16 @@ namespace Strawberry
public bool Collidable = true;
public Rect Rect;
public this(Rect rect)
{
Rect = rect;
}
public this(int x, int y, int width, int height)
{
Rect = .(x, y, width, height);
}
public void DebugDraw()
{
Game.Batcher.Rect(SceneHitbox, .Red);
@ -116,52 +126,62 @@ namespace Strawberry
Single Collisions
*/
[Inline]
public bool Check(Point point)
{
return SceneHitbox.Contains(point);
}
[Inline]
public bool Check(Rect rect)
{
return SceneHitbox.Intersects(rect);
}
[Inline]
public bool Check(Grid grid)
{
return grid != null && grid.Check(SceneHitbox);
}
[Inline]
public bool Check(Grid grid, Point offset)
{
return grid != null && grid.Check(SceneHitbox + offset);
}
[Inline]
public bool Check(Hitbox other)
{
return other.Collidable && SceneHitbox.Intersects(other.SceneHitbox);
}
[Inline]
public bool Check(Hitbox other, Point offset)
{
return other.Collidable && (SceneHitbox + offset).Intersects(other.SceneHitbox);
}
[Inline]
public bool CheckOutside(Hitbox other, Point offset)
{
return other.Collidable && !SceneHitbox.Intersects(other.SceneHitbox) && (SceneHitbox + offset).Intersects(other.SceneHitbox);
}
public bool Check<T>(T other) where T : Component, IHasHitbox
[Inline]
public bool Check(IHasHitbox other)
{
return Check(other.Hitbox);
}
public bool Check<T>(T other, Point offset) where T : Component, IHasHitbox
[Inline]
public bool Check(IHasHitbox other, Point offset)
{
return Check(other.Hitbox, offset);
}
public bool CheckOutside<T>(T other, Point offset) where T : Component, IHasHitbox
[Inline]
public bool CheckOutside(IHasHitbox other, Point offset)
{
return CheckOutside(other.Hitbox, offset);
}

View File

@ -1,6 +1,7 @@
using System;
namespace Strawberry
{
[ComponentInterface]
public interface IDebugDraw
{
public void DebugDraw();

View File

@ -1,6 +1,7 @@
using System;
namespace Strawberry
{
[ComponentInterface]
public interface IDraw
{
public void Draw();

View File

@ -1,6 +1,7 @@
using System;
namespace Strawberry
{
[ComponentInterface]
public interface IHasHitbox
{
public Hitbox Hitbox { get; }

View File

@ -1,6 +1,7 @@
using System;
namespace Strawberry
{
[ComponentInterface]
public interface ILateUpdate
{
public void LateUpdate();

View File

@ -1,6 +1,7 @@
using System;
namespace Strawberry
{
[ComponentInterface]
public interface IUpdate
{
public void Update();