コード例 #1
0
ファイル: Game1.cs プロジェクト: easdale2010/College-Year-3
 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
ファイル: Game1.cs プロジェクト: easdale2010/College-Year-3
        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
ファイル: Game1.cs プロジェクト: easdale2010/College-Year-3
        /// <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
            }
            Array.Sort(highscore, highscorename);
            Array.Reverse(highscore);
            Array.Reverse(highscorename);

            background = new graphic2d(Content, "backgroundformenus", 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, "1", displaywidth / 2, 100, 0.7f, Color.White, true);
            menuoptions[0, 1] = new sprite2d(Content, "2", displaywidth / 2, 100, .7f, Color.White, true);
            menuoptions[1, 0] = new sprite2d(Content, "3", displaywidth / 2, 200, .7f, Color.White, true);
            menuoptions[1, 1] = new sprite2d(Content, "4", displaywidth / 2, 200, .7f, Color.White, true);
            menuoptions[2, 0] = new sprite2d(Content, "5", displaywidth / 2, 300, .7f, Color.White, true);
            menuoptions[2, 1] = new sprite2d(Content, "6", displaywidth / 2, 300, .7f, Color.White, true);
            menuoptions[3, 0] = new sprite2d(Content, "7", displaywidth / 2, 400, 0.7f, Color.White, true);
            menuoptions[3, 1] = new sprite2d(Content, "8", displaywidth / 2, 400, 0.7f, Color.White, true);

            for (int i = 0; i < numberofoptions; i++)
                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();

            //resetgame();
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: easdale2010/3DFreeRoam
        /// <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
            mainfont = Content.Load<SpriteFont>("quartz4"); // Load font

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


            // 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
            }
        }
コード例 #5
0
ファイル: Game1.cs プロジェクト: easdale2010/3DFreeRoamPhone
        /// <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
            mainfont = Content.Load<SpriteFont>("quartz4");  // Load the quartz4 font

            background = new graphic2d(Content, "Background for Menus", displaywidth, displayheight);

            up = new sprite2d(Content, "up", 105, displayheight - 180, 0.3f, Color.White, true);
            down = new sprite2d(Content, "down",105, displayheight - 50, 0.3f, Color.White, true);
            left = new sprite2d(Content, "left", 50, displayheight - 115, 0.3f, Color.White, true);
            right = new sprite2d(Content, "right", 160, displayheight - 115, 0.3f, Color.White, true);
            left2 = new sprite2d(Content, "left", displaywidth-180, displayheight - 100, 0.3f, Color.White, true);
            right2 = new sprite2d(Content, "right", displaywidth-60, displayheight - 100, 0.3f, Color.White, true);

            menuoptions[0] = new sprite2d(Content, "player1", displaywidth / 2, 150, 1, Color.White, true);
            menuoptions[1] = new sprite2d(Content, "options", displaywidth / 2, 220, 1, Color.White, true);
            menuoptions[2] = new sprite2d(Content, "highscore", displaywidth / 2, 290, 1, Color.White, true);
            menuoptions[3] = new sprite2d(Content, "exit", displaywidth / 2, 360, 1, Color.White, true);

            // Load the 3D models for the static objects in the game from the ContentManager
            ground = new staticmesh(Content, "sground", 100f, new Vector3(0, -40, 0), new Vector3(0, 0, 0));

            // Initialise robot1 object
            uservehicle = new model3d(Content, "tiefighter", 2f, new Vector3(1000, 0, 1000), new Vector3(0, 0, 0), 0.002f, 0.06f, 10);

            /*
            tree[50] = new staticmesh(Content, "tank", (float)(randomiser.Next(20) + 1) / 10,
                                    new Vector3(randomiser.Next(6000) - 3000, 200, randomiser.Next(6000) - 3000),
                                        new Vector3(0, randomiser.Next(7), 0));
            tree[51] = new staticmesh(Content, "ship", (float)(randomiser.Next(20) + 1) / 10,
                                    new Vector3(randomiser.Next(6000) - 3000, 200, randomiser.Next(6000) - 3000),
                                        new Vector3(0, randomiser.Next(7), 0));
            tree[52] = new staticmesh(Content, "stars", 10,
                                    new Vector3(randomiser.Next(6000) - 3000, 200, randomiser.Next(6000) - 3000),
                                        new Vector3(0, randomiser.Next(7), 0));
            */

            // Load High Scores in
            using (IsolatedStorageFile savegamestorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (savegamestorage.FileExists("highscores.txt"))
                {
                    using (IsolatedStorageFileStream fs = savegamestorage.OpenFile("highscores.txt", System.IO.FileMode.Open))
                    {
                        using (StreamReader sr = new StreamReader(fs))
                        {
                            string line;
                            for (int i = 0; i < numberofhighscores; i++)
                            {
                                line = sr.ReadLine();
                                highscores[i] = Convert.ToInt32(line);
                            }

                            sr.Close();
                        }
                    }
                }
            }
            // Sort high scores
            Array.Sort(highscores);
            Array.Reverse(highscores);

        }
