Initial commit

This commit is contained in:
Matt Thorson
2020-05-04 20:50:38 -07:00
commit 4a44eb0f26
15 changed files with 1457 additions and 0 deletions

112
src/Physics/Actor.bf Normal file
View File

@ -0,0 +1,112 @@
using System;
namespace Strawberry
{
[Reflect]
public class Actor : Entity
{
private Vector remainder;
public this(int x, int y)
: base(x, y)
{
}
public bool GroundCheck(int distance = 1)
{
return Check<Solid>(.(0, distance));
}
public virtual bool IsRiding(Solid solid)
{
return Check(solid, .(0, 1));
}
public virtual void Squish()
{
}
public bool MoveX(float amount, Action onCollide = null)
{
remainder.X += amount;
let move = (int)Math.Round(remainder.X);
if (move != 0)
{
remainder.X -= move;
return MoveExactX(move, onCollide);
}
else
return false;
}
public bool MoveY(float amount, Action onCollide = null)
{
remainder.Y += amount;
let move = (int)Math.Round(remainder.Y);
if (move != 0)
{
remainder.Y -= move;
return MoveExactY(move, onCollide);
}
else
return false;
}
public bool MoveExactX(int amount, Action onCollide = null)
{
int move = amount;
int sign = Math.Sign(amount);
while (move != 0)
{
if (Check<Solid>(.(sign, 0)))
{
ZeroRemainderX();
onCollide?.Invoke();
return true;
}
X += sign;
move -= sign;
}
return false;
}
public bool MoveExactY(int amount, Action onCollide = null)
{
int move = amount;
int sign = Math.Sign(amount);
while (move != 0)
{
if (Check<Solid>(.(0, sign)))
{
ZeroRemainderY();
onCollide?.Invoke();
return true;
}
Y += sign;
move -= sign;
}
return false;
}
public void ZeroRemainderX()
{
remainder.X = 0;
}
public void ZeroRemainderY()
{
remainder.Y = 0;
}
public void ZeroRemainder()
{
remainder = Vector.Zero;
}
}
}

57
src/Physics/Platform.bf Normal file
View File

@ -0,0 +1,57 @@
using System;
using System.Collections;
namespace Strawberry
{
public abstract class Platform : Entity
{
private Vector remainder;
public this(int x, int y)
: base(x, y)
{
}
public void MoveX(float amount, Action onCollide = null)
{
remainder.X += amount;
let move = (int)Math.Round(remainder.X);
if (move != 0)
{
remainder.X -= move;
MoveExactX(move, onCollide);
}
}
public void MoveY(float amount, Action onCollide = null)
{
remainder.Y += amount;
let move = (int)Math.Round(remainder.Y);
if (move != 0)
{
remainder.Y -= move;
MoveExactY(move, onCollide);
}
}
public abstract void MoveExactX(int amount, Action onCollide = null);
public abstract void MoveExactY(int amount, Action onCollide = null);
public abstract List<Actor> GetRiders(List<Actor> into);
public void ZeroRemainderX()
{
remainder.X = 0;
}
public void ZeroRemainderY()
{
remainder.Y = 0;
}
public void ZeroRemainder()
{
remainder = Vector.Zero;
}
}
}

42
src/Physics/Solid.bf Normal file
View File

@ -0,0 +1,42 @@
using System.Collections;
namespace Strawberry
{
public class Solid : Platform
{
public this(int x, int y, Rect hitbox)
: base(x, y)
{
Hitbox = hitbox;
}
public override void Draw()
{
DrawHitbox(.(255, 255, 255, 255));
}
public override List<Actor> GetRiders(List<Actor> into)
{
for (var a in Scene.All<Actor>(scope List<Actor>))
if (a.IsRiding(this))
into.Add(a);
return into;
}
public override void MoveExactX(int amount, System.Action onCollide = null)
{
if (amount != 0)
{
}
}
public override void MoveExactY(int amount, System.Action onCollide = null)
{
if (amount != 0)
{
}
}
}
}