Beispiel #1
0
 // Method to load sprites and set them up
 void loadsprite(ref sprite2d sprite, string graphicname, int x, int y, float msize)
 {
     sprite.image       = Content.Load <Texture2D>(graphicname); // Load image into texture
     sprite.position    = new Vector3((float)x, (float)y, 0);    // Set position
     sprite.rect.X      = x;                                     // Set position of draw rectangle x
     sprite.rect.Y      = y;                                     // Set position of draw rectangle y
     sprite.origin.X    = sprite.image.Width / 2;                // Set X origin to half of width
     sprite.origin.Y    = sprite.image.Height / 2;               // Set Y origin to half of height
     sprite.rect.Width  = (int)(sprite.image.Width * msize);     // Set the new width based on the size ratio
     sprite.rect.Height = (int)(sprite.image.Height * msize);    // Set the new height based on the size ratio
     sprite.size        = msize;                                 // Store size ratio
     // Create Boundingsphere and BoundingBox around the object
     sprite.bsphere = new BoundingSphere(sprite.position, sprite.rect.Width / 2);
     sprite.bbox    = new BoundingBox(new Vector3(sprite.position.X - (sprite.rect.Width / 2), sprite.position.Y - (sprite.rect.Height / 2), sprite.position.Z),
                                      new Vector3(sprite.position.X + (sprite.rect.Width / 2), sprite.position.Y + (sprite.rect.Height / 2), sprite.position.Z));
 }
Beispiel #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // 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
            }
        }
Beispiel #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
            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);
        }
 // Method to load sprites and set them up
 void loadsprite(ref sprite2d sprite, string graphicname, int x, int y, float msize)
 {
     sprite.image = Content.Load<Texture2D>(graphicname);    // Load image into texture
     sprite.position = new Vector3((float)x, (float)y, 0);   // Set position
     sprite.rect.X = x;                                      // Set position of draw rectangle x
     sprite.rect.Y = y;                                      // Set position of draw rectangle y
     sprite.origin.X = sprite.image.Width / 2;               // Set X origin to half of width
     sprite.origin.Y = sprite.image.Height / 2;              // Set Y origin to half of height
     sprite.rect.Width = (int)(sprite.image.Width * msize);  // Set the new width based on the size ratio 
     sprite.rect.Height = (int)(sprite.image.Height * msize);// Set the new height based on the size ratio
     sprite.size = msize;                                    // Store size ratio
     // Create Boundingsphere and BoundingBox around the object
     sprite.bsphere = new BoundingSphere(sprite.position, sprite.rect.Width / 2);
     sprite.bbox = new BoundingBox(new Vector3(sprite.position.X - (sprite.rect.Width / 2), sprite.position.Y - (sprite.rect.Height / 2), sprite.position.Z),
                             new Vector3(sprite.position.X + (sprite.rect.Width / 2), sprite.position.Y + (sprite.rect.Height / 2), sprite.position.Z));
 }
Beispiel #5
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);

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