Skip to content

Commit

Permalink
close?
Browse files Browse the repository at this point in the history
  • Loading branch information
thedeeno committed Mar 18, 2012
1 parent 1589b0b commit 95b6b34
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
58 changes: 51 additions & 7 deletions StormGame/StormGame/Debris.cs
Expand Up @@ -33,6 +33,8 @@ abstract class Debris
private const float WindAcceleration = 0.0003f;
private Vector2 Accel;
private bool wasHit;
private Vector2 _windForce;
private Vector2 _gravity;

public Rectangle BoundingBox { get; set; }

Expand Down Expand Up @@ -103,6 +105,19 @@ public void Collide()
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()
Expand All @@ -114,7 +129,7 @@ public void Move(Vector2 center, GameTime gameTime)
{
if (isOrbiting)
{
//Velocity = new Vector2((float)(radius * Math.Cos(theta)), (float)(radius * Math.Sin(theta)));
//var windAccel = new Vector2((float)(radius * Math.Cos(theta)), (float)(radius * Math.Sin(theta)));
//Velocity += center;
//Position = Velocity;
//Position.Normalize();
Expand All @@ -128,27 +143,57 @@ public void Move(Vector2 center, GameTime gameTime)
var deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
var distance = (center - Position);



Accel = distance*.5f;

_gravity = distance * .5f;
//Accel = _gravity;
//var repulse = distance * -1 * .1f;

//if (distance.Length() < radius)
//{
// var temp = 1f - (distance.Length() / radius);
// Accel += -Accel * (float)temp;
//}
_windForce = CalcWindForce(distance, 100);
//Accel += wind;
//Accel
//Accel += repulse;

//if (Accel.Length() > MAX_ACCEL)
// Accel = a0;
//Velocity += _windForce;
Velocity += Accel * deltaTime;
Velocity = ApplyDrag(Velocity);
if (wasHit)
Velocity *= 0.3f;
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)
{
// Vector2 windForce;
//var xlength = storm.X - debrie.X;
//var ylength = storm.Y - debrie.Y;
var a1 = (float)Math.Atan((float)distance.X /(float)distance.Y);
var windAngle = a1;
//a1 = MathHelper.ToDegrees(a1);
//var step = Math.Pow(distance.Y, 2) / Math.Pow(distance.Length(), 2);
//var a2 = 90f - a1;

//windForce = new Vector2((float)Math.Sin(MathHelper.ToRadians(a2)) * windMagnitude, (float)Math.Cos(MathHelper.ToRadians(a2)) * windMagnitude);
var windForce = new Vector2((float)Math.Sin(windAngle) * 10f, (float)Math.Cos(windAngle) * 10f);
return windForce;
}

public void StartOrbiting()
Expand All @@ -158,6 +203,5 @@ public void StartOrbiting()
isOrbiting = true;
radius = rand.Next(25) + 30;
}

}
}
4 changes: 2 additions & 2 deletions StormGame/StormGame/Level.cs
Expand Up @@ -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, 200);
d1.Position = new Vector2(200, 400);
debris.Add(d1);

//Debris d2 = new LargeDebris();
Expand Down

0 comments on commit 95b6b34

Please sign in to comment.