diff --git a/src/Core/Scene.bf b/src/Core/Scene.bf index 2d96a61..fd35852 100644 --- a/src/Core/Scene.bf +++ b/src/Core/Scene.bf @@ -7,6 +7,7 @@ namespace Strawberry { public float TimeStarted { get; private set; } public Grid SolidGrid; + public Rect Bounds; private List entities; private HashSet toRemove; diff --git a/src/Physics/Grid.bf b/src/Physics/Grid.bf index 92572e2..0a0b7c4 100644 --- a/src/Physics/Grid.bf +++ b/src/Physics/Grid.bf @@ -1,4 +1,5 @@ using System; +using Strawberry; namespace Strawberry { @@ -70,6 +71,63 @@ namespace Strawberry public int CellsX => contents.GetLength(0); public int CellsY => contents.GetLength(1); + //Expand Edges + + public enum ExpandDirections { Left, Right, Up, Down }; + + public void ExpandEdge(ExpandDirections direction, int add = 1) + { + Runtime.Assert(add > 0); + + char8[,] newContents; + if (direction == .Left || direction == .Right) + newContents = new char8[CellsX + add, CellsY]; + else + newContents = new char8[CellsX, CellsY + add]; + + switch (direction) + { + case .Left: + Offset.X -= CellSize.X * add; + for (let x < CellsX) + for (let y < CellsY) + newContents[x + add, y] = contents[x, y]; + for (let x < add) + for (let y < CellsY) + newContents[x, y] = contents[0, y]; + + case .Right: + for (let x < CellsX) + for (let y < CellsY) + newContents[x, y] = contents[x, y]; + for (let x < add) + for (let y < CellsY) + newContents[CellsX + x, y] = contents[CellsX - 1, y]; + + case .Up: + Offset.Y -= CellSize.Y * add; + for (let x < CellsX) + for (let y < CellsY) + newContents[x, y + add] = contents[x, y]; + for (let x < CellsX) + for (let y < add) + newContents[x, y] = contents[x, 0]; + + case .Down: + for (let x < CellsX) + for (let y < CellsY) + newContents[x, y] = contents[x, y]; + for (let x < CellsX) + for (let y < add) + newContents[x, CellsY + y] = contents[x, CellsY - 1]; + } + + delete contents; + contents = newContents; + } + + //Collision Checks + public bool IsInBounds(Point p) { return p.X >= 0 && p.Y >= 0 && p.X < CellsX && p.Y < CellsY;