Пример #1
0
        public IGuyState Update(Guy guy, KeyboardState keyboardState, GameTime gameTime)
        {
            var maybeDirection = guy.Physics.HorizontalMovementDirection;

            if (maybeDirection.HasValue)
            {
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    guy.Facing = XDirection.Right;
                }
                else if (keyboardState.IsKeyDown(Keys.Left))
                {
                    guy.Facing = XDirection.Left;
                }
            }
            if (keyboardState.IsKeyDown(Keys.Down))
            {
                return(guy.States.Cannonball);
            }
            if (keyboardState.IsKeyDown(Keys.Up) && _entryTimeout.IsFinished(gameTime))
            {
                return(guy.States.Hooray);
            }
            if (!guy.Physics.IsOnGround)
            {
                return(null);
            }
            if (guy.Physics.IsMovingHorizontally)
            {
                return(guy.States.Running);
            }
            return(guy.States.Idle);
        }
 public override void Update(GameTime gameTime)
 {
     _particleSystem.Update(gameTime);
     if (_timer.IsFinished(gameTime))
     {
         _particleSystem.SpawnRandom(3);
         _timer.Reset(gameTime);
     }
 }
Пример #3
0
 public IGuyState Update(Guy guy, KeyboardState keyboardState, GameTime gameTime)
 {
     return(_timer.IsFinished(gameTime)
         ? guy.States.CannonballCrashRecovery
         : null);
 }
 public IGuyState Update(Guy guy, KeyboardState keyboardState, GameTime gameTime)
 {
     return(_timer.IsFinished(gameTime)
         ? guy.States.Idle
         : null);
 }
Пример #5
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape) ||
                Keyboard.GetState().IsKeyDown(Keys.Q))
            {
                Exit();
            }

            currentMouse = Mouse.GetState();

            var point = viewport.PointToScreen(currentMouse.X, currentMouse.Y);

            newGameRect  = new Rectangle(310, 20, newGame.Width, newGame.Height);
            newGameColor = Color.White;

            undoRect  = new Rectangle(310, 80, undo.Width, undo.Height);
            undoColor = Color.White;

            solveRect  = new Rectangle(310, 75, solve.Width, solve.Height);
            solveColor = Color.White;

            if (IsActive && table.isSetup && !table.isAnimating)
            {
                if (solveRect.Contains(point))
                {
                    solveColor = Color.Aqua;
                    if (table.gameState == GameState.complete && click)
                    {
                        table.solve = true;
                    }
                }

                if (newGameRect.Contains(point))
                {
                    newGameColor = Color.Aqua;

                    if (click)
                    {
                        gameWinPlaying = false;
                        table.NewGame(gameTime);

                        foreach (var card in table.drawPile.cards)
                        {
                            var location = "deck/" + card.suit + card.rank;
                            card.SetTexture(Content.Load <Texture2D>(location));
                        }

                        table.SetTable();
                    }
                }

                if (table.gameState == GameState.active && undoRect.Contains(point))
                {
                    undoColor = Color.Aqua;
                    if (click)
                    {
                        table.Undo(gameTime);
                    }
                }
                if (table.gameState == GameState.won && !gameWinPlaying)
                {
                    gameWinPlaying = true;
                    gameWinFX.Play();
                }
            }

#if DEBUG
            debugRect  = new Rectangle(310, 140, debug.Width, debug.Height);
            debugColor = Color.White;
            if (debugRect.Contains(point))
            {
                debugColor = Color.Aqua;
                if (click)
                {
                    foreach (var stack in table.stacks)
                    {
                        stack.debug();
                    }
                }
            }
#endif

            oldMouse = currentMouse;
            if (IsActive)
            {
                table.Update(gameTime);
            }

            if (table.gameState == GameState.won && !table.isAnimating)
            {
                // final confetti stuff
                if (transitionTimer.IsFinished(gameTime))
                {
                    spawningConfetti = !spawningConfetti;
                    transitionTimer.Reset(gameTime);
                    explosionPositions.Reset();
                    explosionTimer.Reset(gameTime);
                    spawnTimer.Reset(gameTime);
                }

                if (spawningConfetti)
                {
                    if (spawnTimer.IsFinished(gameTime))
                    {
                        confetti.Sprinkle(confettiRate, new Rectangle(0, -10, GraphicsDevice.Viewport.Width, 10));
                        spawnTimer.Reset(gameTime);
                    }
                }
                else
                {
                    if (explosionTimer.IsFinished(gameTime))
                    {
                        if (!Properties.Settings.Default.mute)
                        {
                            explosionPositions.TryDoWithCurrent(p => confetti.Explode(20, p, popFX));
                        }
                        else
                        {
                            explosionPositions.TryDoWithCurrent(p => confetti.Explode(20, p));
                        }
                        explosionTimer.Reset(gameTime);
                    }
                }
                confetti.Update(gameTime);
            }
            else
            {
                spawningConfetti = false;
                transitionTimer.Reset(gameTime);
                explosionPositions.Reset();
                explosionTimer.Reset(gameTime);
                spawnTimer.Reset(gameTime);
            }

            base.Update(gameTime);
        }