Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: thedeeno/storm
base: 8f9e069e45
...
head fork: thedeeno/storm
compare: 4800e4d64c
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
79 StormGame/StormGame/Debris.cs
@@ -31,6 +31,10 @@ abstract class Debris
private Vector2 Velocity;
private float theta;
private const float WindAcceleration = 0.0003f;
+ private Vector2 Accel;
+ private bool wasHit;
+ private Vector2 _windForce;
+ private Vector2 _gravity;
public Rectangle BoundingBox { get; set; }
@@ -52,6 +56,7 @@ public void Initialize()
Weight = 10;
time = 0.0f;
RotationAngle = 0f;
+ wasHit = false;
Origin.X = Texture.Width / 2;
Origin.Y = Texture.Height / 2;
@@ -90,16 +95,29 @@ public void Collide()
{
if (CooldownReady)
{
- Cooldown = 1.5f;
- Speed *= 0.3f;
+ Cooldown = 0.5f;
CooldownReady = false;
time = 0;
+ wasHit = true;
}
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(Texture, Position, null, Color.White, RotationAngle, Origin, 1.0f, SpriteEffects.None, 0f);
+
+ Texture2D blank = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
+ blank.SetData(new[] { Color.White });
+ DrawLine(spriteBatch, blank, 1, Color.Red, Position, Position + _windForce);
+ DrawLine(spriteBatch, blank, 1, Color.Green, Position, Position + _gravity);
+ }
+
+ void DrawLine(SpriteBatch batch, Texture2D blank, float width, Color color, Vector2 point1, Vector2 point2)
+ {
+ float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
+ float length = Vector2.Distance(point1, point2);
+
+ batch.Draw(blank, point1, null, color, angle, Vector2.Zero, new Vector2(length, width), SpriteEffects.None, 0);
}
private void UpdateDamage()
@@ -107,17 +125,63 @@ private void UpdateDamage()
Damage = (int)Math.Ceiling((Speed*40) + (Weight / 4));
}
- public void Move(Vector2 center)
+ public void Move(Vector2 center, GameTime gameTime)
{
if (isOrbiting)
{
- Velocity = new Vector2((float)(radius * Math.Cos(theta)), (float)(radius * Math.Sin(theta)));
- Velocity += center;
- Position = Velocity;
- Position.Normalize();
+ //var windAccel = new Vector2((float)(radius * Math.Cos(theta)), (float)(radius * Math.Sin(theta)));
+ //Velocity += center;
+ //Position = Velocity;
+ //Position.Normalize();
+ const float MAX_VELOCITY = 10f;
+ const float MAX_ACCEL = 1f;
+
+ var a0 = Accel;
+ var v0 = Velocity;
+ var x0 = Position;
+
+ var deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
+ var distance = (center - Position);
+
+
+ _gravity = distance;
+ _gravity *= .4f;
+ _windForce = CalcWindForce(distance, 500f);
+
+ Accel = _gravity;
+ Accel += _windForce;
+
+ //if (Accel.Length() > MAX_ACCEL)
+ // Accel = a0;
+ Velocity += Accel * deltaTime;
+ Velocity = ApplyDrag(Velocity);
+ if (wasHit)
+ Velocity *= 0.1f;
+ if (Velocity.Length() > MAX_VELOCITY)
+ Velocity = v0;
+
+ Position += Velocity;
+ wasHit = false;
}
}
+ public Vector2 ApplyDrag(Vector2 velocity)
+ {
+ var drag = new Vector2(0.95f);
+ return velocity *= drag;
+ }
+
+ public Vector2 CalcWindForce(Vector2 distance, float windMagnitude)
+ {
+ var x = distance.X;
+ var y = distance.Y;
+ var a1 = (float)Math.Atan2((float)distance.X, (float)distance.Y);
+ var windAngle = a1 + MathHelper.ToRadians(90);
+
+ var windForce = new Vector2((float)Math.Sin(windAngle) * windMagnitude, (float)Math.Cos(windAngle) * windMagnitude);
+ return windForce / distance.Length();
+ }
+
public void StartOrbiting()
{
Random rand = new Random();
@@ -125,6 +189,5 @@ public void StartOrbiting()
isOrbiting = true;
radius = rand.Next(25) + 30;
}
-
}
}
View
2  StormGame/StormGame/Game1.cs
@@ -57,7 +57,7 @@ protected override void LoadContent()
Globals.Font1 = _font;
Globals.SpriteBatch = spriteBatch;
Globals.Content = Content;
-
+ Globals.GraphicsDevice = GraphicsDevice;
level1.LoadContent(Content);
View
1  StormGame/StormGame/Globals.cs
@@ -14,5 +14,6 @@ static class Globals
//public static GameTime gameTime { get; set; }
public static SpriteBatch SpriteBatch { get; set; }
public static ContentManager Content { get; set; }
+ public static GraphicsDevice GraphicsDevice { get; set; }
}
}
View
6 StormGame/StormGame/Level.cs
@@ -41,12 +41,12 @@ public void LoadContent(ContentManager Content)
destructibles.Add(medbdg6);
StartingDebris = new LargeDebris();
- StartingDebris.Position = new Vector2(0, 0);
+ StartingDebris.Position = new Vector2(250, 100);
debris.Add(StartingDebris);
StartingDebris.StartOrbiting();
Debris d1 = new LargeDebris();
- d1.Position = new Vector2(400, 350);
+ d1.Position = new Vector2(200, 400);
debris.Add(d1);
//Debris d2 = new LargeDebris();
@@ -94,7 +94,7 @@ private void UpdateDebris(List<Destructible> listofDestros, GameTime gameTime)
{
deb.Update(gameTime, storm);
- deb.Move(storm.GetCenter());
+ deb.Move(storm.GetCenter(), gameTime);
foreach (Destructible destructible in listofDestros)
{
if (destructible.CheckCollision(deb.BoundingBox) && deb.CooldownReady)
View
2  StormGame/StormGame/Storm.cs
@@ -29,7 +29,7 @@ public Storm(ContentManager Content)
imageTexture = Content.Load<Texture2D>("Circle");
BoundingBox = new Rectangle(100, 100, imageTexture.Width, imageTexture.Height);
- Position = new Vector2(100, 100);
+ Position = new Vector2(200, 200);
}
View
2  StormGame/StormGame/StormGame.csproj.Debug.cachefile
@@ -1,7 +1,7 @@
Content\DefaultFont.xnb
+Content\DamagePopupFont.xnb
Content\Circle.xnb
Content\MedBldgDead.xnb
Content\MedBldgGood.xnb
Content\MedBldgPoor.xnb
Content\debris1.xnb
-Content\DamagePopupFont.xnb

No commit comments for this range

Something went wrong with that request. Please try again.