mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2025-06-29 19:05:26 +08:00
Initial commit
This commit is contained in:
112
src/Physics/Actor.bf
Normal file
112
src/Physics/Actor.bf
Normal 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
57
src/Physics/Platform.bf
Normal 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
42
src/Physics/Solid.bf
Normal 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user