コード例 #6
0
ファイル: Game1.cs プロジェクト: easdale2010/College-Year-3
        /// <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
            }
        }
コード例 #7
0
ファイル: Game1.cs プロジェクト: easdale2010/Beat-the-Clock
 public void checkcollision2(animatedsprite mega, sprite2d fballs)// checks for collision between player and balls move horizontally
 {
     if (mega.bbox.Intersects(fballs.bbox) && invinsibletime >= 1000 && fballs.visible)
     {
         lives--;
         invinsibletime = 0;
         gameallowedtime -= 1000f;
         playerdeath2.Play();
     }
 }
コード例 #8
0
ファイル: Game1.cs プロジェクト: easdale2010/Beat-the-Clock
        void resetlevel()// used for moving the player on to the next level
        {
            // Level 1
            if (levelon == 1)
            {

                megaman.position = new Vector3(50, 500, 0);

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


                balls[0] = new sprite2d(Content, "ball", 340, displayheight - 50, 0.2f, Color.White, true);// move balls
                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, false);
                balls[6] = new sprite2d(Content, "ball", 500 + (8 * 335), displayheight - 25, 0.2f, Color.White, false);

                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++)// make unsed balls invisible
                    balls[7].visible = false;

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

                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);
                platforms[13] = new sprite2d(Content, "redflip", 3830, displayheight - 20, 1, Color.White, false);

                for (int i = 14; 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);// set the unsued spikes visiblity to 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);// give the ball a random velocity ip and down
                }
                //for (int i = 0; i < numberofballs; i++)
                //{
                //    balls[i].velocity = new Vector3(0, -2, 0);
                //}

                for (int i = 0; i < numofsuperballs; i++)
                    superballs[i].visible = false;
                for (int i = 0; i < numofsuperballs; i++)
                {

//                    superballs[i].position = new Vector3(500 + (5 * 335), displayheight - 25, 0);
                    superballs[0].position = new Vector3(500 + (5 * 335), displayheight - 25, 0);
                    superballs[1].position = new Vector3(3630, displayheight - 25, 0);
                    superballs[0].visible = true;
                    superballs[1].visible = true;
                    
                }

                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);// Draw these as true when in use

                collectable2[0] = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 1, Color.White, false);
                collectable2[1] = 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);// used for checking when the player has reached the end.
                }
            }

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

                for (int i = 0; i < numofsuperballs; i++)
                    superballs[i].visible = false;
                megaman.position = new Vector3(50, 500, 0);

                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, "key", platforms[9].rect.X + 330, displayheight - 300, 0.2f, Color.White, true);

                collectable2[0] = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 1, Color.White, false);
                collectable2[1] = 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));// decided not to use this 

                for (int i = 0; i < numofsuperballs; i++)
                    superballs[i].visible = false;

                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)// loads level 3
            {
                backgscroll = new scrollingbackground(Content, "sky", 4f, 3, 1);
                backgscroll.makehorizontal(displayheight);

                megaman.position = new Vector3(50, 500, 0);

                for (int i = 0; i < numofsuperballs; i++)
                    superballs[i].visible = false;

                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, "key", platforms[9].rect.X + 100, 100, 0.2f, Color.White, true);
                collectable2[0] = new sprite2d(Content, "clock", 2285, 400, 0.3f, 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)// load level 5
            {
                backgscroll = new scrollingbackground(Content, "backgroundscrolling2", 4f, 2, 1);
                backgscroll.makehorizontal(displayheight);

                for (int i = 0; i < numofsuperballs; i++)
                    superballs[i].visible = false;

                megaman.position = new Vector3(50, 500, 0);


                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, 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);
                }
                balls[39].velocity = new Vector3(8, 0, 0);
                //superballs[3].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, "key", 2980, 205, 0.2f, Color.White, true);

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

                //for (int i = 0; i < numofsuperballs; i++)
                //    superballs[i].visible = false;

                for (int i = 0; i < numofsuperballs; i++)
                {
                    if (numofsuperballs < 2)
                        superballs[i].visible = false;
                    else
                        superballs[i].visible = true;

                    //superballs[i].velocity = new Vector3(100, 0, 0);
                }
                superballs[3].visible = false;
                
                superballs[2].position = new Vector3(1140, displayheight - 25, 0);
                superballs[3].position = new Vector3(1500, displayheight - 25, 0);
                superballs[4].position = new Vector3(2500, displayheight - 25, 0);
              

                megaman.position = new Vector3(50, 500, 0);

                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, false);

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

                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);

                platforms[16] = new sprite2d(Content, "orange", 3780, displayheight - 25, 1, Color.White, false);
                platforms[17] = new sprite2d(Content, "orange", 100, displayheight - 25, 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);
                }

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

                collectable2[0] = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 1, Color.White, false);
                collectable2[1] = new sprite2d(Content, "car", platforms[9].rect.X + 330, displayheight - 300, 1, Color.White, false);
            }
            if (levelon == 6)/// if player gets here the game will end 
            {
                gameover = true;

            }
        }
