mirror of
				https://github.com/MaddyThorson/StrawberryBF.git
				synced 2025-11-04 01:41:33 +08:00 
			
		
		
		
	Numerics ToString overrides. Moving Solids work. Actor.Pushed
This commit is contained in:
		@ -27,6 +27,23 @@ namespace Strawberry
 | 
				
			|||||||
			Y = y;
 | 
								Y = y;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public override void ToString(String strBuffer)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								let s = scope String;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Set("[ ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								X.ToString(s);
 | 
				
			||||||
 | 
								strBuffer.Append(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Append(", ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Y.ToString(s);
 | 
				
			||||||
 | 
								strBuffer.Append(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Append(" ]");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		static public explicit operator Point(Vector a)
 | 
							static public explicit operator Point(Vector a)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return Point((int)a.X, (int)a.Y);
 | 
								return Point((int)a.X, (int)a.Y);
 | 
				
			||||||
 | 
				
			|||||||
@ -111,6 +111,33 @@ namespace Strawberry
 | 
				
			|||||||
			return point.X >= X && point.X < X + Width && point.Y >= Y && point.Y < Y + Height;
 | 
								return point.X >= X && point.X < X + Width && point.Y >= Y && point.Y < Y + Height;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public override void ToString(String strBuffer)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								let s = scope String;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Set("[ ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								X.ToString(s);
 | 
				
			||||||
 | 
								strBuffer.Append(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Append(", ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Y.ToString(s);
 | 
				
			||||||
 | 
								strBuffer.Append(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Append(", ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Width.ToString(s);
 | 
				
			||||||
 | 
								strBuffer.Append(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Append(", ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Height.ToString(s);
 | 
				
			||||||
 | 
								strBuffer.Append(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Append(" ]");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		static public bool operator==(Rect a, Rect b)
 | 
							static public bool operator==(Rect a, Rect b)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
 | 
								return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
 | 
				
			||||||
 | 
				
			|||||||
@ -51,6 +51,23 @@ namespace Strawberry
 | 
				
			|||||||
			return Point((int)Math.Round(X), (int)Math.Round(Y));
 | 
								return Point((int)Math.Round(X), (int)Math.Round(Y));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public override void ToString(String strBuffer)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								let s = scope String;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Set("[ ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								X.ToString(s);
 | 
				
			||||||
 | 
								strBuffer.Append(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Append(", ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Y.ToString(s);
 | 
				
			||||||
 | 
								strBuffer.Append(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								strBuffer.Append(" ]");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		static public operator Vector(Point a)
 | 
							static public operator Vector(Point a)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return Vector(a.X, a.Y);
 | 
								return Vector(a.X, a.Y);
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,8 @@ namespace Strawberry
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		private Vector remainder;
 | 
							private Vector remainder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public Point Pushed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public this(Point position)
 | 
							public this(Point position)
 | 
				
			||||||
			: base(position)
 | 
								: base(position)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@ -28,11 +30,20 @@ namespace Strawberry
 | 
				
			|||||||
			return CheckOutside(jumpThru, .(0, 1));
 | 
								return CheckOutside(jumpThru, .(0, 1));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public virtual void Squish()
 | 
							public virtual void Squish(Collision collision)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			RemoveSelf();
 | 
								RemoveSelf();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public override void Update()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								base.Update();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (Pushed != Point.Zero)
 | 
				
			||||||
 | 
									Calc.Log(Pushed);
 | 
				
			||||||
 | 
								Pushed = Point.Zero;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public bool MoveX(float amount, Action<Collision> onCollide = null)
 | 
							public bool MoveX(float amount, Action<Collision> onCollide = null)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			remainder.X += amount;
 | 
								remainder.X += amount;
 | 
				
			||||||
 | 
				
			|||||||
@ -23,8 +23,11 @@ namespace Strawberry
 | 
				
			|||||||
				let riders = GetRiders(scope List<Actor>);
 | 
									let riders = GetRiders(scope List<Actor>);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
				X += amount;
 | 
									X += amount;
 | 
				
			||||||
				for (var r in riders)
 | 
									for (var a in riders)
 | 
				
			||||||
					r.MoveExactX(amount);
 | 
									{
 | 
				
			||||||
 | 
										a.MoveExactX(amount);
 | 
				
			||||||
 | 
										a.Pushed += Point.UnitX * amount;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
				X += amount;
 | 
									X += amount;
 | 
				
			||||||
@ -39,8 +42,14 @@ namespace Strawberry
 | 
				
			|||||||
				if (amount < 0)
 | 
									if (amount < 0)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					for (var a in Scene.All<Actor>(scope List<Actor>))
 | 
										for (var a in Scene.All<Actor>(scope List<Actor>))
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
						if (riders.Contains(a) || CheckOutside(a, Point.UnitY * amount))
 | 
											if (riders.Contains(a) || CheckOutside(a, Point.UnitY * amount))
 | 
				
			||||||
							a.MoveExactY((Top + amount) - a.Bottom);
 | 
											{
 | 
				
			||||||
 | 
												let move = (Top + amount) - a.Bottom;
 | 
				
			||||||
 | 
												a.MoveExactY(move);
 | 
				
			||||||
 | 
												a.Pushed += Point.UnitY * move;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
					Y += amount;
 | 
										Y += amount;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else
 | 
									else
 | 
				
			||||||
@ -48,7 +57,10 @@ namespace Strawberry
 | 
				
			|||||||
					Collidable = false;
 | 
										Collidable = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					for (var a in riders)
 | 
										for (var a in riders)
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
						a.MoveExactY(amount);
 | 
											a.MoveExactY(amount);
 | 
				
			||||||
 | 
											a.Pushed += Point.UnitY * amount;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					Collidable = true;
 | 
										Collidable = true;
 | 
				
			||||||
					Y += amount;
 | 
										Y += amount;
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,13 @@ namespace Strawberry
 | 
				
			|||||||
			Hitbox = hitbox;
 | 
								Hitbox = hitbox;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public override void Update()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								base.Update();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								MoveY(0.1f);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		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>))
 | 
				
			||||||
@ -20,18 +27,74 @@ namespace Strawberry
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		public override void MoveExactX(int amount)
 | 
							public override void MoveExactX(int amount)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (amount != 0)
 | 
								if (Collidable)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
 | 
									let riders = GetRiders(scope List<Actor>);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									X += amount;
 | 
				
			||||||
 | 
									Collidable = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									for (Actor a in Scene.All<Actor>(scope List<Actor>))
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										if (Check(a))
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											//Push
 | 
				
			||||||
 | 
											int move;
 | 
				
			||||||
 | 
											if (amount > 0)
 | 
				
			||||||
 | 
												move = Right - a.Left;
 | 
				
			||||||
 | 
											else
 | 
				
			||||||
 | 
												move = Left - a.Right;
 | 
				
			||||||
 | 
											a.MoveExactX(move, scope => a.Squish, this);
 | 
				
			||||||
 | 
											a.Pushed += Point.UnitX * move;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
										else if (riders.Contains(a))
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											//Carry
 | 
				
			||||||
 | 
											a.MoveExactX(amount);
 | 
				
			||||||
 | 
											a.Pushed += Point.UnitX * amount;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									Collidable = true;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									X += amount;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public override void MoveExactY(int amount)
 | 
							public override void MoveExactY(int amount)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (amount != 0)
 | 
								if (Collidable)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
 | 
									let riders = GetRiders(scope List<Actor>);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									Y += amount;
 | 
				
			||||||
 | 
									Collidable = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									for (Actor a in Scene.All<Actor>(scope List<Actor>))
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										if (Check(a))
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											//Push
 | 
				
			||||||
 | 
											int move;
 | 
				
			||||||
 | 
											if (amount > 0)
 | 
				
			||||||
 | 
												move = Bottom - a.Top;
 | 
				
			||||||
 | 
											else
 | 
				
			||||||
 | 
												move = Top - a.Bottom;
 | 
				
			||||||
 | 
											a.MoveExactY(move, scope => a.Squish, this);
 | 
				
			||||||
 | 
											a.Pushed += Point.UnitY * move;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
										else if (riders.Contains(a))
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											//Carry
 | 
				
			||||||
 | 
											a.MoveExactY(amount);
 | 
				
			||||||
 | 
											a.Pushed += Point.UnitY * amount;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									Collidable = true;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									Y += amount;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public override void Draw()
 | 
							public override void Draw()
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user