Skip to content

Commit

Permalink
Remove my own primitives and replace them with XNA
Browse files Browse the repository at this point in the history
  • Loading branch information
YogurtTheHorse committed May 4, 2019
1 parent b526d65 commit 0713e18
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 101 deletions.
20 changes: 10 additions & 10 deletions src/Dyflissu.DesktopGL/DyflissuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DyflissuGame : Game
public DyflissuGame()
{
graphics = new GraphicsDeviceManager(this);
world = new World(new Primitives.Vector2(0, 1f));
world = new World(new Vector2(0, 1f));
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
Expand All @@ -28,14 +28,14 @@ protected override void Initialize()
{
Shape = new RectangleShape(10f),
Mass = 1f,
Position = new Primitives.Vector2(250f, 250f - 20)
Position = new Vector2(250f, 250f - 20)
};

world.AddBody(controlledBody);
world.AddBody(new Body
{
Mass = 0,
Position = new Primitives.Vector2(250f, 250f + 20),
Position = new Vector2(250f, 250f + 20),
Shape = new RectangleShape(100f, 30f),
});

Expand Down Expand Up @@ -63,30 +63,30 @@ protected override void Update(GameTime gameTime)
world.AddBody(new Body
{
Shape = new RectangleShape(10f),
Position = new Primitives.Vector2(currentMouseState.X, currentMouseState.Y)
Position = new Vector2(currentMouseState.X, currentMouseState.Y)
});
}

Primitives.Vector2 velocity;
Vector2 velocity;
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
velocity = new Primitives.Vector2(0, 1);
velocity = new Vector2(0, 1);
}
else if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
velocity = new Primitives.Vector2(0, -1);
velocity = new Vector2(0, -1);
}
else if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
velocity = new Primitives.Vector2(-1, 0);
velocity = new Vector2(-1, 0);
}
else if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
velocity = new Primitives.Vector2(1, 0);
velocity = new Vector2(1, 0);
}
else
{
velocity = new Primitives.Vector2(0);
velocity = new Vector2(0);
}

controlledBody.Velocity = velocity;
Expand Down
7 changes: 2 additions & 5 deletions src/Dyflissu.DesktopGL/PhysicsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Dyflissu.Physics.Shapes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using DyflissuVector2 = Dyflissu.Primitives.Vector2;

namespace Dyflissu.DesktopGL
{
Expand All @@ -16,13 +15,11 @@ public static void Draw(this World world, SpriteBatch spriteBatch)
switch (body.Shape)
{
case RectangleShape rectangleShape:
Vector2 position = (body.Position - body.Shape.Box / 2).ToXna();
spriteBatch.DrawRectangle(position, rectangleShape.Box.ToXna(), Color.Green);
Vector2 position = (body.Position - body.Shape.Box / 2);
spriteBatch.DrawRectangle(position, rectangleShape.Box, Color.Green);
break;
}
}
}

public static Vector2 ToXna(this DyflissuVector2 v) => new Vector2(v.X, v.Y);
}
}
3 changes: 2 additions & 1 deletion src/Dyflissu.Physics/Body.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dyflissu.Physics.Shapes;
using Dyflissu.Primitives;
using Microsoft.Xna.Framework;

// Argh. I'm checking exactly with zero, don't bother me, man.
// ReSharper disable CompareOfFloatsByEqualityOperator

Expand Down
3 changes: 1 addition & 2 deletions src/Dyflissu.Physics/CollisionChecker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using Dyflissu.Physics.Shapes;
using Dyflissu.Primitives;
using Microsoft.Xna.Framework;

