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

@ -1,4 +1,5 @@
using System.Collections;
using System.Collections;
namespace Strawberry.Sample
{
@ -6,9 +7,54 @@ namespace Strawberry.Sample
{
public Hitbox Hitbox { get; private set; }
private Vector remainder;
public Vector ExactPosition => Entity.Position + remainder;
public this(Hitbox hitbox)
{
Hitbox = hitbox;
}
public void FindRiders(List<Actor> into)
{
for (let a in Scene.All<Actor>(scope .()))
if (a.IsRiding(this))
into.Add(a);
}
public void Move(Vector amount)
{
remainder += amount;
Point move = remainder.Round();
MoveExact(move);
}
public void MoveTo(Vector pos)
{
Move(pos - ExactPosition);
}
public void MoveExact(Point amount)
{
if (amount != .Zero)
{
if (Hitbox.Collidable)
{
List<Actor> riders = FindRiders(..scope .());
Hitbox.Collidable = false;
for (let r in riders)
{
r.MoveExactX(amount.X);
r.MoveExactY(amount.Y);
}
Hitbox.Collidable = true;
}
Entity.Position += amount;
}
}
}
}

View File

@ -6,9 +6,15 @@ namespace Strawberry.Sample
{
public Hitbox Hitbox { get; private set; }
private Vector remainder;
public Vector ExactPosition => Entity.Position + remainder;
public this(Hitbox hitbox)
{
Hitbox = hitbox;
}
}
}