mirror of
				https://github.com/MaddyThorson/StrawberryBF.git
				synced 2025-11-04 01:41:33 +08:00 
			
		
		
		
	Grid out of bounds checks snap into bounds. RemoveSelf->Destroy
This commit is contained in:
		@ -33,7 +33,7 @@ namespace Strawberry
 | 
				
			|||||||
					value = 0;
 | 
										value = 0;
 | 
				
			||||||
					OnComplete?.Invoke();
 | 
										OnComplete?.Invoke();
 | 
				
			||||||
					if (RemoveOnComplete)
 | 
										if (RemoveOnComplete)
 | 
				
			||||||
						RemoveSelf();
 | 
											Entity.Remove(this);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,7 @@ namespace Strawberry
 | 
				
			|||||||
		public Ease.Easer Easer ~ delete _;
 | 
							public Ease.Easer Easer ~ delete _;
 | 
				
			||||||
		public delegate void(float) OnUpdate ~ delete _;
 | 
							public delegate void(float) OnUpdate ~ delete _;
 | 
				
			||||||
		public delegate void() OnComplete ~ delete _;
 | 
							public delegate void() OnComplete ~ delete _;
 | 
				
			||||||
		public bool RemoveOnComplete;
 | 
							public bool DestroyOnComplete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public bool Playing { get; private set; }
 | 
							public bool Playing { get; private set; }
 | 
				
			||||||
		public float T { get; private set; }
 | 
							public float T { get; private set; }
 | 
				
			||||||
@ -17,7 +17,7 @@ namespace Strawberry
 | 
				
			|||||||
			Easer = easer;
 | 
								Easer = easer;
 | 
				
			||||||
			OnUpdate = onUpdate;
 | 
								OnUpdate = onUpdate;
 | 
				
			||||||
			OnComplete = onComplete;
 | 
								OnComplete = onComplete;
 | 
				
			||||||
			RemoveOnComplete = removeOnComplete;
 | 
								DestroyOnComplete = removeOnComplete;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
