Exemple #1
0
        /// <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);

            // TODO: use this.Content to load your game content here
            background = new graphic2d(Content, "Background for Menus", displaywidth, displayheight);
            mousepointer1 = new sprite2d(Content, "X-Games-Cursor", 0, 0, 0.15f, Color.White, true);
            mousepointer2 = new sprite2d(Content, "X-Games-Cursor-Highlight", 0, 0, 0.15f, Color.White, true);

            menuoptions[0, 0] = new sprite2d(Content, "Start-Normal", displaywidth / 2, 100, 1, Color.White, true);
            menuoptions[0, 1] = new sprite2d(Content, "Start-Selected", displaywidth / 2, 100, 1, Color.White, true);
            menuoptions[1, 0] = new sprite2d(Content, "Options-Normal", displaywidth / 2, 200, 1, Color.White, true);
            menuoptions[1, 1] = new sprite2d(Content, "Options-Selected", displaywidth / 2, 200, 1, Color.White, true);
            menuoptions[2, 0] = new sprite2d(Content, "High-Score-Normal", displaywidth / 2, 300, 1, Color.White, true);
            menuoptions[2, 1] = new sprite2d(Content, "High-Score-Selected", displaywidth / 2, 300, 1, Color.White, true);
            menuoptions[3, 0] = new sprite2d(Content, "Exit-Normal", displaywidth / 2, 400, 1, Color.White, true);
            menuoptions[3, 1] = new sprite2d(Content, "Exit-Selected", displaywidth / 2, 400, 1, Color.White, true);
            for (int i = 0; i < numberofoptions; i++)
            {
                menuoptions[i, 0].updateobject();
            }

            backgscroll = new scrollingbackground2(Content, "skypan", 4f, 6, 1);
            backgscroll.image[1, 0] = Content.Load<Texture2D>("skypan2");
               // backgscroll.image[2, 0] = Content.Load<Texture2D>("skypan2");
              //  backgscroll.image[5, 0] = Content.Load<Texture2D>("skypan2");
            backgscroll.makehorizontal(displayheight);
            mainfont = Content.Load<SpriteFont>("quartz4"); // Load font

            // Initialise game character, setting position, friction and gravity
            cutedude = new animatedsprite(new Vector3(50, 300, 0), 0.95f, 2f, 1f, 4);
            //            cutedude.spriteanimation[0] = new animation(Content, "superguy1", 100, 100, 2f, Color.White, true, 6, 1, 4, true);
            //          cutedude.spriteanimation[1] = new animation(Content, "superguy2", 100, 100, 2f, Color.White, true, 6, 1, 4, true);
            cutedude.spriteanimation[0] = new animation(Content, "cuteman", 100, 100, 0.8f, Color.White, true, 6, 1, 4, true,false);
            cutedude.spriteanimation[1] = new animation(Content, "cuteman2", 100, 100, 0.8f, Color.White, true, 6, 1, 4, true, true);
            cutedude.spriteanimation[2] = new animation(Content, "cutejump", 100, 100, 0.8f, Color.White, true, 14, 1, 7, false, false);
            cutedude.spriteanimation[3] = new animation(Content, "cutejump2", 100, 100, 0.8f, Color.White, true, 14, 1, 7, false,true);

            hitsound = Content.Load<SoundEffect>("ballhit");

            // Values for sonic type game
            //cutedude = new animatedsprite(new Vector3(300, 300, 0), 0.995f, 1.5f, 2f);
            //cutedude.running = new animation(Content, "sonic", 100, 100, 1f, Color.White, true, 24, 1, 4);

            // cutedude = new animatedsprite(new Vector3(300, 300, 0), 0.95f, 1f);
            // cutedude.running = new animation(Content, "dragon", 100, 100, 1f, Color.White, true, 24, 4, 3);

            // Load the platforms and position them
            platform[0] = new sprite2d(Content, "BRICK_blue", 450, 350, 1, Color.White, true);
            for (int i = 1; i < numberofplatforms; i++)
                platform[i] = new sprite2d(Content, "BRICK_blue", 500 + (i * platform[0].rect.Width), 250, 1, Color.White, true);
            for (int i = 11; i < numberofplatforms; i++)
                platform[i] = new sprite2d(Content, "BRICK_blue", 500 + (i * platform[0].rect.Width), 350, 1, Color.White, true);

            platform[8] = new sprite2d(Content, "BRICK_green", (int)platform[8].position.X, (int)(platform[8].position.Y - 150), 1f, Color.White, true);
            platform[9] = new sprite2d(Content, "BRICK_green", (int)platform[9].position.X, (int)(platform[9].position.Y - 150), 1f, Color.White, true);
            platform[10] = new sprite2d(Content, "BRICK_green", (int)platform[16].position.X, (int)(platform[16].position.Y - platform[16].rect.Height), 1f, Color.White, true);
            platform[18] = new sprite2d(Content, "BRICK_green", 3100, 420, 3f, Color.White, true);
            platform[19] = new sprite2d(Content, "BRICK_green", 3500, 220, 1.5f, Color.White, true);

            for (int i = 20; i < numberofplatforms; i++)
                platform[i] = new sprite2d(Content, "BRICK_blue", (int)platform[19].bbox.Max.X + ((i-17) * platform[0].rect.Width), 250, 1, Color.White, true);

            // Load in high scores
            if (File.Exists(@"highscore.txt")) // This checks to see if the file exists
            {
                StreamReader sr = new StreamReader(@"highscore.txt");	// Open the file

                String line;		// Create a string variable to read each line into
                for (int i = 0; i < numberofhighscores && !sr.EndOfStream; i++)
                {
                    line = sr.ReadLine();	// Read the first line in the text file
                    highscorenames[i] = line.Trim(); // Read high score name

                    if (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();	// Read the first line in the text file
                        line = line.Trim(); 	// This trims spaces from either side of the text
                        highscores[i] = (int)Convert.ToDecimal(line);	// This converts line to numeric
                    }
                }
                sr.Close();			// Close the file
            }
        }
