mirror of
				https://github.com/MaddyThorson/StrawberryBF.git
				synced 2025-11-04 01:41:33 +08:00 
			
		
		
		
	Actor fixes. Calc.Map functions
This commit is contained in:
		@ -7,7 +7,8 @@ namespace Strawberry
 | 
			
		||||
	{
 | 
			
		||||
		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)
 | 
			
		||||
			: base(position)
 | 
			
		||||
@ -68,10 +69,24 @@ namespace Strawberry
 | 
			
		||||
				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 sign = Math.Sign(amount);
 | 
			
		||||
			bool byGeometry = carrier != null || pusher != null;
 | 
			
		||||
 | 
			
		||||
			while (move != 0)
 | 
			
		||||
			{
 | 
			
		||||
				let hit = First<Solid>(.(sign, 0));
 | 
			
		||||
@ -104,16 +119,20 @@ namespace Strawberry
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				X += sign;
 | 
			
		||||
				if (byGeometry)
 | 
			
		||||
					MovedByGeometry.X += sign;
 | 
			
		||||
				move -= sign;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			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 sign = Math.Sign(amount);
 | 
			
		||||
			bool byGeometry = carrier != null || pusher != null;
 | 
			
		||||
 | 
			
		||||
			while (move != 0)
 | 
			
		||||
			{
 | 
			
		||||
				Geometry hit = First<Solid>(.(0, sign));
 | 
			
		||||
@ -149,6 +168,8 @@ namespace Strawberry
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				Y += sign;
 | 
			
		||||
				if (byGeometry)
 | 
			
		||||
					MovedByGeometry.Y += sign;
 | 
			
		||||
				move -= sign;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@ -169,5 +190,10 @@ namespace Strawberry
 | 
			
		||||
		{
 | 
			
		||||
			remainder = Vector.Zero;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private void MoveByGeometry(Point amount)
 | 
			
		||||
		{
 | 
			
		||||
			MovedByGeometry += amount;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System;
 | 
			
		||||
namespace Strawberry
 | 
			
		||||
{
 | 
			
		||||
	public class JumpThru : Geometry
 | 
			
		||||
@ -23,10 +24,7 @@ namespace Strawberry
 | 
			
		||||
	
 | 
			
		||||
				X += amount;
 | 
			
		||||
				for (var a in riders)
 | 
			
		||||
				{
 | 
			
		||||
					a.MoveExactX(amount);
 | 
			
		||||
					a.MovedByGeometry += Point.UnitX * amount;
 | 
			
		||||
				}
 | 
			
		||||
					a.MoveExactX(amount, null, null, this);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
				X += amount;
 | 
			
		||||
@ -45,8 +43,7 @@ namespace Strawberry
 | 
			
		||||
						if (riders.Contains(a) || CheckOutside(a, Point.UnitY * amount))
 | 
			
		||||
						{
 | 
			
		||||
							let move = (Top + amount) - a.Bottom;
 | 
			
		||||
							a.MoveExactY(move);
 | 
			
		||||
							a.MovedByGeometry += Point.UnitY * move;
 | 
			
		||||
							a.MoveExactY(move, null, null, this);
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					Y += amount;
 | 
			
		||||
@ -56,10 +53,7 @@ namespace Strawberry
 | 
			
		||||
					Collidable = false;
 | 
			
		||||
 | 
			
		||||
					for (var a in riders)
 | 
			
		||||
					{
 | 
			
		||||
						a.MoveExactY(amount);
 | 
			
		||||
						a.MovedByGeometry += Point.UnitY * amount;
 | 
			
		||||
					}
 | 
			
		||||
						a.MoveExactY(amount, null, null, this);
 | 
			
		||||
 | 
			
		||||
					Collidable = true;
 | 
			
		||||
					Y += amount;
 | 
			
		||||
 | 
			
		||||
@ -38,13 +38,11 @@ namespace Strawberry
 | 
			
		||||
						else
 | 
			
		||||
							move = Left - a.Right;
 | 
			
		||||
						a.MoveExactX(move, scope => a.Squish, this);
 | 
			
		||||
						a.MovedByGeometry += Point.UnitX * move;
 | 
			
		||||
					}
 | 
			
		||||
					else if (riders.Contains(a))
 | 
			
		||||
					{
 | 
			
		||||
						//Carry
 | 
			
		||||
						a.MoveExactX(amount);
 | 
			
		||||
						a.MovedByGeometry += Point.UnitX * amount;
 | 
			
		||||
						a.MoveExactX(amount, null, null, this);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@ -74,13 +72,11 @@ namespace Strawberry
 | 
			
		||||
						else
 | 
			
		||||
							move = Top - a.Bottom;
 | 
			
		||||
						a.MoveExactY(move, scope => a.Squish, this);
 | 
			
		||||
						a.MovedByGeometry += Point.UnitY * move;
 | 
			
		||||
					}
 | 
			
		||||
					else if (riders.Contains(a))
 | 
			
		||||
					{
 | 
			
		||||
						//Carry
 | 
			
		||||
						a.MoveExactY(amount);
 | 
			
		||||
						a.MovedByGeometry += Point.UnitY * amount;
 | 
			
		||||
						a.MoveExactY(amount, null, null, this);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,30 @@ namespace Strawberry
 | 
			
		||||
			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()
 | 
			
		||||
		{
 | 
			
		||||
			Debug.WriteLine("***");
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user