Пример #1
0
 public void checkcollision2(animatedsprite mega, sprite2d fballs)
 {
     if (mega.bbox.Intersects(fballs.bbox) && invinsibletime >= 1000 && fballs.visible)
     {
         lives--;
         invinsibletime = 0;
         gameruntime += 1000f;
         playerdeath2.Play();
     }
 }
Пример #2
0
        void resetlevel()
        {
            // Level 1
            if (levelon == 1)
            {
                megaman = new animatedsprite(new Vector3(50, 500, 0), 0.95f, 2f, 1f, 4);
                megaman.spriteanimation[0] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, false);
                megaman.spriteanimation[1] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, true);
                megaman.spriteanimation[2] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, false);
                megaman.spriteanimation[3] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, true);

                backgscroll = new scrollingbackground(Content, "backgroundforscrolling", 4f, 3, 1);
                backgscroll.makehorizontal(displayheight);

                balls[0] = new sprite2d(Content, "ball", 340, displayheight - 50, 0.2f, Color.White, true);
                for (int i = 1; i < numberofballs; i++)
                {
                    //balls[1] = new sprite2d(Content, "ball", 830, displayheight / 2, 0.2f, Color.White, true);
                    balls[i] = new sprite2d(Content, "ball", 500 + (i * 335), displayheight - 50, 0.2f, Color.White, true);

                }

                balls[5] = new sprite2d(Content, "ball", 500 + (5 * 335), displayheight - 25, 0.2f, Color.White, true);
                balls[6] = new sprite2d(Content, "ball", 500 + (8 * 335), displayheight - 25, 0.2f, Color.White, true);

                for (int i = 7; i < numberofballs; i++)
                    balls[i] = new sprite2d(Content, "ball", 500 + (i * 335), displayheight - 50, 0.2f, Color.White, false);

                for (int i = 7; i < numberofballs; i++)
                    balls[7].visible = false;

                platforms[0] = new sprite2d(Content, "red", 340, displayheight - 20, 1, Color.White, true);

                for (int i = 1; i < 5; i++)
                    platforms[i] = new sprite2d(Content, "red", 500 + (i * platforms[0].rect.Width) * 5, displayheight - 20, 1, Color.White, true);
                platforms[5] = new sprite2d(Content, "redflip", 339, platforms[0].rect.Height / 2, 1, Color.White, true);
                platforms[6] = new sprite2d(Content, "redflip", 834, platforms[0].rect.Height / 2, 1, Color.White, true);
                platforms[7] = new sprite2d(Content, "redflip", 839 + 330, platforms[0].rect.Height / 2, 1, Color.White, true);
                platforms[8] = new sprite2d(Content, "redflip", 845 + 330 + 330, platforms[0].rect.Height / 2, 1, Color.White, true);
                platforms[9] = new sprite2d(Content, "redflip", 849 + 330 + 330 + 330, platforms[0].rect.Height / 2, 1, Color.White, true);

                platforms[10] = new sprite2d(Content, "red", 849 + 990 + 600, displayheight - platforms[0].rect.Height / 2, 1, Color.White, true);
                platforms[11] = new sprite2d(Content, "redflip", 849 + 990 + 600, displayheight - 200, 1, Color.White, true);
                platforms[12] = new sprite2d(Content, "redflip", 849 + 990 + 600, displayheight - 200, 1, Color.White, true);

                for (int i = 13; i < numberofplatforms; i++)
                    platforms[i] = new sprite2d(Content, "redflip", 849 + 990 + 600, displayheight + 500 + 200, 1, Color.White, false);

                spikes[0] = new sprite2d(Content, "spikes", 100, 500, 1, Color.White, false);

                for (int i = 1; i < numberofspikes; i++)
                    spikes[i] = new sprite2d(Content, "spikes", platforms[9].rect.X + 330, displayheight - spikes[0].rect.Height / 2, 1, Color.White, false);

                for (int i = 0; i < numberofballs; i++)
                {
                    do
                    {
                        balls[i].velocity = new Vector3(0, (float)(randomiser.Next(20) + 1) / 2, 0);
                    } while (balls[i].velocity.Y == 0);
                }
                //for (int i = 0; i < numberofballs; i++)
                //{
                //    balls[i].velocity = new Vector3(0, -2, 0);
                //}
                for (int i = 5; i < numberofballs; i++)
                    balls[i].velocity = new Vector3(2, 0, 0);

                collectable = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 1, Color.White, false);

                collectable2 = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 1, Color.White, false);

                for (int i = 0; i < numberofends; i++)
                {
                    ends[i] = new sprite2d(Content, "green", 3830, displayheight - (i * 35), 1, Color.White, false);
                }
            }

            // Level 2
            if (levelon == 2)
            {
                backgscroll = new scrollingbackground(Content, "skypan2", 4f, 1, 1);
                backgscroll.makehorizontal(displayheight);

                megaman = new animatedsprite(new Vector3(50, 500, 0), 0.95f, 2f, 1f, 4);
                megaman.spriteanimation[0] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, false);
                megaman.spriteanimation[1] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, true);
                megaman.spriteanimation[2] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, false);
                megaman.spriteanimation[3] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, true);

                balls[0] = new sprite2d(Content, "ball", 340, displayheight - 50, 0.2f, Color.White, true);
                for (int i = 0; i < numberofballs; i++)
                {
                    //balls[1] = new sprite2d(Content, "ball", 830, displayheight / 2, 0.2f, Color.White, true);
                    balls[i] = new sprite2d(Content, "ball", 500 + (i * 335), displayheight - 50, 0.2f, Color.White, false);

                }
                //balls[5] = new sprite2d(Content, "ball", 500 + (5 * 335), displayheight - 25, 0.2f, Color.White, false);
                //balls[6] = new sprite2d(Content, "ball", 500 + (8 * 335), displayheight - 25, 0.2f, Color.White, false);

                platforms[0] = new sprite2d(Content, "green", 340, displayheight - 20, 1, Color.White, true);

                for (int i = 1; i < 5; i++)
                    platforms[i] = new sprite2d(Content, "green", 500 + (i * platforms[0].rect.Width) * 5, displayheight - 20 - (i * 40), 1, Color.White, true);
                for (int i = 5; i < numberofplatforms; i++)
                    platforms[i] = new sprite2d(Content, "green", platforms[4].rect.X + 330 + (i * platforms[3].rect.Width), displayheight / 2, 1, Color.White, true);
                //platforms[6] = new sprite2d(Content, "greenflip", 834, platforms[0].rect.Height / 2, 1, Color.White, false);
                //platforms[7] = new sprite2d(Content, "greenflip", 839 + 330, platforms[0].rect.Height / 2, 1, Color.White, false);
                //platforms[8] = new sprite2d(Content, "greenflip", 845 + 330 + 330, platforms[0].rect.Height / 2, 1, Color.White, false);
                //platforms[9] = new sprite2d(Content, "greenflip", 849 + 330 + 330 + 330, platforms[0].rect.Height / 2, 1, Color.White, false);

                platforms[10] = new sprite2d(Content, "green", platforms[4].rect.X + 330, displayheight / 2, 1, Color.White, true);
                platforms[11] = new sprite2d(Content, "green", platforms[9].rect.X + 330, displayheight / 2, 1, Color.White, true);
                platforms[12] = new sprite2d(Content, "greenflip", platforms[9].rect.X + 330, displayheight - 400, 1, Color.White, true);

                for (int i = 13; i < numberofplatforms; i++)
                    platforms[i] = new sprite2d(Content, "redflip", 849 + 990 + 600, displayheight + 500 + 200, 1, Color.White, false);

                collectable = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 0.1f, Color.White, true);

                collectable2 = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 1, Color.White, false);

                for (int i = 0; i < numberofspikes; i++)
                    spikes[i] = new sprite2d(Content, "spikes", platforms[9].rect.X + 330, displayheight - spikes[i].rect.Height / 2, 1, Color.White, true);

                animation powerup = new animation(Content, "cast_006", platforms[9].rect.X + 330, displayheight - 200, 0.1f, Color.White, true, 25, 6, 6);
                powerup.start(new Vector3(200, 300, 0));

                for (int i = 0; i < numberofends; i++)
                {
                    ends[i] = new sprite2d(Content, "green", 3830, displayheight - (i * 35), 1, Color.White, false);
                }

                //for (int i = 0; i < numberofballs; i++)
                //{
                //    do
                //    {
                //        balls[i].velocity = new Vector3(0, (float)(randomiser.Next(20) + 1) / 2, 0);
                //    } while (balls[i].velocity.Y == 0);
                //}
            }

            // Level 3
            if (levelon == 3)
            {
                backgscroll = new scrollingbackground(Content, "sky", 4f, 3, 1);
                backgscroll.makehorizontal(displayheight);

                megaman = new animatedsprite(new Vector3(50, 350, 0), 0.95f, 2f, 1f, 4);
                megaman.spriteanimation[0] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, false);
                megaman.spriteanimation[1] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, true);
                megaman.spriteanimation[2] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, false);
                megaman.spriteanimation[3] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, true);

                balls[0] = new sprite2d(Content, "ball", 340, displayheight - 50, 0.2f, Color.White, false);
                for (int i = 1; i < numberofballs; i++)
                {
                    //balls[1] = new sprite2d(Content, "ball", 830, displayheight / 2, 0.2f, Color.White, true);
                    balls[i] = new sprite2d(Content, "ball", 500 + (i * 335), displayheight - 50, 0.2f, Color.White, false);

                }
                balls[5] = new sprite2d(Content, "ball", 500 + (5 * 335), displayheight - 25, 0.2f, Color.White, true);
                balls[6] = new sprite2d(Content, "ball", 500 + (8 * 335), displayheight - 25, 0.2f, Color.White, true);

                platforms[0] = new sprite2d(Content, "diamond", 50, displayheight - 100, 1, Color.White, true);
                for (int i = 1; i < 5; i++)
                    platforms[i] = new sprite2d(Content, "diamond", 80 + (i * platforms[0].rect.Width) * 4, displayheight - 100, 1, Color.White, true);

                for (int i = 5; i < 8; i++)
                    platforms[i] = new sprite2d(Content, "diamond", (i * platforms[0].rect.Width - 50) * 5, displayheight - 20 - (i * 40), 1, Color.White, true);

                platforms[10] = new sprite2d(Content, "diamond", (platforms[9].rect.X - 400), displayheight - 200, 1, Color.White, true);
                platforms[11] = new sprite2d(Content, "diamond", platforms[9].rect.X - 50, displayheight - 150, 1, Color.White, true);
                platforms[8] = new sprite2d(Content, "red", platforms[7].rect.X, displayheight - 75, 1, Color.White, true);
                platforms[9] = new sprite2d(Content, "diamond", platforms[7].rect.X + 60, displayheight - 120, 1, Color.White, true);
                platforms[12] = new sprite2d(Content, "diamond", platforms[9].rect.X + 1000, displayheight - 200, 1, Color.White, true);
                for (int i = 13; i < 17; i++)
                    platforms[i] = new sprite2d(Content, "triangle", i * platforms[9].rect.Width + 2700, displayheight - 300, 1, Color.White, true);

                platforms[20] = new sprite2d(Content, "diamond", platforms[19].rect.Width + 3400, displayheight - 100, 1, Color.White, true);

                for (int i = 21; i < numberofplatforms; i++)
                    platforms[i] = new sprite2d(Content, "triangle", 849 + 990 + 600, displayheight + 500 + 200, 1, Color.White, false);

                collectable = new sprite2d(Content, "car", platforms[9].rect.X + 100, 100, 0.1f, Color.White, true);
                collectable2 = new sprite2d(Content, "saucer2", 2255, 400, 0.1f, Color.White, true);

                spikes[0] = new sprite2d(Content, "spikes", 100, displayheight - 40, 1, Color.White, true);

                for (int i = 1; i < numberofspikes; i++)
                    spikes[i] = new sprite2d(Content, "spikes", 100 + (i * spikes[0].rect.Width), displayheight - 40, 1, Color.White, true);

                for (int i = 0; i < numberofends; i++)
                {
                    ends[i] = new sprite2d(Content, "green", 3830, (i * 35), 1, Color.White, false);
                }

                for (int i = 0; i < numberofballs; i++)
                {
                    do
                    {
                        balls[i].velocity = new Vector3(0, (float)(randomiser.Next(40) + 1) / 2f, 0);
                    } while (balls[i].velocity.Y == 0);
                }

            }
            if (levelon == 4)
            {
                backgscroll = new scrollingbackground(Content, "backgroundscrolling2", 4f, 5, 1);
                backgscroll.makehorizontal(displayheight);

                megaman = new animatedsprite(new Vector3(50, 500, 0), 0.95f, 2f, 1f, 4);
                megaman.spriteanimation[0] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, false);
                megaman.spriteanimation[1] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, true);
                megaman.spriteanimation[2] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, false);
                megaman.spriteanimation[3] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, true);

                for (int i = 0; i < numberofplatforms; i++)
                    platforms[i] = new sprite2d(Content, "red", (i * 70), displayheight + 100 + platforms[i].rect.Height / 2, 1, Color.White, false);
                for (int i = 56; i < numberofplatforms; i++)
                    platforms[i] = new sprite2d(Content, "redflip", platforms[0].rect.X + (10 * 1), 100 + platforms[i].rect.Height / 2, 1, Color.White, false);

                for (int i = 0; i < numberofspikes; i++)
                    spikes[i] = new sprite2d(Content, "spikes", 100 + (i * spikes[0].rect.Width), displayheight + 340, 1, Color.White, false);

                //balls[0] = new sprite2d(Content, "ball", 50, displayheight - 50, 0.2f, Color.White, true);
                for (int i = 7; i < numberofballs; i++)
                {
                    //balls[1] = new sprite2d(Content, "ball", 830, displayheight / 2, 0.2f, Color.White, true);
                    balls[i] = new sprite2d(Content, "ball", 40 + (i * 120), displayheight - 50, 0.2f, Color.White, true);

                }

                balls[39] = new sprite2d(Content, "ball", 340, displayheight - balls[39].rect.Height / 2, 0.2f, Color.White, true);

                for (int i = 0; i < numberofballs; i++)
                {
                    do
                    {
                        balls[i].velocity = new Vector3(0, (float)(randomiser.Next(40) + 1) / 2f, 0);
                    } while (balls[i].velocity.Y == 0);
                }
                balls[39].velocity = new Vector3(8, 0, 0);

                for (int i = 0; i < numberofends; i++)
                {
                    ends[i] = new sprite2d(Content, "green", 3830, displayheight - (i * 35), 1, Color.White, false);
                }

                collectable = new sprite2d(Content, "car", 2980, 205, 0.1f, Color.White, true);

                collectable2 = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 1, Color.White, false);
            }
            if (levelon == 5)
            {
                backgscroll = new scrollingbackground(Content, "skypan2", 4f, 1, 1);
                backgscroll.makehorizontal(displayheight);

                megaman = new animatedsprite(new Vector3(50, 500, 0), 0.95f, 2f, 1f, 4);
                megaman.spriteanimation[0] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, false);
                megaman.spriteanimation[1] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, true);
                megaman.spriteanimation[2] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, false);
                megaman.spriteanimation[3] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, true);

                platforms[0] = new sprite2d(Content, "orange", 200, 350, 1, Color.White, true);
                for (int i = 0; i < numberofplatforms; i++)
                    platforms[i] = new sprite2d(Content, "orange", (i * 700), 350, 1, Color.White, true);

                balls[37] = new sprite2d(Content, "ball", 540, displayheight - balls[39].rect.Height / 2, 0.2f, Color.White, true);

                balls[38] = new sprite2d(Content, "ball", 1500, displayheight - balls[39].rect.Height / 2, 0.2f, Color.White, true);
                balls[39] = new sprite2d(Content, "ball", 2500, displayheight - balls[39].rect.Height / 2, 0.2f, Color.White, true);

                for (int i = 0; i < numberofballs; i++)
                {
                    balls[i].visible = false;
                }
                balls[37].visible = true;
                balls[37].velocity = new Vector3((float)(randomiser.Next(12) + 8), 0, 0);
                balls[38].visible = true;
                balls[38].velocity = new Vector3((float)(randomiser.Next(12) + 8), 0, 0);

                balls[39].visible = true;
                balls[39].velocity = new Vector3((float)(randomiser.Next(12) + 8), 0, 0);

                for (int i = 0; i < numberofends; i++)
                {
                    ends[i] = new sprite2d(Content, "green", 3830, displayheight - (i * 35), 1, Color.White, false);
                }

                collectable = new sprite2d(Content, "car", 2980, 205, 0.1f, Color.White, true);

                collectable2 = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 1, Color.White, false);
            }
            if (levelon == 6)
            {
                gameover = true;
            }
        }
