/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { rand = new Random(); Units = new ArrayList(); //for (int i = 0; i < 10; i++) // Units.Add(new Debris(new Vector2(rand.Next((int)screen.X), rand.Next((int)screen.Y)), 15 + rand.Next(10), 7780)); BaseUnit u; for (int j = 1; j <= 10; j++) { for (int i = 1; i <= 10; i++) { u = new Debris(new Vector2(i * screen.X / 12, j * screen.Y / 12), 10 + rand.Next(20), 1); u.Velocity = new Vector2(rand.Next(20) - 10, rand.Next(20) - 10); Units.Add(u); } } /*u = new Debris(new Vector2(600, 300), 20, 1); * u.Velocity = new Vector2(-40, 0); * u.Spin = 10; * Units.Add(u); * u = new Debris(new Vector2(200, 300), 50, 1); * u.Velocity = new Vector2(40, 0); * u.Spin = 0; * Units.Add(u);*/ BaseUnit.Init(screen); base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { rand = new Random(); Units = new ArrayList(); //for (int i = 0; i < 10; i++) // Units.Add(new Debris(new Vector2(rand.Next((int)screen.X), rand.Next((int)screen.Y)), 15 + rand.Next(10), 7780)); BaseUnit u; for(int j = 1; j <= 10; j++) for (int i = 1; i <= 10; i++) { u = new Debris(new Vector2(i * screen.X / 12, j * screen.Y / 12), 10 + rand.Next(20), 1); u.Velocity = new Vector2(rand.Next(20) - 10, rand.Next(20) - 10); Units.Add(u); } /*u = new Debris(new Vector2(600, 300), 20, 1); u.Velocity = new Vector2(-40, 0); u.Spin = 10; Units.Add(u); u = new Debris(new Vector2(200, 300), 50, 1); u.Velocity = new Vector2(40, 0); u.Spin = 0; Units.Add(u);*/ BaseUnit.Init(screen); base.Initialize(); }
public void Collision(Debris other) { if (other == this) { return; } float compression = Bounding + other.Bounding - Vector2.Distance(Position, other.Position); if (compression <= 0) { return; } Vector2 fromOther = Vector2.Normalize(Position - other.Position); float force = compression * (spring * other.spring) / (spring + other.spring); Vector2 forceDif = fromOther * force; Acceleration += forceDif / Mass; other.Acceleration -= forceDif / other.Mass; float angle = Calc.Angle(Velocity, -fromOther); float spn = Spin * radius + Velocity.Length() * (float)Math.Sin(angle); float oangle = Calc.Angle(other.Velocity, fromOther); float ospn = other.Spin * other.radius + other.Velocity.Length() * (float)Math.Sin(oangle); float torqueDif = Calc.Sign(ospn - spn) * (friction + other.friction) * force; AngAccel += torqueDif / mI; other.AngAccel += torqueDif / other.mI; }
public void Collision(Debris other) { if (other == this) return; float compression = Bounding + other.Bounding - Vector2.Distance(Position, other.Position); if (compression <= 0) return; Vector2 fromOther = Vector2.Normalize(Position - other.Position); float force = compression * (spring * other.spring) / (spring + other.spring); Vector2 forceDif = fromOther * force; Acceleration += forceDif / Mass; other.Acceleration -= forceDif / other.Mass; float angle = Calc.Angle(Velocity, -fromOther); float spn = Spin * radius + Velocity.Length() * (float)Math.Sin(angle); float oangle = Calc.Angle(other.Velocity, fromOther); float ospn = other.Spin * other.radius + other.Velocity.Length() * (float)Math.Sin(oangle); float torqueDif = Calc.Sign(ospn - spn) * (friction + other.friction) * force; AngAccel += torqueDif / mI; other.AngAccel += torqueDif / other.mI; }