diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs
--- a/isometric-park-fna/FNAGame.cs
+++ b/isometric-park-fna/FNAGame.cs
@@ -11,45 +11,6 @@
using System.Diagnostics;
-struct Entity
-{
- public Vector2 loc;
- public Vector2 velocity;
-
- private Rectangle _boundingBox;
-
- public Rectangle BoundingBox
- {
-
- get
- {
- Rectangle calculatedRectangle = _boundingBox;
- calculatedRectangle.Location += new Point((int)loc.X, (int)loc.Y);
- return calculatedRectangle;
- }
- set { _boundingBox = value; }
- }
-
- public Entity(Vector2 loc, Vector2 velocity)
- {
- this.loc = loc;
- this.velocity = velocity;
- this._boundingBox = Rectangle.Empty;
- }
-
- public Entity(Vector2 loc, Vector2 velocity, Rectangle boundingBox)
- {
- this.loc = loc;
- this.velocity = velocity;
- this._boundingBox = boundingBox;
- }
-}
-
-//static class Camera
-//{
-// static public Vector2 Location = Vector2.Zero;
-//}
-
class FNAGame : Game
{
private KeyboardState keyboardPrev = new KeyboardState();
@@ -75,14 +36,6 @@
private const int height = 640;
- private Entity paddleEntity = new Entity(Vector2.Zero, Vector2.Zero,
- new Rectangle(36, 0, 20, 100));
- private Entity ballEntity = new Entity(new Vector2(height, 360),
- new Vector2(2.0f, 2.0f),
- new Rectangle(36, 36, 20, 20));
- private Entity aiPaddleEntity = new Entity(new Vector2(width - 100, 0), Vector2.Zero,
- new Rectangle(36, 0, 20, 100));
-
private const float friction = 0.1f;
private const float inputVelocityDelta = friction + 0.1f;
@@ -106,50 +59,6 @@
g.Run();
}
- public static bool Between(float val, float x, float y)
- {
- return ((x < val && val < y) || (y < val && val < x));
-
- }
-
- public Entity Move(ref Entity orig, bool score)
- {
- orig.loc += orig.velocity;
-
- if (orig.loc.Y <= 0 && orig.velocity.Y < 0)
- {
- orig.velocity.Y *= -1;
- orig.loc.Y = 0;
- }
- else if (orig.loc.Y >= (height) && orig.velocity.Y > 0)
- {
- orig.velocity.Y *= -1;
- orig.loc.Y = (720 - 100);
- }
-
- if (orig.loc.X <= 0 && orig.velocity.X < 0)
- {
- orig.velocity.X *= -1;
- orig.loc.X = 0;
-
- if (score)
- {
- playerScore += 1;
- }
- }
- else if (orig.loc.X >= width && orig.velocity.X > 0)
- {
- orig.velocity.X *= -1;
- orig.loc.X = width;
-
- if (score)
- {
- aiScore += 1;
- }
- }
-
- return orig;
- }
@@ -230,29 +139,6 @@
}
- protected float Decrement(float value, float delta)
- {
- float magnitude = Math.Abs(value);
-
- //If distance from zero is less than our delta,
- //go to zero to prevent overshooting:
- if (magnitude < delta)
- {
- return 0.0f;
- }
- else if (value > 0)
- {
- return value - delta;
- }
- else if (value < 0)
- {
- return value + delta;
- }
- else
- {
- return 0.0f;
- }
- }
protected override void Update(GameTime gameTime)
{
@@ -291,12 +177,12 @@
}
else if (keyboardCur.IsKeyDown(Keys.Subtract) && keyboardPrev.IsKeyUp(Keys.Subtract))
{
- this.camera.zoom -= 0.25f;
+ this.camera.zoom *= 0.75f;
}
else if (keyboardCur.IsKeyDown(Keys.Add) && keyboardPrev.IsKeyUp(Keys.Add))
{
- this.camera.zoom += 0.25f;
+ this.camera.zoom *= 1.25f;
}
@@ -319,21 +205,20 @@
MouseState mouseCur = Mouse.GetState();
- if ((mouseCur.X < 50) && (mouseCur.X > 0))
-
+ if (MathUtils.Between(mouseCur.X, 0, 50))
{
this.camera.Move(new Vector2(-4, 0));
}
- else if ((mouseCur.X > (FNAGame.width - 50)) && (mouseCur.X < FNAGame.width))
+ else if (MathUtils.Between(mouseCur.X, (FNAGame.width - 50), FNAGame.width))
{
this.camera.Move(new Vector2(4, 0));
}
- if ((mouseCur.Y < 50) && (mouseCur.Y > 0))
+ if (MathUtils.Between(mouseCur.Y, 0, 50))
{
this.camera.Move(new Vector2(0, -4));
}
- else if ((mouseCur.Y > (FNAGame.height - 50)) && (mouseCur.Y < FNAGame.height))
+ else if (MathUtils.Between(mouseCur.Y , (FNAGame.height - 50), FNAGame.height))
{
this.camera.Move(new Vector2(0, 4));
}
@@ -347,9 +232,6 @@
frameCounter = 0;
}
-
-
-
base.Update(gameTime);
@@ -515,7 +397,6 @@
batch.DrawString(font, this.drawTime.TotalMilliseconds.ToString(), new Vector2(120, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);
batch.DrawString(font, this.drawTime.TotalMilliseconds.ToString(), new Vector2(119, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f);
-
batch.DrawString(font, camera.position.ToString(), new Vector2(190, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);
batch.DrawString(font, camera.position.ToString(), new Vector2(189, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f);
diff --git a/isometric-park-fna/MathUtils.cs b/isometric-park-fna/MathUtils.cs
new file mode 100644
--- /dev/null
+++ b/isometric-park-fna/MathUtils.cs
@@ -0,0 +1,47 @@
+using System;
+namespace isometricparkfna
+{
+ public class MathUtils
+ {
+ public MathUtils()
+ {
+ }
+
+ public static bool Between(float val, float x, float y)
+ {
+ return ((x < val && val < y) || (y < val && val < x));
+
+ }
+
+ public static bool Between(int val, int x, int y)
+ {
+ return ((x < val && val < y) || (y < val && val < x));
+
+ }
+
+ protected float Decrement(float value, float delta)
+ {
+ float magnitude = Math.Abs(value);
+
+ //If distance from zero is less than our delta,
+ //go to zero to prevent overshooting:
+ if (magnitude < delta)
+ {
+ return 0.0f;
+ }
+ else if (value > 0)
+ {
+ return value - delta;
+ }
+ else if (value < 0)
+ {
+ return value + delta;
+ }
+ else
+ {
+ return 0.0f;
+ }
+ }
+
+ }
+}
diff --git a/isometric-park-fna/isometric-park-fna.csproj b/isometric-park-fna/isometric-park-fna.csproj
--- a/isometric-park-fna/isometric-park-fna.csproj
+++ b/isometric-park-fna/isometric-park-fna.csproj
@@ -33,6 +33,7 @@
+