The sample game works again!

This commit is contained in:
Maddy Thorson
2021-12-23 17:09:38 -08:00
parent d3bf09f173
commit bae5798f07
17 changed files with 264 additions and 115 deletions

View File

@ -335,19 +335,19 @@ namespace Strawberry
[Inline]
public bool Check(Hitbox other)
{
return other.Collidable && SceneHitbox.Intersects(other.SceneHitbox);
return other.Collidable && other.Entity != Entity && SceneHitbox.Intersects(other.SceneHitbox);
}
[Inline]
public bool Check(Hitbox other, Point offset)
{
return other.Collidable && (SceneHitbox + offset).Intersects(other.SceneHitbox);
return other.Collidable && other.Entity != Entity && (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);
return other.Collidable && other.Entity != Entity && !SceneHitbox.Intersects(other.SceneHitbox) && (SceneHitbox + offset).Intersects(other.SceneHitbox);
}
[Inline]

View File

@ -24,7 +24,7 @@ namespace Strawberry
delete s;
}
public override void Awake()
protected override void Awake()
{
CallEnter();
}

View File

@ -0,0 +1,19 @@
using System;
namespace Strawberry
{
public class Updater : Component, IUpdate
{
private delegate void() update ~ delete _;
public this(delegate void() update)
{
this.update = update;
}
public void Update()
{
update?.Invoke();
}
}
}

View File

@ -7,9 +7,9 @@ namespace Strawberry
public Entity Entity { get; private set; }
public bool IsAwake { get; private set; }
public virtual void Added() { }
public virtual void Awake() { }
public virtual void End() { }
protected virtual void Added() { }
protected virtual void Awake() { }
protected virtual void End() { }
[Inline]
public void Destroy()

View File

@ -35,7 +35,7 @@ namespace Strawberry
{
for (var c in components)
{
c.End();
c.[Friend]End();
c.[Friend]IsAwake = false;
Scene.[Friend]UntrackComponent(c);
}
@ -49,7 +49,7 @@ namespace Strawberry
{
if (!c.[Friend]IsAwake)
{
c.Awake();
c.[Friend]Awake();
c.[Friend]IsAwake = true;
}
}
@ -67,6 +67,11 @@ namespace Strawberry
Components
*/
public bool Has<T>() where T : Component
{
return First<T>() != null;
}
public T First<T>() where T : Component
{
for (let c in components)
@ -75,7 +80,7 @@ namespace Strawberry
return null;
}
public ICollection<T> All<T>(ICollection<T> into) where T : Component
public List<T> All<T>(List<T> into) where T : Component
{
for (let c in components)
if (c is T)
@ -119,14 +124,14 @@ namespace Strawberry
components.Add(c);
Scene.[Friend]TrackComponent(c);
c.[Friend]Entity = this;
c.Added();
c.[Friend]Added();
}
if (IsAwake)
{
for (var c in toAdd)
{
c.Awake();
c.[Friend]Awake();
c.[Friend]IsAwake = true;
}
}

View File

@ -38,9 +38,16 @@ namespace Strawberry
public virtual void Update()
{
ForEach<IEarlyUpdate>(scope (u) => u.EarlyUpdate());
ForEach<IUpdate>(scope (u) => u.Update());
ForEach<ILateUpdate>(scope (u) => u.LateUpdate());
{
delegate void(IEarlyUpdate) early = scope (u) => u.EarlyUpdate();
delegate void(IUpdate) update = scope (u) => u.Update();
delegate void(ILateUpdate) late = scope (u) => u.LateUpdate();
ForEach<IEarlyUpdate>(early);
ForEach<IUpdate>(update);
ForEach<ILateUpdate>(late);
}
UpdateLists();
}

View File

@ -11,7 +11,6 @@ namespace Strawberry
while (currentModule != null)
{
let newModule = currentModule.[Friend]Run();
delete currentModule;
currentModule = newModule;
}

View File

@ -4,14 +4,14 @@ namespace Strawberry
{
public struct Point : IHashable
{
static public readonly Point Right = .(1, 0);
static public readonly Point Left = .(-1, 0);
static public readonly Point Up = .(0, -1);
static public readonly Point Down = .(0, 1);
static public readonly Point UnitX = .(1, 0);
static public readonly Point UnitY = .(0, 1);
static public readonly Point Zero = .(0, 0);
static public readonly Point One = .(1, 1);
public const Point Right = .(1, 0);
public const Point Left = .(-1, 0);
public const Point Up = .(0, -1);
public const Point Down = .(0, 1);
public const Point UnitX = .(1, 0);
public const Point UnitY = .(0, 1);
public const Point Zero = .(0, 0);
public const Point One = .(1, 1);
public int X;
public int Y;
@ -73,7 +73,7 @@ namespace Strawberry
return .((int32)a.X, (int32)a.Y);
}
[Inline]
[Inline, Commutable]
static public bool operator==(Point a, Point b)
{
return a.X == b.X && a.Y == b.Y;