mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 04:53:29 +01:00
added a corner-based rectangleF method to fix the pathfinding demo
This commit is contained in:
parent
60e512f9b1
commit
c209078661
4 changed files with 15 additions and 11 deletions
|
@ -51,10 +51,6 @@
|
|||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Mono.Android" />
|
||||
<Reference Include="MonoGame.Extended, Version=3.7.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\packages\MonoGame.Extended.3.7.0\lib\netstandard2.0\MonoGame.Extended.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
||||
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Demos\Demos.csproj" />
|
||||
<ProjectReference Include="..\MLEM.Extended\MLEM.Extended.csproj" />
|
||||
<ProjectReference Include="..\MLEM.Startup\MLEM.Startup.csproj" />
|
||||
<ProjectReference Include="..\MLEM.Ui\MLEM.Ui.csproj" />
|
||||
<ProjectReference Include="..\MLEM\MLEM.csproj" />
|
||||
|
|
|
@ -53,8 +53,10 @@ namespace Demos {
|
|||
|
||||
// print out some info
|
||||
Console.WriteLine("Pathfinding took " + this.pathfinder.LastTriesNeeded + " tries and " + this.pathfinder.LastTimeNeeded.TotalSeconds + " seconds");
|
||||
if (this.path == null)
|
||||
Console.WriteLine("Couldn't find a path, press the left mouse button to try again");
|
||||
if (this.path == null) {
|
||||
Console.WriteLine("Couldn't find a path, trying again");
|
||||
this.Init();
|
||||
}
|
||||
}
|
||||
|
||||
public override void LoadContent() {
|
||||
|
@ -88,10 +90,9 @@ namespace Demos {
|
|||
// in a real game, you'd obviously make your characters walk along the path instead of drawing it
|
||||
if (this.path != null) {
|
||||
for (var i = 1; i < this.path.Count; i++) {
|
||||
var first = this.path[i - 1];
|
||||
var second = this.path[i];
|
||||
Vector2 firstPos = new Vector2(first.X + 0.25F, first.Y + 0.25F);
|
||||
this.SpriteBatch.Draw(tex, new RectangleF(firstPos, new Vector2(second.X + 0.75F, second.Y + 0.75F) - firstPos), Color.Blue);
|
||||
var (firstX, firstY) = this.path[i - 1];
|
||||
var (secondX, secondY) = this.path[i];
|
||||
this.SpriteBatch.Draw(tex, RectangleF.FromCorners(new Vector2(firstX + 0.25F, firstY + 0.25F), new Vector2(secondX + 0.75F, secondY + 0.75F)), Color.Blue);
|
||||
}
|
||||
}
|
||||
this.SpriteBatch.End();
|
||||
|
|
|
@ -54,6 +54,14 @@ namespace MLEM.Misc {
|
|||
this.Height = size.Y;
|
||||
}
|
||||
|
||||
public static RectangleF FromCorners(Vector2 corner1, Vector2 corner2) {
|
||||
var minX = Math.Min(corner1.X, corner2.X);
|
||||
var minY = Math.Min(corner1.Y, corner2.Y);
|
||||
var maxX = Math.Max(corner1.X, corner2.X);
|
||||
var maxY = Math.Max(corner1.Y, corner2.Y);
|
||||
return new RectangleF(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
public static explicit operator Rectangle(RectangleF rect) {
|
||||
return new Rectangle(rect.X.Floor(), rect.Y.Floor(), rect.Width.Floor(), rect.Height.Floor());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue