Example #1
0
        protected override void Update(GameTime gameTime)
        {
            handleBounds(gameTime);

            daggerBound.X = position;

            lgCandle.Update(gameTime.ElapsedGameTime.Ticks);
            // Bounding rectangles...
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            #region Skeleton handling
            timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
            if (timeSinceLastFrame > (timePerFrame * 4))
            {
                timeSinceLastFrame -= (timePerFrame * 4);
                if (enemyCurrentFrameX < 36)
                {
                    enemyCurrentFrameX += 36;
                }
                else
                {
                    enemyCurrentFrameX = 0;
                }
            }
            if (skeletonPosition.X == 0)
            {
                left = false;
                skeletonPosition.X += 1;
            }
            else if (skeletonPosition.X > 0 && left)
            {
                skeletonPosition.X -= 1;
                enemyCurrentFrameY  = 0;
            }
            else if (skeletonPosition.X < 200)
            {
                skeletonPosition.X += 1;
                enemyCurrentFrameY  = 64;
            }
            else if (skeletonPosition.X == 200)
            {
                left = true;
                skeletonPosition.X -= 1;
            }
            #endregion

            #region Player handling
            KeyboardState keyState = Keyboard.GetState();
            if (keyState.IsKeyDown(Keys.Right))
            {
                // if the screen is at boundaries, then go to right edge
                if (trevorPosition.X < 605 && !scrolling)
                {
                    trevorPosition.X += 1;
                }
                // otherwise, limit the boundary to the center of the screen to scroll
                if (trevorPosition.X > 300 && viewPosX > -1651)
                {
                    scrolling = true;
                    viewPosX -= 1;
                    foreach (Candle c in candles)
                    {
                        c.location.X -= 1;
                    }
                }
                // allow player to reach right edge of screen by disabling scrolling since we are at edge
                if (viewPosX <= -1651)
                {
                    scrolling = false;
                }

                currentFrameY       = 62;
                timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
                if (timeSinceLastFrame > (timePerFrame / 3))
                {
                    timeSinceLastFrame -= (timePerFrame * 3);
                    if (currentFrameX < 80)
                    {
                        currentFrameX += 40;
                    }
                    else
                    {
                        currentFrameX = 0;
                    }
                }
            }
            else if (keyState.IsKeyDown(Keys.Left))
            {
                // if not scrolling, allow the player to reach the left edge
                if (trevorPosition.X > 0 && !scrolling)
                {
                    trevorPosition.X -= 1;
                }
                // we are scrolling, keep player in center of screen
                if (viewPosX < 0 && trevorPosition.X >= 300)
                {
                    scrolling = true;
                    viewPosX += 1;
                    foreach (Candle c in candles)
                    {
                        c.location.X += 1;
                    }
                }
                // we are at left boundary, allow player to reach the edge by disabling scrolling
                if (viewPosX == 0)
                {
                    scrolling = false;
                }

                currentFrameY       = 0;
                timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
                if (timeSinceLastFrame > (timePerFrame / 3))
                {
                    timeSinceLastFrame -= (timePerFrame * 3);
                    if (currentFrameX < 80)
                    {
                        currentFrameX += 40;
                    }
                    else
                    {
                        currentFrameX = 0;
                    }
                }
            }
            #endregion

            #region Handle jumping...
            if (keyState.IsKeyDown(Keys.Space) && !jumping)
            {
                jumping           = true;
                trevorPosition.Y -= 100;
            }
            else if (keyState.IsKeyUp(Keys.Space))
            {
                if (viewPosX < -807 && viewPosX > -900)
                {
                    jumping = false;
                }

                else if (viewPosX < -900 && viewPosX > -1000)
                {
                    if (trevorPosition.Y < 224)
                    {
                        trevorPosition.Y += 1;
                    }
                    jumping = false;
                }
                else if (trevorPosition.Y < 400)
                {
                    trevorPosition.Y += 4;
                }
                else if (trevorPosition.Y >= 400)
                {
                    jumping = false;
                }
            }
            #endregion

            #region Weapon handling
            if (keyState.IsKeyDown(Keys.D))
            {
                if (!weapon)
                {
                    position = (int)trevorPosition.X;
                    weapon   = true;
                }
            }

            if (weapon)
            {
                fireWeapon();
            }
            #endregion

            // Move the Medusa sprite by speed, scaled by elapsed time
            medusaPosition.X += medusaSpeed.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
            medusaPosition.Y  = medusaPosition.Y + (-(float)Math.Acos(medusaPosition.X / 25) * 10);

            base.Update(gameTime);
        }
Example #2
0
 protected override void Update(GameTime gameTime)
 {
     back.Update(gameTime.ElapsedGameTime.Ticks);
     base.Update(gameTime);
 }
Example #3
0
 public override void Update(GameTime gameTime)
 {
     animation.Update(gameTime.ElapsedGameTime.Ticks * (int)(speedControl / 2));
     base.Update(gameTime);
 }