コード例 #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Main Manu.
            menu.LoadContent(Content);

            //Load font
            font = Content.Load <SpriteFont>("ScoreFont/Score");

            //Scrolling path load.
            scrolling1 = new ScrollingPath(Content.Load <Texture2D>("path"), new Rectangle(0, 930, 1920, 150));
            scrolling2 = new ScrollingPath(Content.Load <Texture2D>("path2"), new Rectangle(1920, 930, 1920, 150));

            //Background load.
            backGround1 = new BackGround(Content.Load <Texture2D>("LabBGNew"), new Rectangle(0, 0, 2000, 1080));
            backGround2 = new BackGround(Content.Load <Texture2D>("LabBGNew"), new Rectangle(2000, 0, 2000, 1080));
            backGround3 = new BackGround(Content.Load <Texture2D>("GraduationBG"), new Rectangle(4000, 0, 2000, 1080));
            backGround4 = new BackGround(Content.Load <Texture2D>("WorkBG2"), new Rectangle(6000, 0, 2000, 1080));
            backGround5 = new BackGround(Content.Load <Texture2D>("WorkBG2"), new Rectangle(8000, 0, 2000, 1080));
            backGround6 = new BackGround(Content.Load <Texture2D>("StartScreen/darkscreen"), new Rectangle(-1366 + darkscreenmovement, 0, 1366, 788));

            //Set default velocity to runner.
            velocity.X = 3f;
            velocity.Y = 3f;

            //Load hurdles.
            hurdle1 = new Hurdles(Content.Load <Texture2D>("Pickups/(b)missed_alarm_pickup"), new Rectangle(2010, 790, 150, 150));
            hurdle2 = new Hurdles(Content.Load <Texture2D>("Pickups/(b)missed_alarm_pickup"), new Rectangle(3800, 650, 150, 150));
            hurdle3 = new Hurdles(Content.Load <Texture2D>("Pickups/(b)missed_alarm_pickup"), new Rectangle(1500, 400, 150, 150));
            hurdle4 = new Hurdles(Content.Load <Texture2D>("Pickups/(b)missed_alarm_pickup"), new Rectangle(575, 600, 150, 150));

            //Start Manu item Loading.
            IsMouseVisible = true;
            startButton    = Content.Load <Texture2D>("StartScreen/start");
            exitButton     = Content.Load <Texture2D>("StartScreen/exit");
            resumeButton   = Content.Load <Texture2D>("StartScreen/resume");
            loadingScreen  = Content.Load <Texture2D>("StartScreen/loading");
            pushButton     = Content.Load <Texture2D>("StartScreen/pause");
            resumeButton   = Content.Load <Texture2D>("StartScreen/resume");

            // Load audio objects
            gameMusic = Content.Load <Song>("game_music");
            MediaPlayer.IsRepeating = true;
        }
