void frame_KeyPressDown(Element sender, KeyEventArgs e) { switch (e.InterestingKeys[0]) { case Keys.G: gactive = !gactive; if (gactive) { PhysicsManager.AddUniversalForce(DefaultForces.Gravity); } else { PhysicsManager.RemoveUniversalForce(DefaultForces.Gravity); } break; case Keys.X: var br = new BombRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), winSize.Height), 25); br.Mass = 100; br.Velocity = -1000 * Vector2.UnitY; br.FuseTime = .1f; ActiveMap.AddObject(br); PhysicsManager.ActiveBodies.Add(br); break; case Keys.C: var gr = new InertRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), winSize.Height), 25); gr.Mass = 100; gr.Velocity = -1000 * Vector2.UnitY; ActiveMap.AddObject(gr); PhysicsManager.ActiveBodies.Add(gr); break; case Keys.OemPeriod: draw = !draw; break; case Keys.Space: break; } }
public override void Update(GameTime time) { if (!UIManager.Update(time)) { base.Exit(); } ActiveMap.UpdateDynamicObjects(time); PhysicsManager.Update(time.ElapsedGameTime.Milliseconds / 1000f); if (!time.IsRunningSlowly) { dint -= time.ElapsedGameTime.Milliseconds / 1000f; if (dint <= 0.0f) { dynamic obj; if (MathUtils.Rand.Next(0, 2) == 0) { obj = new BombRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), (float)MathUtils.Rand.Next(60, (int)winSize.Height - 60)), MathUtils.Rand.Next(2, 10)); } else { obj = new InertRoid(new Vector2((float)MathUtils.Rand.Next(60, (int)winSize.Width - 60), (float)MathUtils.Rand.Next(60, (int)winSize.Height - 60)), MathUtils.Rand.Next(2, 10)); } obj.Velocity = 1000 * (float)MathUtils.Rand.NextDouble() * MathUtils.RandDirection(); PhysicsManager.ActiveBodies.Add(obj); ActiveMap.AddObject(obj); Console.WriteLine(PhysicsManager.ActiveBodies.Count.ToString() + " bodies"); dint = delay; } } else { Console.Write(PhysicsManager.ActiveBodies.Count.ToString() + " bodies "); Console.WriteLine("SLOW - HIT PERIOD TO DISABLE GRFX"); dint = 0.0f; } }
public override void Reload() { winSize = DefaultSettings.Settings["WindowSize"]; PhysicsManager = new PhysicsEngine(new Region(0, (float)winSize.Width, 0, (float)winSize.Height), 10); PhysicsManager.AddUniversalForce(DefaultForces.LinearDrag); //PhysicsManager.AddUniversalForce(DefaultForces.Gravity); int maxAstroids = 10; var world = new List <WorldObject>(); Random rand = new Random(); var player = new Player( new Vector2((float)rand.NextDouble() * (winSize.Width - 50), (float)rand.NextDouble() * (winSize.Height - 50)), 0f); world.Add(player); PhysicsManager.ActiveBodies.Add(player); int nx = 30; int ny = 30; var rad = 4f; var buf = 2f; var pos = new Vector2(winSize.Width / 2 - nx * (2f * rad + buf) / 2f, winSize.Height / 2 - ny * (2f * rad + buf) / 2f); for (int xi = 0; xi < nx; xi++) { for (int yi = 0; yi < ny; yi++) { var pert = 0.1f * buf * (float)MathUtils.Rand.NextDouble() * MathUtils.RandDirection(); //minor perturbation from perfect grid. var cent = pos + new Vector2((2f * rad + buf) * xi, (2f * rad + buf) * yi) + pert; var obs = new InertRoid(cent, rad); world.Add(obs); PhysicsManager.ActiveBodies.Add(obs); } } ActiveMap = new Map(world); // Create map from world // Walls -- invisible var w0 = new ROIDS.Sandbox.VertWallBody(new Vector2(0, winSize.Height / 2), winSize.Height); var w1 = new ROIDS.Sandbox.VertWallBody(new Vector2(winSize.Width, winSize.Height / 2), winSize.Height); var w2 = new ROIDS.Sandbox.HorizWallBody(new Vector2(winSize.Width / 2, 0), winSize.Width); var w3 = new ROIDS.Sandbox.HorizWallBody(new Vector2(winSize.Width / 2, winSize.Height), winSize.Width); PhysicsManager.MapBodies.Add(w0); PhysicsManager.MapBodies.Add(w1); PhysicsManager.MapBodies.Add(w2); PhysicsManager.MapBodies.Add(w3); // Console.WriteLine("CONTROLS:"); Console.WriteLine("[LCLICK] - trigger explosion"); Console.WriteLine("[RCLICK] - infect area"); }