namespace Dyflissu.Physics
{
Expand Down
2 changes: 1 addition & 1 deletion src/Dyflissu.Physics/Dyflissu.Physics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Dyflissu.Primitives\Dyflissu.Primitives.csproj" />
<PackageReference Include="MonoGame.Framework.Portable" Version="3.7.1.189" />
</ItemGroup>

</Project>
14 changes: 7 additions & 7 deletions src/Dyflissu.Physics/Manifold.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Dyflissu.Primitives;
using Microsoft.Xna.Framework;

namespace Dyflissu.Physics
{
Expand Down Expand Up @@ -27,23 +27,23 @@ public Manifold(Body a, Body b)
A = a;
B = b;

E = Math.Abs((b.Velocity - a.Velocity).SquareLength) < 1e-10
E = Math.Abs((b.Velocity - a.Velocity).LengthSquared()) < 1e-10
? 0
: MathF.Min(a.Restitution, b.Restitution);
}

public bool Solve()
{
Vector2 normal = A.Position - B.Position;
float aHalfSizeX = A.Shape.Box.X / 2;
float bHalfSizeX = B.Shape.Box.X / 2;
float aHalfSizeX = A.Shape.Box.X / 2f;
float bHalfSizeX = B.Shape.Box.X / 2f;

float xOverlap = aHalfSizeX + bHalfSizeX - MathF.Abs(normal.X);

if (xOverlap <= 0) return false;

float aHalfSizeY = A.Shape.Box.Y / 2;
float bHalfSizeY = B.Shape.Box.Y / 2;
float aHalfSizeY = A.Shape.Box.Y / 2f;
float bHalfSizeY = B.Shape.Box.Y / 2f;

float yOverlap = aHalfSizeY + bHalfSizeY - MathF.Abs(normal.Y);

Expand All @@ -70,7 +70,7 @@ public bool Solve()

public void Resolve()
{
E = Math.Abs((B.Velocity - A.Velocity).SquareLength) < 1e-10
E = Math.Abs((B.Velocity - A.Velocity).LengthSquared()) < 1e-10
? 0
: MathF.Min(A.Restitution, B.Restitution);

Expand Down
2 changes: 1 addition & 1 deletion src/Dyflissu.Physics/PhysicsMath.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dyflissu.Primitives;
using Microsoft.Xna.Framework;

namespace Dyflissu.Physics
{
Expand Down
2 changes: 1 addition & 1 deletion src/Dyflissu.Physics/Shapes/RectangleShape.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dyflissu.Primitives;
using Microsoft.Xna.Framework;

namespace Dyflissu.Physics.Shapes
{
Expand Down
3 changes: 1 addition & 2 deletions src/Dyflissu.Physics/Shapes/Shape.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Dyflissu.Primitives;
using Microsoft.Xna.Framework;

namespace Dyflissu.Physics.Shapes
{
Expand Down
3 changes: 1 addition & 2 deletions src/Dyflissu.Physics/World.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Dyflissu.Primitives;
using Microsoft.Xna.Framework;

namespace Dyflissu.Physics
{
Expand Down
7 changes: 0 additions & 7 deletions src/Dyflissu.Primitives/Dyflissu.Primitives.csproj

This file was deleted.

55 changes: 0 additions & 55 deletions src/Dyflissu.Primitives/Vector2.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Dyflissu.Shared/GameWorld.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Dyflissu.Physics;
using Dyflissu.Primitives;
using Microsoft.Xna.Framework;

namespace Dyflissu.Shared
{
Expand Down
6 changes: 0 additions & 6 deletions src/Dyflissu.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dyflissu.Backend", "Dyfliss
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dyflissu.Physics", "Dyflissu.Physics\Dyflissu.Physics.csproj", "{D0161D6B-B987-4D22-AC82-E136874EBBB0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dyflissu.Primitives", "Dyflissu.Primitives\Dyflissu.Primitives.csproj", "{A62F8FC9-133F-4710-BFCC-899F49EE422B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network.MultiTarget", "..\submodules\lidgren-network-gen3\Lidgren.Network.MultiTarget\Lidgren.Network.MultiTarget.csproj", "{3F46F990-29F4-4DFC-AB52-AF9586773907}"
EndProject
Global
Expand All @@ -34,10 +32,6 @@ Global
{D0161D6B-B987-4D22-AC82-E136874EBBB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0161D6B-B987-4D22-AC82-E136874EBBB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0161D6B-B987-4D22-AC82-E136874EBBB0}.Release|Any CPU.Build.0 = Release|Any CPU
{A62F8FC9-133F-4710-BFCC-899F49EE422B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A62F8FC9-133F-4710-BFCC-899F49EE422B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A62F8FC9-133F-4710-BFCC-899F49EE422B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A62F8FC9-133F-4710-BFCC-899F49EE422B}.Release|Any CPU.Build.0 = Release|Any CPU
{3F46F990-29F4-4DFC-AB52-AF9586773907}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F46F990-29F4-4DFC-AB52-AF9586773907}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F46F990-29F4-4DFC-AB52-AF9586773907}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

0 comments on commit 0713e18

Please sign in to comment.