コード例 #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Manu Button Update.
            menu.Update();

            // Play audio objects
            if (!songstart)
            {
                MediaPlayer.Play(gameMusic);
                songstart = true;
            }

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                int Score = score;
                if (Score > Int32.Parse(ReadHighScore()))
                {
                    SaveHighScore(Score);
                    SavePlayer(playre);
                }

                this.Exit();
            }



            //Escape button set to exit.
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                int Score = score;
                if (Score > Int32.Parse(ReadHighScore()))
                {
                    SaveHighScore(Score);
                    SavePlayer(playre);
                }

                this.Exit();
            }

            //Initialise mouse click event.
            if (menu.Set == "Done")
            {
                mouseState = Mouse.GetState();
                if (previousMouseState.LeftButton == ButtonState.Pressed &&
                    mouseState.LeftButton == ButtonState.Released)
                {
                    MouseClick(mouseState.X, mouseState.Y);
                }

                previousMouseState = mouseState;
            }

            //Set player state to run game.
            if (gameState == GameState.Playing)
            {
                //runner
                runner.Update(gameTime);
                count++;
                if (count == 500)
                {
                    int   cframe = runner.currentFrame;
                    float ypos   = runner.position.Y;
                    float xpos   = runner.position.X;

                    //runner = new Animation(Content.Load<Texture2D>("RunnerWHat"), new Vector2(xpos, ypos), 330, 288);
                    runner.currentFrame = cframe;
                }

                //Scrolling path

                if (scrolling1.rectangle.X + 1920 <= 0)
                {
                    scrolling1.rectangle.X = scrolling2.rectangle.X + 1920;
                }
                if (scrolling2.rectangle.X + 1920 <= 0)
                {
                    scrolling2.rectangle.X = scrolling1.rectangle.X + 1920;
                }

                //Scrolling Background

                if (backGround1.rectangle.X + 2000 <= 0)
                {
                    backGround1.rectangle.X = backGround2.rectangle.X + 2000;
                }
                if (backGround2.rectangle.X + 2000 <= 0)
                {
                    backGround2.rectangle.X = backGround3.rectangle.X + 2000;
                }
                if (backGround3.rectangle.X + 2000 <= 0)
                {
                    backGround3.rectangle.X = backGround4.rectangle.X + 2000;
                }
                if (backGround4.rectangle.X + 2000 <= 0)
                {
                    backGround4.rectangle.X = backGround5.rectangle.X + 2000;
                }
                if (backGround5.rectangle.X + 2000 <= 0)
                {
                    backGround5.rectangle.X = backGround4.rectangle.X + 2000;
                }

                //Hurdle looping
                if (hurdle1.rectangle.X + 2000 <= 0)
                {
                    hurdle1.rectangle.X = hurdle2.rectangle.X + 2000;
                }
                if (hurdle2.rectangle.X + 2000 <= 0)
                {
                    hurdle2.rectangle.X = hurdle3.rectangle.X + 2000;
                }
                if (hurdle3.rectangle.X + 2000 <= 0)
                {
                    hurdle3.rectangle.X = hurdle4.rectangle.X + 2000;
                }
                if (hurdle4.rectangle.X + 2000 <= 0)
                {
                    hurdle4.rectangle.X = hurdle1.rectangle.X + 2000;
                }
                //Collision hurdle1.
                if (runner.PositionRectangle.Intersects(hurdle1.PositionRectangle))
                {
                    Random        r          = new Random();
                    int           r1         = r.Next(0, 8);
                    List <string> Hurdlelist = HurdlesGood();
                    string        randomname = Hurdlelist[r1];
                    int           random     = r.Next(1366, 1800);
                    int           random2    = r.Next(100, 600);
                    score += 10;
                    if (backGround6.rectangle.X >= -1920)
                    {
                        darkscreenmovement = darkscreenmovement - 10;
                    }
                    hurdle1.rectangle.Y += 1000;
                    //hurdle1.rectangle.Y = random2;
                    // hurdle1.rectangle.X = random;
                    // hurdle1.rectangle.X -= 10;
                    hurdle1              = new Hurdles(Content.Load <Texture2D>("Pickups/" + randomname), new Rectangle(random, random2, 150, 150));
                    hurdle1.rectangle.X -= 10;
                }

                //Collision hurdle2.
                if (runner.PositionRectangle.Intersects(hurdle2.PositionRectangle))
                {
                    Random        r          = new Random();
                    int           r1         = r.Next(0, 8);
                    List <string> Hurdlelist = HurdlesBad();
                    string        randomname = Hurdlelist[r1];
                    int           random     = r.Next(1366, 1800);
                    int           random2    = r.Next(100, 600);
                    if (score > 0)
                    {
                        score -= 25;
                    }
                    darkscreenmovement = darkscreenmovement + 10;
                    //hurdle2.rectangle.Y += 1000;
                    //hurdle2.rectangle.Y = random2;
                    //hurdle2.rectangle.X = random;

                    //Set hurdle2 to random generate.
                    hurdle2 = new Hurdles(Content.Load <Texture2D>("Pickups/" + randomname), new Rectangle(random, random2, 150, 150));

                    hurdle2.rectangle.X -= 10;
                }

                //Collision hurdle3.
                if (runner.PositionRectangle.Intersects(hurdle3.PositionRectangle))
                {
                    Random        r          = new Random();
                    int           r1         = r.Next(0, 8);
                    List <string> Hurdlelist = HurdlesGood();
                    string        randomname = Hurdlelist[r1];
                    int           random     = r.Next(1366, 1800);
                    int           random2    = r.Next(100, 600);
                    score += 10;
                    if (backGround6.rectangle.X >= -1920)
                    {
                        darkscreenmovement = darkscreenmovement - 10;
                    }
                    hurdle1.rectangle.Y += 1000;
                    //hurdle3.rectangle.Y = random2;
                    // hurdle3.rectangle.X = random;
                    // hurdle3.rectangle.X -= 10;
                    hurdle3              = new Hurdles(Content.Load <Texture2D>("Pickups/" + randomname), new Rectangle(random, random2, 150, 150));
                    hurdle3.rectangle.X -= 10;
                }

                //Collision hurdle4.
                if (runner.PositionRectangle.Intersects(hurdle4.PositionRectangle))
                {
                    Random        r          = new Random();
                    int           r1         = r.Next(0, 8);
                    List <string> Hurdlelist = HurdlesBad();
                    string        randomname = Hurdlelist[r1];
                    int           random     = r.Next(1366, 1800);
                    int           random2    = r.Next(100, 600);
                    if (score > 0)
                    {
                        score -= 25;
                    }
                    darkscreenmovement = darkscreenmovement + 10;
                    //hurdle4.rectangle.Y += 1000;
                    //hurdle4.rectangle.Y = random2;
                    //hurdle4.rectangle.X = random;

                    //Set hurdle2 to random generate.
                    hurdle4 = new Hurdles(Content.Load <Texture2D>("Pickups/" + randomname), new Rectangle(random, random2, 150, 150));

                    hurdle4.rectangle.X -= 10;
                }

                //Partial code for a gradual increase in unemployment screen
                //float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
                //float creepTimer = 10;

                //creepTimer -= elapsedTime;

                //if (creepTimer >= 0)
                //{
                //    darkscreenmovement++;
                //    creepTimer = 100f;
                //}


                //Set close screen.
                backGround6 = new BackGround(Content.Load <Texture2D>("StartScreen/darkscreen"), new Rectangle(-1900 + darkscreenmovement, 0, 1920, 1080));


                //Update.
                scrolling1.Update();
                scrolling2.Update();
                backGround1.Update();
                backGround2.Update();
                backGround3.Update();
                backGround4.Update();
                backGround5.Update();
                hurdle1.Update();
                hurdle2.Update();
                ScoreUpadate(gameTime);

                isLoading = false;
            }

            base.Update(gameTime);
        }