mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Grid out of bounds checks snap into bounds. RemoveSelf->Destroy
This commit is contained in:
parent
33dad92fcf
commit
ccf4db2f9f
|
@ -33,7 +33,7 @@ namespace Strawberry
|
|||
value = 0;
|
||||
OnComplete?.Invoke();
|
||||
if (RemoveOnComplete)
|
||||
RemoveSelf();
|
||||
Entity.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Strawberry
|
|||
public Ease.Easer Easer ~ delete _;
|
||||
public delegate void(float) OnUpdate ~ delete _;
|
||||
public delegate void() OnComplete ~ delete _;
|
||||
public bool RemoveOnComplete;
|
||||
public bool DestroyOnComplete;
|
||||
|
||||
public bool Playing { get; private set; }
|
||||
public float T { get; private set; }
|
||||
|
@ -17,7 +17,7 @@ namespace Strawberry
|
|||
Easer = easer;
|
||||
OnUpdate = onUpdate;
|
||||
OnComplete = onComplete;
|
||||
RemoveOnComplete = removeOnComplete;
|
||||
DestroyOnComplete = removeOnComplete;
|
||||
}
|
||||
|
||||
[Inline]
|
||||
|
@ -45,8 +45,8 @@ namespace Strawberry
|
|||
{
|
||||
OnComplete?.Invoke();
|
||||
Playing = false;
|
||||
if (RemoveOnComplete)
|
||||
RemoveSelf();
|
||||
if (DestroyOnComplete)
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ namespace Strawberry
|
|||
public virtual void End() { }
|
||||
|
||||
[Inline]
|
||||
public void RemoveSelf()
|
||||
public void Destroy()
|
||||
{
|
||||
Entity?.Remove(this);
|
||||
Entity.Destroy();
|
||||
}
|
||||
|
||||
[Inline]
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace Strawberry
|
|||
}
|
||||
|
||||
[Inline]
|
||||
public void RemoveSelf()
|
||||
public void Destroy()
|
||||
{
|
||||
Scene?.Remove(this);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Strawberry
|
|||
[Inline]
|
||||
get
|
||||
{
|
||||
return contents[x, y];
|
||||
return contents[Math.Clamp(x, 0, CellsX - 1), Math.Clamp(y, 0, CellsY - 1)];
|
||||
}
|
||||
|
||||
[Inline]
|
||||
|
@ -61,13 +61,13 @@ namespace Strawberry
|
|||
[Inline]
|
||||
get
|
||||
{
|
||||
return contents[p.X, p.Y];
|
||||
return this[p.X, p.Y];
|
||||
}
|
||||
|
||||
[Inline]
|
||||
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++)
|
||||
{
|
||||
let p = Point(x, y);
|
||||
if (IsInBounds(p) && this[p] != '0')
|
||||
if (this[p] != '0')
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -177,122 +177,10 @@ namespace Strawberry
|
|||
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)
|
||||
{
|
||||
Point check = (point - Offset) / CellSize;
|
||||
return IsInBounds(check) && this[check] != '0';
|
||||
return this[check] != '0';
|
||||
}
|
||||
|
||||
public void Draw(Color color)
|
||||
|
|
Loading…
Reference in New Issue
Block a user