public static GameObject CreateCircleGameObject(PhysicsSimulator simulator, string resourceName, float rad, float mass) { var go = new GameObject(); go.Body = BodyFactory.Instance.CreateCircleBody(rad, mass); go.Geom = GeomFactory.Instance.CreateCircleGeom(simulator, go.Body, rad, 20); go.ResourceName = resourceName; simulator.Add(go.Body); simulator.Add(go.Geom); return go; }
public static GameObject CreateRectangleGameObject(PhysicsSimulator simulator, string resourceName, float width, float height, float mass) { var go = new GameObject(); go.ResourceName = resourceName; go.Body = BodyFactory.Instance.CreateRectangleBody(width,height, mass); go.Geom = GeomFactory.Instance.CreateRectangleGeom(simulator,go.Body, width, height); simulator.Add(go.Body); simulator.Add(go.Geom); return go; }
/// <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() { graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 600; graphics.SynchronizeWithVerticalRetrace = false; graphics.ApplyChanges(); assets = new Dictionary<string, Texture2D>(); gameObjects = new List<GameObject>(); phySim = new PhysicsSimulator(new Vector2(0, -200)); var ballObject = GameObjectFactory.CreateCircleGameObject(phySim, "ball", 22f, 1); ballObject.Center = new Vector2(250, 400); ballObject.Geom.FrictionCoefficient = 0; FixedAngleJoint asdf = new FixedAngleJoint(ballObject.Body, 0); phySim.Add(asdf); player = ballObject; gameObjects.Add(ballObject); var platformObject = GameObjectFactory.CreateRectangleGameObject(phySim, "platform", 256, 64, 6); platformObject.IsStatic = true; platformObject.Center = new Vector2(250, 300); platformObject.Rotation = MathHelper.ToRadians(-30f); var platformObject2 = GameObjectFactory.CreateRectangleGameObject(phySim, "platform", 256, 64, 6); platformObject2.Center = new Vector2(5, 150); platformObject2.Rotation = MathHelper.ToRadians(90f); platformObject2.Geom.FrictionCoefficient = 10; var floorObject = GameObjectFactory.CreateRectangleGameObject(phySim, "floor", 1024, 12, 1); floorObject.Center = new Vector2(500, 0); floorObject.IsStatic = true; floorObject.Geom.FrictionCoefficient = 1; camera = new Camera2d(new Vector2(0, 0), new Vector2(800, 600), new Vector2(100, 100)); gameObjects.Add(floorObject); gameObjects.Add(platformObject2); gameObjects.Add(platformObject); base.Initialize(); }