2020-05-04 20:50:38 -07:00
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
namespace Strawberry
|
|
|
|
{
|
2020-05-05 17:43:33 -07:00
|
|
|
public class Solid : Geometry
|
2020-05-04 20:50:38 -07:00
|
|
|
{
|
2020-05-05 18:51:27 -07:00
|
|
|
public this(Point position, Rect hitbox)
|
|
|
|
: base(position)
|
2020-05-04 20:50:38 -07:00
|
|
|
{
|
|
|
|
Hitbox = hitbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override List<Actor> GetRiders(List<Actor> into)
|
|
|
|
{
|
2020-05-20 11:46:25 -07:00
|
|
|
for (var a in Scene.All<Actor>(scope List<Actor>()))
|
2020-05-04 20:50:38 -07:00
|
|
|
if (a.IsRiding(this))
|
|
|
|
into.Add(a);
|
|
|
|
return into;
|
|
|
|
}
|
|
|
|
|
2020-05-05 17:43:33 -07:00
|
|
|
public override void MoveExactX(int amount)
|
2020-05-04 20:50:38 -07:00
|
|
|
{
|
2020-05-06 16:51:09 -07:00
|
|
|
if (Collidable)
|
2020-05-04 20:50:38 -07:00
|
|
|
{
|
2020-05-20 11:46:25 -07:00
|
|
|
let riders = GetRiders(scope List<Actor>());
|
2020-05-04 20:50:38 -07:00
|
|
|
|
2020-05-06 16:51:09 -07:00
|
|
|
X += amount;
|
|
|
|
Collidable = false;
|
|
|
|
|
2020-05-20 11:46:25 -07:00
|
|
|
for (Actor a in Scene.All<Actor>(scope List<Actor>()))
|
2020-05-06 16:51:09 -07:00
|
|
|
{
|
|
|
|
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-19 22:31:32 -07:00
|
|
|
a.MoveExactX(amount, null, null, this);
|
2020-05-06 16:51:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Collidable = true;
|
2020-05-04 20:50:38 -07:00
|
|
|
}
|
2020-05-06 16:51:09 -07:00
|
|
|
else
|
|
|
|
X += amount;
|
2020-05-04 20:50:38 -07:00
|
|
|
}
|
|
|
|
|
2020-05-05 17:43:33 -07:00
|
|
|
public override void MoveExactY(int amount)
|
2020-05-04 20:50:38 -07:00
|
|
|
{
|
2020-05-06 16:51:09 -07:00
|
|
|
if (Collidable)
|
2020-05-04 20:50:38 -07:00
|
|
|
{
|
2020-05-20 11:46:25 -07:00
|
|
|
let riders = GetRiders(scope List<Actor>());
|
2020-05-06 16:51:09 -07:00
|
|
|
|
|
|
|
Y += amount;
|
|
|
|
Collidable = false;
|
|
|
|
|
2020-05-20 11:46:25 -07:00
|
|
|
for (Actor a in Scene.All<Actor>(scope List<Actor>()))
|
2020-05-06 16:51:09 -07:00
|
|
|
{
|
|
|
|
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-19 22:31:32 -07:00
|
|
|
a.MoveExactY(amount, null, null, this);
|
2020-05-06 16:51:09 -07:00
|
|
|
}
|
|
|
|
}
|
2020-05-04 20:50:38 -07:00
|
|
|
|
2020-05-06 16:51:09 -07:00
|
|
|
Collidable = true;
|
2020-05-04 20:50:38 -07:00
|
|
|
}
|
2020-05-06 16:51:09 -07:00
|
|
|
else
|
|
|
|
Y += amount;
|
2020-05-04 20:50:38 -07:00
|
|
|
}
|
2020-05-05 18:51:27 -07:00
|
|
|
|
|
|
|
public override void Draw()
|
|
|
|
{
|
|
|
|
DrawHitbox(.(255, 255, 255, 255));
|
|
|
|
}
|
2020-05-04 20:50:38 -07:00
|
|
|
}
|
|
|
|
}
|