コード例 #9
0
ファイル: Game1.cs プロジェクト: easdale2010/Beat-the-Clock
        /// <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();
        }
コード例 #10
0
ファイル: Game1.cs プロジェクト: easdale2010/ZombiesUnleashed
        /// <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);

            // Create a music track
            soundtrack = Content.Load<SoundEffect>("Behind-every-Idea");
            music = soundtrack.CreateInstance();

            playergun = Content.Load<SoundEffect>("starting_pistol");
            zombiehit = Content.Load<SoundEffect>("Zombie Attacked");
            playerhit = Content.Load<SoundEffect>("Bite");

            //Make the track looped and if its stop then play it
            music.IsLooped = true;
            music.Volume = 0.75f;
            if (music.State == SoundState.Playing) music.Stop();



            // TODO: use this.Content to load your game content here
            mainfont = Content.Load<SpriteFont>("quartz4");  // Load the quartz4 font

            background = new graphic2d(Content, "ZombieBG", displaywidth, displayheight);
            background2 = new graphic2d(Content, "skyline", displaywidth, displayheight);
            backgroundGO = new graphic2d(Content, "gameoverbg", displaywidth, displayheight);

            up = new sprite2d(Content, "up", 115, displayheight - 150, 0.25f, Color.White, true);
            down = new sprite2d(Content, "down",115, displayheight - 50, 0.25f, Color.White, true);
            left = new sprite2d(Content, "left", 55, displayheight - 100, 0.25f, Color.White, true);
            right = new sprite2d(Content, "right", 175, displayheight - 100, 0.25f, Color.White, true);

            controlshowto = new sprite2d(Content, "Controls", 425, displayheight - 225, 0.65f, Color.White, true);

            firebut = new sprite2d(Content, "fire", 700, displayheight - 100, 0.50f, Color.White, true);
            menuback = new sprite2d(Content, "right", displaywidth - 50, 50, 0.25f, Color.White, true);
            
            menuoptions[0] = new sprite2d(Content, "buttonstart", displaywidth / 2, 150, 0.50f, Color.White, true);
            menuoptions[1] = new sprite2d(Content, "buttonhowtoplay", displaywidth / 2, 220, 0.50f, Color.White, true);
            menuoptions[2] = new sprite2d(Content, "buttonhighscore", displaywidth / 2, 290, 0.50f, Color.White, true);
            menuoptions[3] = new sprite2d(Content, "buttonexit", displaywidth / 2, 360, 0.50f, Color.White, true);

            // Initialise robot1 object
            playerchar = new model3d(Content, "player", 2f, new Vector3(0, 0, 0), new Vector3(0, 0, 0), 0.002f, 0.06f, 10);
            playerchar.bboxsize = new Vector3(25, 115, 25);


            // Load High Scores in
            using (IsolatedStorageFile savegamestorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (savegamestorage.FileExists("highscores.txt"))
                {
                    using (IsolatedStorageFileStream fs = savegamestorage.OpenFile("highscores.txt", System.IO.FileMode.Open))
                    {
                        using (StreamReader sr = new StreamReader(fs))
                        {
                            string line;
                            for (int i = 0; i < numberofhighscores; i++)
                            {
                                line = sr.ReadLine();
                                highscores[i] = Convert.ToInt32(line);
                            }

                            sr.Close();
                        }
                    }
                }
            }
            // Sort high scores
            Array.Sort(highscores);
            Array.Reverse(highscores);

        }