Exemple #2
0
        /// <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);

            // Initialise game character, setting position, friction and gravity
            cutedude = new animatedsprite(new Vector3(50, 300, 0), 0.95f, 2f, 1f, 4);
            //            cutedude.spriteanimation[0] = new animation(Content, "superguy1", 100, 100, 2f, Color.White, true, 6, 1, 4, true);
            //          cutedude.spriteanimation[1] = new animation(Content, "superguy2", 100, 100, 2f, Color.White, true, 6, 1, 4, true);
            cutedude.spriteanimation[0] = new animation(Content, "cuteman", 100, 100, 0.8f, Color.White, true, 6, 1, 4, true, false);
            cutedude.spriteanimation[1] = new animation(Content, "cuteman2", 100, 100, 0.8f, Color.White, true, 6, 1, 4, true, true);
            cutedude.spriteanimation[2] = new animation(Content, "cutejump", 100, 100, 0.8f, Color.White, true, 14, 1, 7, false, false);
            cutedude.spriteanimation[3] = new animation(Content, "cutejump2", 100, 100, 0.8f, Color.White, true, 14, 1, 7, false, true);

            hitsound = Content.Load<SoundEffect>("ballhit");

            backgscroll = new scrollingbackground2(Content, "skypan", 4f, 6, 1);
            backgscroll.image[1, 0] = Content.Load<Texture2D>("skypan2");
            // backgscroll.image[2, 0] = Content.Load<Texture2D>("skypan2");
            //  backgscroll.image[5, 0] = Content.Load<Texture2D>("skypan2");
            backgscroll.makehorizontal(displayheight);

            // Load in high scores
            if (File.Exists(@"highscore.txt")) // This checks to see if the file exists
            {
                StreamReader sr = new StreamReader(@"highscore.txt");	// Open the file

                String line;		// Create a string variable to read each line into
                for (int i = 0; i < numberofhighscores && !sr.EndOfStream; i++)
                {
                    line = sr.ReadLine();	// Read the first line in the text file
                    highscorenames[i] = line.Trim(); // Read high score name

                    if (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();	// Read the first line in the text file
                        line = line.Trim(); 	// This trims spaces from either side of the text
                        highscores[i] = (int)Convert.ToDecimal(line);	// This converts line to numeric
                    }
                }
                sr.Close();			// Close the file
            }
            Array.Sort(highscores, highscorenames);
            Array.Reverse(highscores);
            Array.Reverse(highscorenames);

            collectgoodfood = new animation(Content, "magic_008", 0, 0, 2, Color.White, false, 26, 3, 5,true, false);
            collectbadfood = new animation(Content, "magic_008", 0, 0, 2, Color.Red, false, 26, 3, 5,true,false);

            death = Content.Load<SoundEffect>("ballhit");
            mainfont = Content.Load<SpriteFont>("font");                                    //Loads Font

            background.image = Content.Load<Texture2D>("Main_Menu");                         //Loads Menu Background
            background.rect.Y = 0;
            background.rect.X = 0;
            background.rect.Width = displaywidth;
            background.rect.Height = displayheight;

            controls.image = Content.Load<Texture2D>("controls");                           //Loads Controls
            controls.rect.Y = 0;
            controls.rect.X = 0;
            controls.rect.Width = displaywidth;
            controls.rect.Height = displayheight;

            soundtrack1 = Content.Load<SoundEffect>("explosive_attack");
            music1 = soundtrack1.CreateInstance();
            music1.IsLooped = true;
            music1.Volume = 0.35f;

            gamebackground.image = Content.Load<Texture2D>("desert_BG");                    //Loads Game Background
            gamebackground.position.Y = 0;
            gamebackground.position.X = 0;
            gamebackground.rect.Width = displaywidth;
            gamebackground.rect.Height = displayheight;
            gamebackground.velocity = new Vector3(-2, 0, 0);

            gamebackground2.image = Content.Load<Texture2D>("desert_BG");                   //Loads Scrolling Background
            gamebackground2.position.Y = 0;
            gamebackground2.position.X = displaywidth;
            gamebackground2.rect.Width = displaywidth;
            gamebackground2.rect.Height = displayheight;
            gamebackground2.velocity = new Vector3(-2, 0, 0);

            gameoverimage.image = Content.Load<Texture2D>("gameoverimage");
            gameoverimage.rect.Y = 0;
            gameoverimage.rect.X = 0;
            gameoverimage.rect.Width = displaywidth;
            gameoverimage.rect.Height = displayheight;

            vicscreen.image = Content.Load<Texture2D>("victoryscreen1");
            vicscreen.rect.Y = 0;
            vicscreen.rect.X = 0;
            vicscreen.rect.Width = displaywidth;
            vicscreen.rect.Height = displayheight;

            loadsprites(ref menuoptions[0, 0], "START", displaywidth / 2, 200, 1.25f);                    //Loads Menu Options
            loadsprites(ref menuoptions[0, 1], "START LOGO", displaywidth / 2, 200, 1.25f);
            loadsprites(ref menuoptions[1, 0], "CONTROLS (2)", displaywidth / 2, 300, 1.25f);
            loadsprites(ref menuoptions[1, 1], "CONTROLS BUTTON", displaywidth / 2, 300, 1.25f);
            loadsprites(ref menuoptions[2, 0], "HIGH SCORE", displaywidth / 2, 400, 1.25f);
            loadsprites(ref menuoptions[2, 1], "HIGH SCORE LOGO", displaywidth / 2, 400, 1.25f);
            loadsprites(ref menuoptions[3, 0], "EXIT", displaywidth / 2, 500, 1.25f);
            loadsprites(ref menuoptions[3, 1], "EXIT LOGO", displaywidth / 2, 500, 1.25f);

            playerjump = Content.Load<SoundEffect>("jump sound 1");
            bananacollect = Content.Load<SoundEffect>("collectgfood");

            menuchange = Content.Load<SoundEffect>("MENU A_Select");                        //Loads Menu Sounds
            menuselect = Content.Load<SoundEffect>("menuSound");

            for (int i = 0; i < numberofbadfood; i++)    // load bad foods
            {
                if (i < 20)
                {
                    bfood[i].image = Content.Load<Texture2D>("chipsPHG");

                }
                if (i >= 20 && i < 40)
                {
                    bfood[i].image = Content.Load<Texture2D>("CheeseburgerRage");

                }
                if (i >= 40 && i < numberofbadfood)
                {
                    bfood[i].image = Content.Load<Texture2D>("evilHotdog");

                }

                bfood[i].origin.Y = bfood[i].image.Height / 2;
                bfood[i].origin.X = bfood[i].image.Width / 2;
                bfood[i].position.Y = 640;
                bfood[i].position.X = 400;
                bfood[i].rect.Width = (int)(bfood[i].image.Width *0.3f);
                bfood[i].rect.Height = (int)(bfood[i].image.Height *0.27f);

            }

            for (int i = 0; i < numberofgoodfood; i++)
            {
                gfood[i].image = Content.Load<Texture2D>("banana");
                gfood[i].origin.Y = gfood[i].image.Height / 2;
                gfood[i].origin.X = gfood[i].image.Width / 2;
                gfood[i].position.Y = 300;
                gfood[i].position.X = 1200;
                gfood[i].rect.Width = (int)(gfood[i].image.Width / 2);
                gfood[i].rect.Height = (int)(gfood[i].image.Height / 2);
                gfood[i].velocity = new Vector3(-5, 0, 0);
            }

            List<Texture2D> textures = new List<Texture2D>();
            textures.Add(Content.Load<Texture2D>("circle"));
            textures.Add(Content.Load<Texture2D>("star"));
            textures.Add(Content.Load<Texture2D>("diamond"));
            for (int i = 0; i < numberofgoodfood; i++)
            particleEngine[i] = new ParticleEngine(textures, new Vector2(450, 420));

            spawnfood();
        }