Пример #3
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
            }
        }
Пример #4
0
 public void checkcollision3(animatedsprite mega, animatedsprite aballs)// checks for collision between player and animations move horizontally
 {
     if (mega.bbox.Intersects(aballs.bbox) && invinsibletime >= 1000 && aballs.visible)
     {
         lives--;
         invinsibletime = 0;
         gameallowedtime -= 1000f;
         playerdeath2.Play();
     }
 }
Пример #5
0
 public void checkcollision(animatedsprite mega, sprite2d fballs)// // checks for collision between player and balls move vertically
 {
     if (mega.bbox.Intersects(fballs.bbox) && invinsibletime >= 1000 && fballs.visible)
     {
         lives--;
         invinsibletime = 0;
         gameallowedtime -= 1000f;
         playerdeath.Play();
     }
 }
Пример #6
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);

            // 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
                    highscorename[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
                        highscore[i] = (int)Convert.ToDecimal(line);	// This converts line to numeric
                    }
                }
                sr.Close();			// Close the file
            }

            // sorts highscores and high score names
            Array.Sort(highscore, highscorename);
            Array.Reverse(highscore);
            Array.Reverse(highscorename);

            background = new graphic2d(Content, "backgroundformenus", displaywidth, displayheight);// load in graphic
            mousepointer1 = new sprite2d(Content, "X-Games-Cursor", 0, 0, 0.15f, Color.White, true);// loads in sprites
            mousepointer2 = new sprite2d(Content, "X-Games-Cursor-Highlight", 0, 0, 0.15f, Color.White, true);

            menuoptions[0, 0] = new sprite2d(Content, "1", displaywidth / 2, 75, 0.7f, Color.White, true);
            menuoptions[0, 1] = new sprite2d(Content, "2", displaywidth / 2, 75, .7f, Color.White, true);
            menuoptions[1, 0] = new sprite2d(Content, "5", displaywidth / 2, 232, .7f, Color.White, true);
            menuoptions[1, 1] = new sprite2d(Content, "6", displaywidth / 2, 232, .7f, Color.White, true);
            menuoptions[2, 0] = new sprite2d(Content, "7", displaywidth / 2, 388, 0.7f, Color.White, true);
            menuoptions[2, 1] = new sprite2d(Content, "8", displaywidth / 2, 388, 0.7f, Color.White, true);

            for (int i = 0; i < numberofoptions; i++)// update menu options
                menuoptions[i, 0].updateobject();

            mainfont = Content.Load<SpriteFont>("mainfont");


            //mainfont = Content.Load<SpriteFont>("quartz4");
            gameoverimage = new graphic2d(Content, "gameover", displaywidth, displayheight);
            gameoverimage.stretch2fit(displaywidth, displayheight);
            playerdeath = Content.Load<SoundEffect>("GLASS02");
            playerdeath2 = Content.Load<SoundEffect>("CRASH03");
            winner = new graphic2d(Content, "winner", displaywidth, displayheight);
            gamemusic = Content.Load<SoundEffect>("iron-man");
            music = gamemusic.CreateInstance();
            
            megaman = new animatedsprite(new Vector3(50, 500, 0), 0.95f, 2f, 1f, 4);// loads animation
            megaman.spriteanimation[0] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, false);// animatesa animation
            megaman.spriteanimation[1] = new animation(Content, "megamanx", 100, 100, 2f, Color.White, true, 13, 1, 11, true, false, true);
            megaman.spriteanimation[2] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, false);
            megaman.spriteanimation[3] = new animation(Content, "megamanjump", 100, 100, 2f, Color.White, true, 14, 1, 7, false, false, true);


            for (int i = 0; i < numofsuperballs; i++)
            {
                superballs[i] = new animatedsprite(new Vector3(100, displayheight - 25, 0), 0.95f, 2f, 0.5f, 1);// loads animation
                superballs[i].spriteanimation[0] = new animation(Content, "cast_006", 0, 0, 0.3f, Color.White, true, 18, 4, 5, true, false, false);// animatesa animation
                superballs[i].state = 0;
                superballs[i].gravity = 0;
            }

            //resetgame();
        }
Пример #7
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();
        }