private void GenerateLevel() { XLiveStartupForm form = new XLiveStartupForm(this.manager); form.Show(); circleSprite = Content.Load<Texture2D>("playerBallSprite"); // Circle // Convert screen centre from pixels to meters circlePosition = (screenCenter / MeterInPixels) + new Vector2(0, -1.5f); // Create the circle fixture playerBallBody = BodyFactory.CreateCircle(world, 96f / (2f * MeterInPixels), 1f, circlePosition); playerBallBody.BodyType = BodyType.Dynamic; // Ball bounce and friction playerBallBody.Restitution = 0.3f; playerBallBody.Friction = 0.5f; // First piece of ground groundPosition = (screenCenter / MeterInPixels) + new Vector2(0f, 1.25f); groundBody = BodyFactory.CreateRectangle(world, 380f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); groundBody.IsStatic = true; groundBody.Restitution = 0.3f; groundBody.Friction = 0.5f; // Add it to the list worldObjects.Add(new WorldObject(Content.Load<Texture2D>("groundSprite"), groundBody, groundPosition)); // First obstacle obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(3.7f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); obstacleBody.IsStatic = true; obstacleBody.Restitution = 0.3f; obstacleBody.Friction = 0.5f; // Add it to the list worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite2"), obstacleBody, obstaclePosition)); // Right arrow above starting point arrowPosition = (screenCenter / MeterInPixels) + new Vector2(0f, -3.3f); arrowBody = BodyFactory.CreateRectangle(world, 117f / MeterInPixels, 73f / MeterInPixels, 1f, arrowPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("arrow_right"), arrowBody, arrowPosition)); // The rest of the obstacles & ground: groundPosition = (screenCenter / MeterInPixels) + new Vector2(-3.0f, -5.0f); groundBody = BodyFactory.CreateRectangle(world, 4f / MeterInPixels, 800f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("medWallSprite"), groundBody, groundPosition)); groundPosition = (screenCenter / MeterInPixels) + new Vector2(7.4f, 1.25f); groundBody = BodyFactory.CreateRectangle(world, 380f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("groundSprite"), groundBody, groundPosition)); // First staircase obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(11.1f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(12.5f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(12.5f, -0.78f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); groundPosition = (screenCenter / MeterInPixels) + new Vector2(16.2f, 1.25f); groundBody = BodyFactory.CreateRectangle(world, 380f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("groundSprite"), groundBody, groundPosition)); // Second staircase obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(19.9f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(21.3f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(21.3f, -0.78f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(22.7f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(22.7f, -0.78f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(22.7f, -2.14f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); groundPosition = (screenCenter / MeterInPixels) + new Vector2(26.4f, 1.25f); groundBody = BodyFactory.CreateRectangle(world, 380f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("groundSprite"), groundBody, groundPosition)); // Final staircase obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(30.1f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(31.5f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(31.5f, -0.78f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(32.9f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(32.9f, -0.78f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(32.9f, -2.14f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(34.3f, 0.58f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(34.3f, -0.78f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(34.3f, -2.14f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(34.3f, -3.5f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); // Ground after staircase groundPosition = (screenCenter / MeterInPixels) + new Vector2(38f, 1.25f); groundBody = BodyFactory.CreateRectangle(world, 380f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("groundSprite"), groundBody, groundPosition)); // Down arrows arrowPosition = (screenCenter / MeterInPixels) + new Vector2(48f, -3.0f); arrowBody = BodyFactory.CreateRectangle(world, 73f / MeterInPixels, 117f / MeterInPixels, 1f, arrowPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("arrow_down"), arrowBody, arrowPosition)); // Far wall groundPosition = (screenCenter / MeterInPixels) + new Vector2(50f, 2f); groundBody = BodyFactory.CreateRectangle(world, 4f / MeterInPixels, 1700f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("largeWallSprite"), groundBody, groundPosition)); // First lower ground groundPosition = (screenCenter / MeterInPixels) + new Vector2(47f, 15.35f); groundBody = BodyFactory.CreateRectangle(world, 380f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("groundSprite"), groundBody, groundPosition)); groundPosition = (screenCenter / MeterInPixels) + new Vector2(41.1f, 15.35f); groundBody = BodyFactory.CreateRectangle(world, 380f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("groundSprite"), groundBody, groundPosition)); groundPosition = (screenCenter / MeterInPixels) + new Vector2(35.2f, 15.35f); groundBody = BodyFactory.CreateRectangle(world, 380f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("groundSprite"), groundBody, groundPosition)); // First lower obstacle obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(31.7f, 14.68f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); groundPosition = (screenCenter / MeterInPixels) + new Vector2(31f, 11.3f); groundBody = BodyFactory.CreateRectangle(world, 4f / MeterInPixels, 498f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("smallWallSprite"), groundBody, groundPosition)); groundPosition = (screenCenter / MeterInPixels) + new Vector2(36f, 7.0f); groundBody = BodyFactory.CreateRectangle(world, 4f / MeterInPixels, 672f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("smallWallSprite2"), groundBody, groundPosition)); groundPosition = (screenCenter / MeterInPixels) + new Vector2(34.5f, 12f); groundBody = BodyFactory.CreateRectangle(world, 175f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("hangingGroundSprite2"), groundBody, groundPosition)); obstaclePosition = (screenCenter / MeterInPixels) + new Vector2(35.3f, 11.3f); obstacleBody = BodyFactory.CreateRectangle(world, 96f / MeterInPixels, 96f / MeterInPixels, 1f, obstaclePosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("obstacleSprite"), obstacleBody, obstaclePosition)); groundPosition = (screenCenter / MeterInPixels) + new Vector2(32f, 9.4f); groundBody = BodyFactory.CreateRectangle(world, 175f / MeterInPixels, 4f / MeterInPixels, 1f, groundPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("hangingGroundSprite2"), groundBody, groundPosition)); arrowPosition = (screenCenter / MeterInPixels) + new Vector2(28f, 7.4f); arrowBody = BodyFactory.CreateRectangle(world, 73f / MeterInPixels, 117f / MeterInPixels, 1f, arrowPosition); worldObjects.Add(new WorldObject(Content.Load<Texture2D>("arrow_down"), arrowBody, arrowPosition)); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Initialize camera controls view = Matrix.Identity; cameraPosition = Vector2.Zero; screenCenter = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2f, graphics.GraphicsDevice.Viewport.Height / 2f); spriteBatch = new SpriteBatch(graphics.GraphicsDevice); XLiveStartupForm form = new XLiveStartupForm(this.manager); form.Show(); // SpriteFont //DisplayedTime = Content.Load<SpriteFont>("DisplayedTime"); world.ContactManager.OnBroadphaseCollision += OnBroadphaseCollision; // Generate the level to be played GenerateLevel(); tScore = TimeSpan.FromMilliseconds(1); StartAccelerometer(); }