/// <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() { // Initialize the player class player = new Player(); bgLayer1 = new ParallaxingBackground(); bgLayer2 = new ParallaxingBackground(); bgLayer3 = new ParallaxingBackground(); bgLayer4 = new ParallaxingBackground(); bearTraps = new BearTrap[MAX_TRAPS]; for (int bearTrapIndex = 0; bearTrapIndex < MAX_TRAPS; bearTrapIndex++) { bearTraps[bearTrapIndex] = new BearTrap(); } base.Initialize(); }
/// <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); // Load the player resources Animation playerAnimation = new Animation(); Texture2D playerTexture = Content.Load <Texture2D>("Images/BearWalk"); playerAnimation.Initialize(playerTexture, Vector2.Zero, 152, 95, 8, 48, Color.White, 1f, true); Vector2 playerPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X + playerTexture.Width / 6, GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.Height - playerTexture.Height * 0.75f); player.Initialize(Window, playerAnimation, playerPosition); // initialize all bear traps for (int bearTrapIndex = 0; bearTrapIndex < MAX_TRAPS; bearTrapIndex++) { Animation bearTrapAnimation = new Animation(); Texture2D bearTrapTexture = Content.Load <Texture2D>("Images/BearTrap"); bearTrapAnimation.Initialize(bearTrapTexture, Vector2.Zero, 104, 74, 1, 48, Color.White, 0.5f, true); Vector2 bearTrapPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X + GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.Height - bearTrapTexture.Height * 0.35f); bearTraps[bearTrapIndex] = new BearTrap(); bearTraps[bearTrapIndex].Initialize(Window, bearTrapAnimation, bearTrapPosition); bearTraps[bearTrapIndex].Active = false; bearTraps[bearTrapIndex].TrapCleared = false; } // Load the parallaxing background bgLayer1.Initialize(Content, "Images/Sky", GraphicsDevice.Viewport.Width, -1, 1.0f); bgLayer2.Initialize(Content, "Images/Mountain", GraphicsDevice.Viewport.Width, -2, 0.02f); bgLayer3.Initialize(Content, "Images/Ground", GraphicsDevice.Viewport.Width, -3, 0.15f); bgLayer4.Initialize(Content, "Images/Trees", GraphicsDevice.Viewport.Width, -4, 0.1f); // Load the score font font = Content.Load <SpriteFont>("ScoreFont"); }