/// <summary> /// Spawn a crate at a random position at the top of the screen /// </summary> private void SpawnCrate() { DrawablePhysicsObject crate; crate = new DrawablePhysicsObject(world, Content.Load<Texture2D>("White"), new Vector2(1.0f, 1.0f), 0.1f); crate.Position = new Vector2(playerObj.Position.X, playerObj.Position.Y); if (playerObj.Facing == "right") { Vector2 targetPos = new Vector2(playerObj.Position.X + 100, random.Next(0, GraphicsDevice.Viewport.Height)); } crateList.Add(crate); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); random = new Random(); pList = new List<PhysicsParticleObject>(); cam.Pos = new Vector2(500.0f, 200.0f); // World is the most important farseer object. It's where // all the objects should be registered and it handles the // entire simulation via the step function. // Here we instantiate it with earth like gravity world = new World(new Vector2(0, 9.8f)); floorTexture = Content.Load<Texture2D>("floor"); floor = new DrawablePhysicsObject(world, floorTexture, new Vector2(GraphicsDevice.Viewport.Width, floorTexture.Height), 1000); floor.Position = new Vector2(GraphicsDevice.Viewport.Width / 2.0f, GraphicsDevice.Viewport.Height - 50); floor.body.BodyType = BodyType.Static; wall = new DrawablePhysicsObject(world, floorTexture, new Vector2(floorTexture.Width, floorTexture.Height), 1000); wall.Position = new Vector2(GraphicsDevice.Viewport.Width / 2.0f, GraphicsDevice.Viewport.Height - 400); wall.body.FixedRotation = true; wall.body.Rotation = 15.5f; wall.body.BodyType = BodyType.Static; platform = new DrawablePhysicsObject(world, floorTexture, new Vector2(GraphicsDevice.Viewport.Width/2, floorTexture.Height), 1000); platform.Position = new Vector2(GraphicsDevice.Viewport.Width / 2.0f, GraphicsDevice.Viewport.Height / 2); platform.body.BodyType = BodyType.Static; player = new DrawablePhysicsObject(world,null, new Vector2(36.0f, 48.0f), 1000); // player = BodyFactory.CreateRectangle(world, 36*pixelToUnit, 48*pixelToUnit, 1f); player.Position = new Vector2(200.0f, 100.0f); // player.body.body.Rotation = 90; player.body.BodyType = BodyType.Dynamic; player.body.Friction = playerFriction; crateList = new List<DrawablePhysicsObject>(); prevKeyboardState = Keyboard.GetState(); Animation playerAnimation = new Animation(); Texture2D playerTexture = Content.Load<Texture2D>("shipAnimation"); Texture2D spriteTexture = Content.Load<Texture2D>("jasperrun"); playerAnimation.Initialize(spriteTexture, new Vector2(0, 0), 32, 48, 4, 100, Color.White, 1f, true); // playerAnimation.Initialize(playerTexture, new Vector2(0, 0), 115, 69, 8, 30, Color.White, 1f, true); playerObj.Initialize(playerAnimation, new Vector2(player.Position.X, player.Position.Y)); List<Texture2D> textures = new List<Texture2D>(); textures.Add(Content.Load<Texture2D>("white")); white = Content.Load<Texture2D>("white"); particleEngine = new ParticleEngine(textures, new Vector2(playerObj.Position.X, playerObj.Position.Y), world); // TODO: use this.Content to load your game content here }