public override void Initialize(GnomicGame game) { Hud = ParentGame.GetScreen<HudScreen>(); int floorHeight = 60; Physics = new Gnomic.Physics.PhysicsSystem(this); Physics.CreateBorder(ParentGame.ScreenWidth * PLAY_AREA_WIDTH_IN_SCREENS, ParentGame.ScreenHeight, // * PLAY_AREA_HEIGHT_IN_SCREENS, new Vector2(0.0f, -floorHeight), /*friction*/ 0.005f); // Create a 2D camera base.Camera2D = camera = new Camera2D(ParentGame.GraphicsDevice.Viewport); CreateBackground(); Vector2 vehiclePos = new Vector2(ParentGame.ScreenWidth / 5, ParentGame.ScreenHeight - floorHeight); Vector2 vehicleSizePhysicsCoords = new Vector2(2.7f, 4.5f); Vector2 vehicleOffsetPhysicsCoords = new Vector2(0.0f, -vehicleSizePhysicsCoords.Y / 2.0f); Vector2 princessPos = vehiclePos - ConvertUnits.ToDisplayUnits(new Vector2(0.0f, vehicleSizePhysicsCoords.Y)); lilMissBadAss = Princess.CreatePrincess(princessPos, new Vector2(0.6f, 1.2f), new Vector2(0.0f, -0.6f)); base.AddEntity(lilMissBadAss); // sets ParentScreen Vehicle = PrincessVehicle.CreateDefaultEntity(vehiclePos, vehicleSizePhysicsCoords, vehicleOffsetPhysicsCoords); base.AddEntity(Vehicle); units = new UnitManager(this); //float startX = 0.7f; //for (int i = 0; i < 20; ++i) //{ // AddUnit(UnitType.Grunt, new Vector2(startX+(i*0.05f), 0.7f)); //} //startX = 0.4f; //for (int i = 0; i < 5; ++i) //{ // AddUnit(UnitType.Knight, new Vector2(startX + (i * 0.05f), 0.7f)); //} projectiles = new ProjectileManager(this); this.Audio = this.ParentGame.Audio; base.Initialize(game); standingJoint = new RevoluteJoint(lilMissBadAss.Physics.Bodies[0], Vehicle.Physics.Bodies[0], Vector2.Zero, new Vector2(0.0f, -vehicleSizePhysicsCoords.Y)); Physics.World.AddJoint(standingJoint); }
public virtual void Draw(SpriteBatch spriteBatch) { // Draw 3D groups if (DrawGroups.Count > 0) { // Set default states as using spritebatch can bork them GraphicsDevice dvc = parentGame.GraphicsDevice; dvc.SamplerStates[0] = SamplerState.LinearWrap; dvc.RasterizerState = RasterizerState.CullNone; dvc.BlendState = BlendState.AlphaBlend; dvc.DepthStencilState = DepthStencilState.Default; // Draw 3D buckets foreach (KeyValuePair <int, List <IDrawable3D> > kvp in DrawGroups) { // Call the group pre-draw if it exists if (PreDrawGroup != null) { PreDrawGroup(kvp.Key); } foreach (IDrawable3D drawable3D in kvp.Value) { if (drawable3D.IsVisible) { drawable3D.Draw3D(); } } // After the IDrawable3D objects have beend drawn, // call RenderBatch.Render() to flush any added triangles if (renderBatch != null && renderBatch.HasTriangles) { Debug.Assert(camera3D != null); Matrix view = camera3D.MatrixView; Matrix proj = camera3D.MatrixProj; renderBatch.Render(ref renderBatchWorldTransform, ref view, ref proj); renderBatch.Reset(); } // Call the group post-draw if it exists if (PostDrawGroup != null) { PostDrawGroup(kvp.Key); } } } // Draw 2D layers with SpriteBatch for (int i = Layers.Count - 1; i >= 0; --i) { Layer2D layer = Layers[i]; if (layer.Sprites.Count > 0) { if (Camera2D != null) { LastViewMatrix2D = Camera2D.GetViewMatrix(layer.Parallax); } spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, LastViewMatrix2D); foreach (IDrawable2D e in layer.Sprites) { if (e.IsVisible) { e.Draw2D(spriteBatch); } } spriteBatch.End(); } } if (Physics != null && Physics.DebugView != null && EnablePhysicsDebug) { float worldScale = ConvertUnits.ToSimUnits(1f); Matrix view = Camera2D.GetViewMatrix(new Vector2(worldScale)); Physics.RenderDebugView(ref view); } }