StrawberryBF/src/Physics/Solid.bf

95 lines
1.6 KiB
Brainfuck
Raw Normal View History

2020-05-05 11:50:38 +08:00
using System.Collections;
namespace Strawberry
{
2020-05-06 08:43:33 +08:00
public class Solid : Geometry
2020-05-05 11:50:38 +08:00
{
2020-05-06 09:51:27 +08:00
public this(Point position, Rect hitbox)
: base(position)
2020-05-05 11:50:38 +08:00
{
Hitbox = hitbox;
}
public override List<Actor> GetRiders(List<Actor> into)
{
2020-05-21 02:46:25 +08:00
for (var a in Scene.All<Actor>(scope List<Actor>()))
2020-05-05 11:50:38 +08:00
if (a.IsRiding(this))
into.Add(a);
return into;
}
2020-05-06 08:43:33 +08:00
public override void MoveExactX(int amount)
2020-05-05 11:50:38 +08:00
{
if (Collidable)
2020-05-05 11:50:38 +08:00
{
2020-05-21 02:46:25 +08:00
let riders = GetRiders(scope List<Actor>());
2020-05-05 11:50:38 +08:00
X += amount;
Collidable = false;
2020-05-21 02:46:25 +08:00
for (Actor a in Scene.All<Actor>(scope List<Actor>()))
{
if (Check(a))
{
//Push
int move;
if (amount > 0)
move = Right - a.Left;
else
move = Left - a.Right;
a.MoveExactX(move, scope => a.Squish, this);
}
else if (riders.Contains(a))
{
//Carry
2020-05-20 13:31:32 +08:00
a.MoveExactX(amount, null, null, this);
}
}
Collidable = true;
2020-05-05 11:50:38 +08:00
}
else
X += amount;
2020-05-05 11:50:38 +08:00
}
2020-05-06 08:43:33 +08:00
public override void MoveExactY(int amount)
2020-05-05 11:50:38 +08:00
{
if (Collidable)
2020-05-05 11:50:38 +08:00
{
2020-05-21 02:46:25 +08:00
let riders = GetRiders(scope List<Actor>());
Y += amount;
Collidable = false;
2020-05-21 02:46:25 +08:00
for (Actor a in Scene.All<Actor>(scope List<Actor>()))
{
if (Check(a))
{
//Push
int move;
if (amount > 0)
move = Bottom - a.Top;
else
move = Top - a.Bottom;
a.MoveExactY(move, scope => a.Squish, this);
}
else if (riders.Contains(a))
{
//Carry
2020-05-20 13:31:32 +08:00
a.MoveExactY(amount, null, null, this);
}
}
2020-05-05 11:50:38 +08:00
Collidable = true;
2020-05-05 11:50:38 +08:00
}
else
Y += amount;
2020-05-05 11:50:38 +08:00
}
2020-05-06 09:51:27 +08:00
public override void Draw()
{
DrawHitbox(.(255, 255, 255, 255));
}
2020-05-05 11:50:38 +08:00
}
}