mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2025-04-20 05:36:06 +08:00
Actor fixes. Calc.Map functions
This commit is contained in:
parent
f6eabf5fc3
commit
95c2d5f12f
@ -7,7 +7,8 @@ namespace Strawberry
|
|||||||
{
|
{
|
||||||
private Vector remainder;
|
private Vector remainder;
|
||||||
|
|
||||||
public Point MovedByGeometry;
|
// The amount that geometry has pushed or carried this Actor since the last frame
|
||||||
|
public Point MovedByGeometry { get; private set; }
|
||||||
|
|
||||||
public this(Point position)
|
public this(Point position)
|
||||||
: base(position)
|
: base(position)
|
||||||
@ -68,10 +69,24 @@ namespace Strawberry
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MoveExactX(int amount, Action<Collision> onCollide = null, Geometry pusher = null)
|
[Inline]
|
||||||
|
public void MoveToX(float x)
|
||||||
|
{
|
||||||
|
MoveX(x - (X + remainder.X));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
public void MoveToY(float y)
|
||||||
|
{
|
||||||
|
MoveY(y - (Y + remainder.Y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveExactX(int amount, Action<Collision> onCollide = null, Geometry pusher = null, Geometry carrier = null)
|
||||||
{
|
{
|
||||||
int move = amount;
|
int move = amount;
|
||||||
int sign = Math.Sign(amount);
|
int sign = Math.Sign(amount);
|
||||||
|
bool byGeometry = carrier != null || pusher != null;
|
||||||
|
|
||||||
while (move != 0)
|
while (move != 0)
|
||||||
{
|
{
|
||||||
let hit = First<Solid>(.(sign, 0));
|
let hit = First<Solid>(.(sign, 0));
|
||||||
@ -104,16 +119,20 @@ namespace Strawberry
|
|||||||
}
|
}
|
||||||
|
|
||||||
X += sign;
|
X += sign;
|
||||||
|
if (byGeometry)
|
||||||
|
MovedByGeometry.X += sign;
|
||||||
move -= sign;
|
move -= sign;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MoveExactY(int amount, Action<Collision> onCollide = null, Geometry pusher = null)
|
public bool MoveExactY(int amount, Action<Collision> onCollide = null, Geometry pusher = null, Geometry carrier = null)
|
||||||
{
|
{
|
||||||
int move = amount;
|
int move = amount;
|
||||||
int sign = Math.Sign(amount);
|
int sign = Math.Sign(amount);
|
||||||
|
bool byGeometry = carrier != null || pusher != null;
|
||||||
|
|
||||||
while (move != 0)
|
while (move != 0)
|
||||||
{
|
{
|
||||||
Geometry hit = First<Solid>(.(0, sign));
|
Geometry hit = First<Solid>(.(0, sign));
|
||||||
@ -149,6 +168,8 @@ namespace Strawberry
|
|||||||
}
|
}
|
||||||
|
|
||||||
Y += sign;
|
Y += sign;
|
||||||
|
if (byGeometry)
|
||||||
|
MovedByGeometry.Y += sign;
|
||||||
move -= sign;
|
move -= sign;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,5 +190,10 @@ namespace Strawberry
|
|||||||
{
|
{
|
||||||
remainder = Vector.Zero;
|
remainder = Vector.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MoveByGeometry(Point amount)
|
||||||
|
{
|
||||||
|
MovedByGeometry += amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System;
|
||||||
namespace Strawberry
|
namespace Strawberry
|
||||||
{
|
{
|
||||||
public class JumpThru : Geometry
|
public class JumpThru : Geometry
|
||||||
@ -23,10 +24,7 @@ namespace Strawberry
|
|||||||
|
|
||||||
X += amount;
|
X += amount;
|
||||||
for (var a in riders)
|
for (var a in riders)
|
||||||
{
|
a.MoveExactX(amount, null, null, this);
|
||||||
a.MoveExactX(amount);
|
|
||||||
a.MovedByGeometry += Point.UnitX * amount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
X += amount;
|
X += amount;
|
||||||
@ -45,8 +43,7 @@ namespace Strawberry
|
|||||||
if (riders.Contains(a) || CheckOutside(a, Point.UnitY * amount))
|
if (riders.Contains(a) || CheckOutside(a, Point.UnitY * amount))
|
||||||
{
|
{
|
||||||
let move = (Top + amount) - a.Bottom;
|
let move = (Top + amount) - a.Bottom;
|
||||||
a.MoveExactY(move);
|
a.MoveExactY(move, null, null, this);
|
||||||
a.MovedByGeometry += Point.UnitY * move;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Y += amount;
|
Y += amount;
|
||||||
@ -56,10 +53,7 @@ namespace Strawberry
|
|||||||
Collidable = false;
|
Collidable = false;
|
||||||
|
|
||||||
for (var a in riders)
|
for (var a in riders)
|
||||||
{
|
a.MoveExactY(amount, null, null, this);
|
||||||
a.MoveExactY(amount);
|
|
||||||
a.MovedByGeometry += Point.UnitY * amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
Collidable = true;
|
Collidable = true;
|
||||||
Y += amount;
|
Y += amount;
|
||||||
|
@ -38,13 +38,11 @@ namespace Strawberry
|
|||||||
else
|
else
|
||||||
move = Left - a.Right;
|
move = Left - a.Right;
|
||||||
a.MoveExactX(move, scope => a.Squish, this);
|
a.MoveExactX(move, scope => a.Squish, this);
|
||||||
a.MovedByGeometry += Point.UnitX * move;
|
|
||||||
}
|
}
|
||||||
else if (riders.Contains(a))
|
else if (riders.Contains(a))
|
||||||
{
|
{
|
||||||
//Carry
|
//Carry
|
||||||
a.MoveExactX(amount);
|
a.MoveExactX(amount, null, null, this);
|
||||||
a.MovedByGeometry += Point.UnitX * amount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,13 +72,11 @@ namespace Strawberry
|
|||||||
else
|
else
|
||||||
move = Top - a.Bottom;
|
move = Top - a.Bottom;
|
||||||
a.MoveExactY(move, scope => a.Squish, this);
|
a.MoveExactY(move, scope => a.Squish, this);
|
||||||
a.MovedByGeometry += Point.UnitY * move;
|
|
||||||
}
|
}
|
||||||
else if (riders.Contains(a))
|
else if (riders.Contains(a))
|
||||||
{
|
{
|
||||||
//Carry
|
//Carry
|
||||||
a.MoveExactY(amount);
|
a.MoveExactY(amount, null, null, this);
|
||||||
a.MovedByGeometry += Point.UnitY * amount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,30 @@ namespace Strawberry
|
|||||||
return value > target ? Math.Max(value - maxDelta, target) : Math.Min(value + maxDelta, target);
|
return value > target ? Math.Max(value - maxDelta, target) : Math.Min(value + maxDelta, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
static public float Map(float value, float oldMin, float oldMax)
|
||||||
|
{
|
||||||
|
return (value - oldMin) / (oldMax - oldMin);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
static public float Map(float value, float oldMin, float oldMax, float newMin, float newMax)
|
||||||
|
{
|
||||||
|
return newMin + (newMax - newMin) * Map(value, oldMin, oldMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
static public float ClampedMap(float value, float oldMin, float oldMax)
|
||||||
|
{
|
||||||
|
return Math.Clamp((value - oldMin) / (oldMax - oldMin), 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
static public float ClampedMap(float value, float oldMin, float oldMax, float newMin, float newMax)
|
||||||
|
{
|
||||||
|
return newMin + (newMax - newMin) * ClampedMap(value, oldMin, oldMax);
|
||||||
|
}
|
||||||
|
|
||||||
static public void Log()
|
static public void Log()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("***");
|
Debug.WriteLine("***");
|
||||||
|
Loading…
Reference in New Issue
Block a user