Example #1
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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            monkeyRect = new Rectangle((int)monkeyPosition.X, (int)monkeyPosition.Y, (int)monkey.Width, (int)monkey.Height);

            lastKeyboardState = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            //m.Update();

            switch (currentState)
            {
                case ScreenState.MainMenu:
                    {
                        if ((currentKeyboardState.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter)))
                            currentState = ScreenState.info;

                        if ((currentKeyboardState.IsKeyDown(Keys.F1) && lastKeyboardState.IsKeyUp(Keys.F1)))
                            currentState = ScreenState.credits;

                        if (currentKeyboardState.IsKeyDown(Keys.F2))
                            this.Exit();

                        break;
                    }

                case ScreenState.credits:
                    {
                        if ((currentKeyboardState.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter)))
                            currentState = ScreenState.Game;

                        if ((currentKeyboardState.IsKeyDown(Keys.F1) && lastKeyboardState.IsKeyUp(Keys.F1)))
                            Process.Start("IExplore.exe", "www.facebook.com/prasad.jayashanka");

                        if ((currentKeyboardState.IsKeyDown(Keys.F2) && lastKeyboardState.IsKeyUp(Keys.F2)))
                            Process.Start("IExplore.exe", "www.vickiwenderlich.com");

                        if ((currentKeyboardState.IsKeyDown(Keys.Escape) && lastKeyboardState.IsKeyUp(Keys.Escape)))
                            currentState = ScreenState.MainMenu;

                        break;
                    }

                case ScreenState.info:
                    {
                        if ((currentKeyboardState.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter)))
                            currentState = ScreenState.Game;

                        if ((currentKeyboardState.IsKeyDown(Keys.Escape) && lastKeyboardState.IsKeyUp(Keys.Escape)))
                            currentState = ScreenState.MainMenu;
                        break;
                    }

                case ScreenState.Pause:
                    {
                        if ((currentKeyboardState.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter)))
                            currentState = ScreenState.Game;

                        if (currentKeyboardState.IsKeyDown(Keys.F3))
                            this.Exit();

                        break;
                    }

                case ScreenState.Game:
                    {
                        #region update_Textures

                        //Walk Left

                        leftWalk_timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
                        if (leftWalk_timeSinceLastFrame > leftWalk_millisecondsPerFrame)
                        {
                            leftWalk_timeSinceLastFrame -= leftWalk_millisecondsPerFrame;
                            ++leftWalk_currentFrame.X;
                            if (leftWalk_currentFrame.X >= leftWalk_sheetSize.X)
                            {
                                leftWalk_currentFrame.X = 0;
                                ++leftWalk_currentFrame.Y;
                                if (leftWalk_currentFrame.Y >= leftWalk_sheetSize.Y)
                                    leftWalk_currentFrame.Y = 0;
                            }
                        }

                        //walk right

                       rightWalk_timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
                       if (rightWalk_timeSinceLastFrame > rightWalk_millisecondsPerFrame)
                        {
                            rightWalk_timeSinceLastFrame -= rightWalk_millisecondsPerFrame;
                            ++rightWalk_currentFrame.X;
                            if (rightWalk_currentFrame.X >= rightWalk_sheetSize.X)
                            {
                                rightWalk_currentFrame.X = 0;
                                ++rightWalk_currentFrame.Y;
                                if (rightWalk_currentFrame.Y >= rightWalk_sheetSize.Y)
                                    rightWalk_currentFrame.Y = 0;
                            }
                        }

                        #endregion

                        if ((currentKeyboardState.IsKeyDown(Keys.Escape) && lastKeyboardState.IsKeyUp(Keys.Escape)))
                            currentState = ScreenState.Pause;

                        if (currentKeyboardState.IsKeyDown(Keys.D) && (currentKeyboardState.IsKeyUp(Keys.Space)))
                        {
                            monkeyPosition.X += speed;
                            heroact = monkeyState.rightWalk;
                        }

                        else if (currentKeyboardState.IsKeyDown(Keys.A) && (currentKeyboardState.IsKeyUp(Keys.Space)))
                        {
                            monkeyPosition.X -= speed;
                            heroact = monkeyState.leftWalk;
                        }

                        else if ((currentKeyboardState.IsKeyDown(Keys.Space) && lastKeyboardState.IsKeyUp(Keys.Space)) && touchGround())
                        {
                            monkeyPosition.Y -= 150;
                            //heroact = monkeyState.normal;
                        }

                        else if ((currentKeyboardState.IsKeyDown(Keys.Space) && lastKeyboardState.IsKeyUp(Keys.Space)) && touchGround() && currentKeyboardState.IsKeyDown(Keys.D))
                        {
                            monkeyPosition.X += speed;
                            heroact = monkeyState.rightJump;
                        }

                        else if ((currentKeyboardState.IsKeyDown(Keys.Space) && lastKeyboardState.IsKeyUp(Keys.Space)) && touchGround() && currentKeyboardState.IsKeyDown(Keys.A))
                        {
                            heroact = monkeyState.leftJump;
                        }

                        else
                        {
                            //heroact = monkeyState.normal;
                        }

                        if (!touchGround())
                            monkeyPosition.Y += 5;
                        else
                            monkeyPosition.Y += 0;

                        for (int x = 0; x < 15; x++)
                        {
                            groundPanel[x].Update();
                        }

                        for (int x = 0; x < 50; x++)
                        {
                            bananas[x].Update();
                        }

                        pillar.Update();
                        pillarEnd.Update();
                        touchPillar();
                        touchPillarEnd();

                            break;
                    }

                case ScreenState.Congrats:
                    {

                        break;
                    }

                default:
                    {

                        break;
                    }
            }

            camera.update(gameTime, this);
            base.Update(gameTime);
        }
