mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Entity and Component Ended()
This commit is contained in:
parent
8747ae1cab
commit
610ef2308f
|
@ -17,11 +17,6 @@ namespace Strawberry
|
|||
delete Action;
|
||||
}
|
||||
|
||||
public override void Started()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (Action != null)
|
||||
|
@ -32,10 +27,5 @@ namespace Strawberry
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,11 +35,6 @@ namespace Strawberry
|
|||
CallUpdate();
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Add(TIndex state, delegate void() enter = null, delegate TIndex() update = null, delegate void() exit = null)
|
||||
{
|
||||
let s = new State();
|
||||
|
|
|
@ -31,11 +31,6 @@ namespace Strawberry
|
|||
RemoveOnComplete = destroyOnComplete;
|
||||
}
|
||||
|
||||
public override void Started()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (value > 0)
|
||||
|
@ -53,11 +48,6 @@ namespace Strawberry
|
|||
}
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public float Value
|
||||
{
|
||||
[Inline]
|
||||
|
|
|
@ -27,11 +27,6 @@ namespace Strawberry
|
|||
Active = true;
|
||||
}
|
||||
|
||||
public override void Started()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
T = Math.Min(T + Time.Delta, 1);
|
||||
|
@ -45,10 +40,5 @@ namespace Strawberry
|
|||
RemoveSelf();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,10 @@ namespace Strawberry
|
|||
Entity = null;
|
||||
}
|
||||
|
||||
public abstract void Started();
|
||||
public abstract void Update();
|
||||
public abstract void Draw();
|
||||
public virtual void Started() { }
|
||||
public virtual void Ended() { }
|
||||
public virtual void Update() { }
|
||||
public virtual void Draw() { }
|
||||
|
||||
[Inline]
|
||||
public void RemoveSelf()
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace Strawberry
|
|||
|
||||
private void Removed()
|
||||
{
|
||||
Ended();
|
||||
Scene = null;
|
||||
}
|
||||
|
||||
|
@ -45,6 +46,12 @@ namespace Strawberry
|
|||
c.Started();
|
||||
}
|
||||
|
||||
public virtual void Ended()
|
||||
{
|
||||
for (var c in components)
|
||||
c.Ended();
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
for (var c in components)
|
||||
|
@ -382,6 +389,46 @@ namespace Strawberry
|
|||
return null;
|
||||
}
|
||||
|
||||
public T LeftmostOutside<T>(Point offset) where T : Entity
|
||||
{
|
||||
T ret = null;
|
||||
for (var e in Scene.All<T>(scope List<T>()))
|
||||
if (CheckOutside(e, offset) && (ret == null || e.Left < ret.Left))
|
||||
ret = e;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T RightmostOutside<T>(Point offset) where T : Entity
|
||||
{
|
||||
T ret = null;
|
||||
for (var e in Scene.All<T>(scope List<T>()))
|
||||
if (CheckOutside(e, offset) && (ret == null || e.Right > ret.Right))
|
||||
ret = e;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T TopmostOutside<T>(Point offset) where T : Entity
|
||||
{
|
||||
T ret = null;
|
||||
for (var e in Scene.All<T>(scope List<T>()))
|
||||
if (CheckOutside(e, offset) && (ret == null || e.Top < ret.Top))
|
||||
ret = e;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T BottommostOutside<T>(Point offset) where T : Entity
|
||||
{
|
||||
T ret = null;
|
||||
for (var e in Scene.All<T>(scope List<T>()))
|
||||
if (CheckOutside(e, offset) && (ret == null || e.Bottom > ret.Bottom))
|
||||
ret = e;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<T> All<T>(List<T> into) where T : Entity
|
||||
{
|
||||
for (var e in Scene.All<T>(scope List<T>()))
|
||||
|
|
|
@ -250,5 +250,27 @@ namespace Strawberry
|
|||
return componentTracker[typeof(T)].Count;
|
||||
}
|
||||
|
||||
public List<T> All<T>(List<T> into) where T : Component
|
||||
{
|
||||
for (let c in componentTracker[typeof(T)])
|
||||
into.Add(c as T);
|
||||
return into;
|
||||
}
|
||||
|
||||
public List<T> All<T>(Point point, List<T> into) where T : Component
|
||||
{
|
||||
for (let c in componentTracker[typeof(T)])
|
||||
if (c.Entity.Check(point))
|
||||
into.Add(c as T);
|
||||
return into;
|
||||
}
|
||||
|
||||
public List<T> All<T>(Rect rect, List<T> into) where T : Component
|
||||
{
|
||||
for (let c in componentTracker[typeof(T)])
|
||||
if (c.Entity.Check(rect))
|
||||
into.Add(c as T);
|
||||
return into;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,6 +172,118 @@ 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;
|
||||
|
|
|
@ -92,6 +92,11 @@ namespace Strawberry
|
|||
}
|
||||
}
|
||||
|
||||
static public Cardinals operator -(Cardinals c)
|
||||
{
|
||||
return c.Opposite();
|
||||
}
|
||||
|
||||
static public implicit operator Cardinals(Facings f)
|
||||
{
|
||||
if (f == Facings.Right)
|
||||
|
|
|
@ -35,6 +35,9 @@ namespace Strawberry
|
|||
|
||||
public Vector Normalized()
|
||||
{
|
||||
if (X == 0 && Y == 0)
|
||||
return this;
|
||||
else
|
||||
return this / Length;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user