Reorganizing

This commit is contained in:
Matt Thorson 2020-05-05 18:51:27 -07:00
parent 9374086e97
commit 409a82d6b8
9 changed files with 85 additions and 24 deletions

View File

@ -12,9 +12,9 @@ namespace Strawberry
public bool Collidable = true; public bool Collidable = true;
public bool DeleteOnRemove = 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) public void Added(Scene scene)
@ -42,6 +42,7 @@ namespace Strawberry
} }
[Inline]
public void RemoveSelf() public void RemoveSelf()
{ {
Scene?.Remove(this); Scene?.Remove(this);

View File

@ -8,7 +8,7 @@ namespace Strawberry
public enum OverlapBehaviors { TakeNewer, TakeOlder, CancelOut } public enum OverlapBehaviors { TakeNewer, TakeOlder, CancelOut }
public float Value { get; private set; } 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 Pressed { get; private set; }
public bool Released { get; private set; } public bool Released { get; private set; }
public bool Repeating { get; private set; } public bool Repeating { get; private set; }
@ -42,7 +42,7 @@ namespace Strawberry
n.Update(); n.Update();
//Value //Value
let last = IntValue; let last = Valuei;
Value = 0; Value = 0;
for (var n in nodes) for (var n in nodes)
{ {
@ -52,15 +52,15 @@ namespace Strawberry
break; break;
} }
} }
IntValue = Math.Sign(Value); Valuei = Math.Sign(Value);
//Press //Press
if (last != IntValue && IntValue != 0) if (last != Valuei && Valuei != 0)
lastPress = Time.Elapsed; lastPress = Time.Elapsed;
Pressed = IntValue != 0 && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer; Pressed = Valuei != 0 && lastPress > lastPressClear && Time.Elapsed - lastPress <= pressBuffer;
//Repeat //Repeat
if (IntValue != 0 && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart) if (Valuei != 0 && repeatStart > 0 && Time.Elapsed - lastPress >= repeatStart)
{ {
Repeating = true; Repeating = true;
@ -73,9 +73,9 @@ namespace Strawberry
Repeating = false; Repeating = false;
//Release //Release
if (last != 0 && IntValue == 0) if (last != 0 && Valuei == 0)
lastRelease = Time.Elapsed; lastRelease = Time.Elapsed;
Released = IntValue == 0 && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer; Released = Valuei == 0 && lastRelease > lastReleaseClear && Time.Elapsed - lastRelease <= releaseBuffer;
} }
public void ClearPressBuffer() public void ClearPressBuffer()

View File

@ -7,15 +7,15 @@ namespace Strawberry
{ {
private Vector remainder; private Vector remainder;
public this(int x, int y) public this(Point position)
: base(x, y) : base(position)
{ {
} }
public bool GroundCheck(int distance = 1) public bool GroundCheck(int distance = 1)
{ {
return Check<Solid>(.(0, distance)); return Check<Solid>(.(0, distance)) || CheckOutside<JumpThru>(.(0, distance));
} }
public virtual bool IsRiding(Solid solid) public virtual bool IsRiding(Solid solid)
@ -23,9 +23,14 @@ namespace Strawberry
return Check(solid, .(0, 1)); return Check(solid, .(0, 1));
} }
public virtual bool IsRiding(JumpThru jumpThru)
{
return CheckOutside(jumpThru, .(0, 1));
}
public virtual void Squish() public virtual void Squish()
{ {
Scene.Remove(this); RemoveSelf();
} }
public bool MoveX(float amount, Action<Collision> onCollide = null) public bool MoveX(float amount, Action<Collision> onCollide = null)
@ -90,7 +95,10 @@ namespace Strawberry
int sign = Math.Sign(amount); int sign = Math.Sign(amount);
while (move != 0) while (move != 0)
{ {
let hit = First<Solid>(.(0, sign)); Geometry hit = First<Solid>(.(0, sign));
if (hit == null && sign == 1)
hit = FirstOutside<JumpThru>(.(0, sign));
if (hit != null) if (hit != null)
{ {
ZeroRemainderY(); ZeroRemainderY();

View File

@ -7,8 +7,8 @@ namespace Strawberry
{ {
private Vector remainder; private Vector remainder;
public this(int x, int y) public this(Point position)
: base(x, y) : base(position)
{ {
} }

39
src/Physics/JumpThru.bf Normal file
View File

@ -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<Actor>);
X += amount;
for (var r in riders)
r.MoveExactX(amount);
}
public override void MoveExactY(int amount)
{
let riders = GetRiders(scope List<Actor>);
}
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 Draw()
{
DrawHitbox(.(255, 255, 255, 255));
}
}
}

View File

@ -4,17 +4,12 @@ namespace Strawberry
{ {
public class Solid : Geometry public class Solid : Geometry
{ {
public this(int x, int y, Rect hitbox) public this(Point position, Rect hitbox)
: base(x, y) : base(position)
{ {
Hitbox = hitbox; Hitbox = hitbox;
} }
public override void Draw()
{
DrawHitbox(.(255, 255, 255, 255));
}
public override List<Actor> GetRiders(List<Actor> into) public override List<Actor> GetRiders(List<Actor> into)
{ {
for (var a in Scene.All<Actor>(scope List<Actor>)) for (var a in Scene.All<Actor>(scope List<Actor>))
@ -38,5 +33,10 @@ namespace Strawberry
} }
} }
public override void Draw()
{
DrawHitbox(.(255, 255, 255, 255));
}
} }
} }

13
src/Static/Calc.bf Normal file
View File

@ -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);
}
}
}