Example #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);

            monkey = Content.Load<Texture2D>(@"textures\Monkey\nomalStand");
            leftWalk = Content.Load<Texture2D>(@"textures\Monkey\leftWalk");
            rightWalk = Content.Load<Texture2D>(@"textures\Monkey\rightWalk");

            background = Content.Load<Texture2D>(@"textures\startScreenFull");
            Info = Content.Load<Texture2D>(@"textures\infoScreen");
            credits = Content.Load<Texture2D>(@"textures\credits");
            Pause = Content.Load<Texture2D>(@"textures\pauseScreen");
            win = Content.Load<Texture2D>(@"textures\Congrats");

            pillar = new GameSprite(Content.Load<Texture2D>(@"textures\pillar"), new Rectangle(), new Vector2(-200, 400), 5f);
            pillarEnd = new GameSprite(Content.Load<Texture2D>(@"textures\pillar"), new Rectangle(), new Vector2(17500, 400), 5f);

            font = Content.Load<SpriteFont>(@"Fonts\SpriteFont1");

            #region gameScreens

            Screen1 = Content.Load<Texture2D>(@"textures\background");

            for (int x = 0; x < 15; x++ )
            {
                gameScreen[x] = new GameSprite(Screen1, new Rectangle(), new Vector2(width, 0), 5f);
                groundPanel[x] = new GameSprite(Content.Load<Texture2D>(@"textures\ground"), new Rectangle(), new Vector2(width, 660), 5f);
                width += 1280;
            }

            for (int x = 0; x < 50; x++)
            {
                bananas[x] = new GameSprite(Content.Load<Texture2D>(@"textures\banana"), new Rectangle(), new Vector2((rnd.Next(-100, 17500)), (rnd.Next(200,500))), 5f);
            }

            #endregion

                currentState = ScreenState.MainMenu;
                heroact = monkeyState.normal;

            //m = new Monkey(monkey, new Rectangle(), new Vector2(500, 500), 5f);

            // TODO: use this.Content to load your game content here
        }