public override void LoadContent() { DebugDraw = true; primitiveBatch = new PrimitiveBatch(ScreenManager.GraphicsDevice); if (content == null) { content = new ContentManager(ScreenManager.Game.Services, "Content"); } gameFont = content.Load <SpriteFont>("Fonts/gamefont"); background = content.Load <Texture2D>("Textures/background"); Vector2 gravity = new Vector2(0, 0.0f); physWorld = new World(gravity, true); units = new Dictionary <string, DrawableGameComponent>(4); LoadLevel(); CreateBorders(); units.Add("Player", new Chip(this, new Vector2(0.5f, 0.4f), 0.07f, 1.0f, 0.6f, 0.5f, content.Load <Texture2D>("Textures/Circle"), content.Load <SoundEffect>("Sounds/Hit"))); units.Add("Player2", new Chip(this, new Vector2(0.6f, 0.7f), 0.07f, 1.0f, 0.6f, 0.5f, content.Load <Texture2D>("Textures/Ball"), content.Load <SoundEffect>("Sounds/Hit"))); camera = new Camera(this, new Rectangle(0, 0, 480, 800), (units["Player"] as Chip), new Vector2(1.0f, 1.0f)); // A real game would probably have more content than this sample, so // it would take longer to load. We simulate that by delaying for a // while, giving you a chance to admire the beautiful loading screen. Thread.Sleep(1000); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); }
public void Draw(GameTime gameTime, Camera camera) { Vector2 dif = this.Fixture.GetBody().Position - camera.Target.fixture.GetBody().Position; dif.X *= 480 * camera.Scale.X; dif.Y *= 480 * camera.Scale.Y; Vector2 pos = camera.DrawCenter + dif; Vector2 Center = camera.Target.fixture.GetBody().Position; float coef = GameWorld.ScreenManager.GraphicsDevice.Viewport.Width; Rectangle targetRect = new Rectangle( (int)Math.Round(pos.X), (int)Math.Round(pos.Y), (int)Math.Round(width * 480 * camera.Scale.X), (int)Math.Round(height * 480 * camera.Scale.Y)); if (GameWorld.DebugDraw) { //Matrix.CreateTranslation() PrimitiveBatch.Begin(PrimitiveType.TriangleList); PrimitiveBatch.AddVertex(new Vector2(targetRect.X - targetRect.Width / 2, targetRect.Y - targetRect.Height / 2), Color.Green); PrimitiveBatch.AddVertex(new Vector2(targetRect.X + targetRect.Width / 2, targetRect.Y - targetRect.Height / 2), Color.Green); PrimitiveBatch.AddVertex(new Vector2(targetRect.X + targetRect.Width / 2, targetRect.Y + targetRect.Height / 2), Color.Green); PrimitiveBatch.AddVertex(new Vector2(targetRect.X + targetRect.Width / 2, targetRect.Y + targetRect.Height / 2), Color.Green); PrimitiveBatch.AddVertex(new Vector2(targetRect.X - targetRect.Width / 2, targetRect.Y + targetRect.Height / 2), Color.Green); PrimitiveBatch.AddVertex(new Vector2(targetRect.X - targetRect.Width / 2, targetRect.Y - targetRect.Height / 2), Color.Green); PrimitiveBatch.End(); } else { if (Texture != null) { SpriteBatch.Draw(Texture, targetRect, null, Color.White, Fixture.GetBody().Rotation, textureCenter, SpriteEffects.None, 0); } } Draw(gameTime); }