@ -45,8 +45,8 @@ namespace Strawberry
 | 
				
			|||||||
			{
 | 
								{
 | 
				
			||||||
				OnComplete?.Invoke();
 | 
									OnComplete?.Invoke();
 | 
				
			||||||
				Playing = false;
 | 
									Playing = false;
 | 
				
			||||||
				if (RemoveOnComplete)
 | 
									if (DestroyOnComplete)
 | 
				
			||||||
					RemoveSelf();
 | 
										Destroy();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -12,9 +12,9 @@ namespace Strawberry
 | 
				
			|||||||
		public virtual void End() { }
 | 
							public virtual void End() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
		public void RemoveSelf()
 | 
							public void Destroy()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Entity?.Remove(this);
 | 
								Entity.Destroy();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
 | 
				
			|||||||
@ -58,7 +58,7 @@ namespace Strawberry
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
		public void RemoveSelf()
 | 
							public void Destroy()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Scene?.Remove(this);
 | 
								Scene?.Remove(this);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -46,7 +46,7 @@ namespace Strawberry
 | 
				
			|||||||
			[Inline]
 | 
								[Inline]
 | 
				
			||||||
			get 
 | 
								get 
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				return contents[x, y];
 | 
									return contents[Math.Clamp(x, 0, CellsX - 1), Math.Clamp(y, 0, CellsY - 1)];
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			[Inline]
 | 
								[Inline]
 | 
				
			||||||
@ -61,13 +61,13 @@ namespace Strawberry
 | 
				
			|||||||
			[Inline]
 | 
								[Inline]
 | 
				
			||||||
			get 
 | 
								get 
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				return contents[p.X, p.Y];
 | 
									return this[p.X, p.Y];
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			[Inline]
 | 
								[Inline]
 | 
				
			||||||
			set
 | 
								set
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				contents[p.X, p.Y] = value;
 | 
									this[p.X, p.Y] = value;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -169,7 +169,7 @@ namespace Strawberry
 | 
				
			|||||||
				for (int y = from.Y; y < to.Y; y++)
 | 
									for (int y = from.Y; y < to.Y; y++)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					let p = Point(x, y);
 | 
										let p = Point(x, y);
 | 
				
			||||||
					if (IsInBounds(p) && this[p] != '0')
 | 
										if (this[p] != '0')
 | 
				
			||||||
						return true;
 | 
											return true;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -177,122 +177,10 @@ namespace Strawberry
 | 
				
			|||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public bool CheckTop(Rect rect, out int top)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			Point from = .(
 | 
					 | 
				
			||||||
				(int)Math.Floor((rect.X - Offset.X) / (float)CellSize.X),
 | 
					 | 
				
			||||||
				(int)Math.Floor((rect.Y - Offset.Y) / (float)CellSize.Y)
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
			Point to = .(
 | 
					 | 
				
			||||||
				(int)Math.Ceiling((rect.Right - Offset.X) / (float)CellSize.X),
 | 
					 | 
				
			||||||
				(int)Math.Ceiling((rect.Bottom - Offset.Y) / (float)CellSize.Y)
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			for (int y = from.Y; y < to.Y; y++)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				for (int x = from.X; x < to.X; x++)
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					let p = Point(x, y);
 | 
					 | 
				
			||||||
					if (IsInBounds(p) && this[p] != '0')
 | 
					 | 
				
			||||||
					{
 | 
					 | 
				
			||||||
						top = Offset.Y + y * CellSize.Y;
 | 
					 | 
				
			||||||
						return true;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			top = 0;
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public bool CheckBottom(Rect rect, out int bottom)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			Point from = .(
 | 
					 | 
				
			||||||
				(int)Math.Floor((rect.X - Offset.X) / (float)CellSize.X),
 | 
					 | 
				
			||||||
				(int)Math.Floor((rect.Y - Offset.Y) / (float)CellSize.Y)
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
			Point to = .(
 | 
					 | 
				
			||||||
				(int)Math.Ceiling((rect.Right - Offset.X) / (float)CellSize.X),
 | 
					 | 
				
			||||||
				(int)Math.Ceiling((rect.Bottom - Offset.Y) / (float)CellSize.Y)
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			for (int y = to.Y - 1; y >= from.Y; y--)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				for (int x = from.X; x < to.X; x++)
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					let p = Point(x, y);
 | 
					 | 
				
			||||||
					if (IsInBounds(p) && this[p] != '0')
 | 
					 | 
				
			||||||
					{
 | 
					 | 
				
			||||||
						bottom = Offset.Y + (y + 1) * CellSize.Y;
 | 
					 | 
				
			||||||
						return true;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			bottom = 0;
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public bool CheckLeft(Rect rect, out int left)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			Point from = .(
 | 
					 | 
				
			||||||
				(int)Math.Floor((rect.X - Offset.X) / (float)CellSize.X),
 | 
					 | 
				
			||||||
				(int)Math.Floor((rect.Y - Offset.Y) / (float)CellSize.Y)
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
			Point to = .(
 | 
					 | 
				
			||||||
				(int)Math.Ceiling((rect.Right - Offset.X) / (float)CellSize.X),
 | 
					 | 
				
			||||||
				(int)Math.Ceiling((rect.Bottom - Offset.Y) / (float)CellSize.Y)
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			for (int x = from.X; x < to.X; x++)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				for (int y = from.Y; y < to.Y; y++)
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					let p = Point(x, y);
 | 
					 | 
				
			||||||
					if (IsInBounds(p) && this[p] != '0')
 | 
					 | 
				
			||||||
					{
 | 
					 | 
				
			||||||
						left = Offset.X + x * CellSize.X;
 | 
					 | 
				
			||||||
						return true;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			left = 0;
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public bool CheckRight(Rect rect, out int right)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			Point from = .(
 | 
					 | 
				
			||||||
				(int)Math.Floor((rect.X - Offset.X) / (float)CellSize.X),
 | 
					 | 
				
			||||||
				(int)Math.Floor((rect.Y - Offset.Y) / (float)CellSize.Y)
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
			Point to = .(
 | 
					 | 
				
			||||||
				(int)Math.Ceiling((rect.Right - Offset.X) / (float)CellSize.X),
 | 
					 | 
				
			||||||
				(int)Math.Ceiling((rect.Bottom - Offset.Y) / (float)CellSize.Y)
 | 
					 | 
				
			||||||
			);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			for (int x = to.X - 1; x >= from.X; x--)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				for (int y = from.Y; y < to.Y; y++)
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					let p = Point(x, y);
 | 
					 | 
				
			||||||
					if (IsInBounds(p) && this[p] != '0')
 | 
					 | 
				
			||||||
					{
 | 
					 | 
				
			||||||
						right = Offset.X + (x + 1) * CellSize.X;
 | 
					 | 
				
			||||||
						return true;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			right = 0;
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public bool Check(Point point)
 | 
							public bool Check(Point point)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Point check = (point - Offset) / CellSize;
 | 
								Point check = (point - Offset) / CellSize;
 | 
				
			||||||
			return IsInBounds(check) && this[check] != '0';
 | 
								return this[check] != '0';
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void Draw(Color color)
 | 
							public void Draw(Color color)
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user