mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-28 16:58:56 +08:00
Reorganizing
This commit is contained in:
parent
9374086e97
commit
409a82d6b8
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<Solid>(.(0, distance));
|
||||
return Check<Solid>(.(0, distance)) || CheckOutside<JumpThru>(.(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<Collision> onCollide = null)
|
||||
|
@ -90,7 +95,10 @@ namespace Strawberry
|
|||
int sign = Math.Sign(amount);
|
||||
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)
|
||||
{
|
||||
ZeroRemainderY();
|
||||
|
|
|
@ -7,8 +7,8 @@ namespace Strawberry
|
|||
{
|
||||
private Vector remainder;
|
||||
|
||||
public this(int x, int y)
|
||||
: base(x, y)
|
||||
public this(Point position)
|
||||
: base(position)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
39
src/Physics/JumpThru.bf
Normal file
39
src/Physics/JumpThru.bf
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Actor> GetRiders(List<Actor> into)
|
||||
{
|
||||
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
13
src/Static/Calc.bf
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user