diff --git a/src/Entity.bf b/src/Entity.bf index df8efef..fce064e 100644 --- a/src/Entity.bf +++ b/src/Entity.bf @@ -12,9 +12,9 @@ namespace Strawberry public bool Collidable = true; public bool DeleteOnRemove = true; - public this(int x, int y) + public this(Point position) { - Positionf = .(x, y); + Positionf = position; } public void Added(Scene scene) @@ -42,6 +42,7 @@ namespace Strawberry } + [Inline] public void RemoveSelf() { Scene?.Remove(this); diff --git a/src/Input/VirtualAxis.bf b/src/Input/VirtualAxis.bf index 8aec2e8..f305ce5 100644 --- a/src/Input/VirtualAxis.bf +++ b/src/Input/VirtualAxis.bf @@ -8,7 +8,7 @@ namespace Strawberry public enum OverlapBehaviors { TakeNewer, TakeOlder, CancelOut } public float Value { get; private set; } - public int IntValue { get; private set; } + public int Valuei { get; private set; } public bool Pressed { get; private set; } public bool Released { get; private set; } public bool Repeating { get; private set; } @@ -42,7 +42,7 @@ namespace Strawberry n.Update(); //Value - let last = IntValue; + let last = Valuei; Value = 0; for (var n in nodes) { @@ -52,15 +52,15 @@ namespace Strawberry break; } } - IntValue = Math.Sign(Value); + Valuei = Math.Sign(Value); //Press - if (last != IntValue && IntValue != 0) + if (last != Valuei && Valuei != 0) lastPress = Time.Elapsed; - Pressed = IntValue != 0 && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer; + Pressed = Valuei != 0 && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer; //Repeat - if (IntValue != 0 && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart) + if (Valuei != 0 && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart) { Repeating = true; @@ -73,9 +73,9 @@ namespace Strawberry Repeating = false; //Release - if (last != 0 && IntValue == 0) + if (last != 0 && Valuei == 0) lastRelease = Time.Elapsed; - Released = IntValue == 0 && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer; + Released = Valuei == 0 && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer; } public void ClearPressBuffer() diff --git a/src/Physics/Actor.bf b/src/Physics/Actor.bf index dc724ad..c548776 100644 --- a/src/Physics/Actor.bf +++ b/src/Physics/Actor.bf @@ -7,15 +7,15 @@ namespace Strawberry { private Vector remainder; - public this(int x, int y) - : base(x, y) + public this(Point position) + : base(position) { } public bool GroundCheck(int distance = 1) { - return Check(.(0, distance)); + return Check(.(0, distance)) || CheckOutside(.(0, distance)); } public virtual bool IsRiding(Solid solid) @@ -23,9 +23,14 @@ namespace Strawberry return Check(solid, .(0, 1)); } + public virtual bool IsRiding(JumpThru jumpThru) + { + return CheckOutside(jumpThru, .(0, 1)); + } + public virtual void Squish() { - Scene.Remove(this); + RemoveSelf(); } public bool MoveX(float amount, Action onCollide = null) @@ -90,7 +95,10 @@ namespace Strawberry int sign = Math.Sign(amount); while (move != 0) { - let hit = First(.(0, sign)); + Geometry hit = First(.(0, sign)); + if (hit == null && sign == 1) + hit = FirstOutside(.(0, sign)); + if (hit != null) { ZeroRemainderY(); diff --git a/src/Physics/Geometry.bf b/src/Physics/Geometry.bf index 64bd0a0..9de8813 100644 --- a/src/Physics/Geometry.bf +++ b/src/Physics/Geometry.bf @@ -7,8 +7,8 @@ namespace Strawberry { private Vector remainder; - public this(int x, int y) - : base(x, y) + public this(Point position) + : base(position) { } diff --git a/src/Physics/JumpThru.bf b/src/Physics/JumpThru.bf new file mode 100644 index 0000000..acf7db0 --- /dev/null +++ b/src/Physics/JumpThru.bf @@ -0,0 +1,39 @@ +using System.Collections; +namespace Strawberry +{ + public class JumpThru : Geometry + { + public this(Point position, int width) + : base(position) + { + Hitbox = Rect(0, 0, width, 6); + } + + public override void MoveExactX(int amount) + { + let riders = GetRiders(scope List); + + X += amount; + for (var r in riders) + r.MoveExactX(amount); + } + + public override void MoveExactY(int amount) + { + let riders = GetRiders(scope List); + } + + public override List GetRiders(List into) + { + for (var a in Scene.All(scope List)) + if (a.IsRiding(this)) + into.Add(a); + return into; + } + + public override void Draw() + { + DrawHitbox(.(255, 255, 255, 255)); + } + } +} diff --git a/src/Physics/Solid.bf b/src/Physics/Solid.bf index a67c0b3..c76198e 100644 --- a/src/Physics/Solid.bf +++ b/src/Physics/Solid.bf @@ -4,17 +4,12 @@ namespace Strawberry { public class Solid : Geometry { - public this(int x, int y, Rect hitbox) - : base(x, y) + public this(Point position, Rect hitbox) + : base(position) { Hitbox = hitbox; } - public override void Draw() - { - DrawHitbox(.(255, 255, 255, 255)); - } - public override List GetRiders(List into) { for (var a in Scene.All(scope List)) @@ -38,5 +33,10 @@ namespace Strawberry } } + + public override void Draw() + { + DrawHitbox(.(255, 255, 255, 255)); + } } } diff --git a/src/Static/Calc.bf b/src/Static/Calc.bf new file mode 100644 index 0000000..106fb48 --- /dev/null +++ b/src/Static/Calc.bf @@ -0,0 +1,13 @@ +using System; + +namespace Strawberry +{ + static public class Calc + { + [Inline] + static public float Approach(float value, float target, float maxDelta) + { + return value > target ? Math.Max(value - maxDelta, target) : Math.Min(value + maxDelta, target); + } + } +} diff --git a/src/Draw.bf b/src/Static/Draw.bf similarity index 100% rename from src/Draw.bf rename to src/Static/Draw.bf diff --git a/src/Time.bf b/src/Static/Time.bf similarity index 100% rename from src/Time.bf rename to src/Static/Time.bf