コード例 #1
0
ファイル: Game1.cs プロジェクト: danielsbonnin/cscheckers
        /// <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)
        {
            // TODO: Add your update logic here

            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            game.mouseHandler();
            redCheckAnimated.UpdateFrame(elapsed);
            base.Update(gameTime);
        }
コード例 #2
0
ファイル: Food.cs プロジェクト: ebshimizu/Parchment-Dragon
 public virtual void Update(GameTime gameTime, Rectangle stagingArea, Rectangle fieldBound)
 {
     // Update the animation.
     foodImage.UpdateFrame((float)gameTime.ElapsedGameTime.TotalSeconds);
     // Make the food move.
     Move();
     // If the food moves out of the staging area make it not in play.
     if (!stagingArea.Intersects(getRect()))
     {
         inPlay = false;
     }
 }
コード例 #3
0
        public virtual void Update(GameTime gameTime, Rectangle enemyFieldBound, Rectangle fieldBound)
        {
            // Toggles between alive animation states and dead animation states.
            if (alive)
            {
                spriteAlive.UpdateFrame((float)gameTime.ElapsedGameTime.TotalSeconds);
                time.update(gameTime);
            }
            if (!alive)
            {
                animating = spriteDead.UpdateFrameOnce((float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            // Handles when enemy moves off screen. Otherwise subclasses must implement other update tasks.
            if (!enemyFieldBound.Intersects(getRect()))
            {
                alive = false;
            }
            foreach (Bullet bullet in bullets)
            {
                bullet.Update(fieldBound);
            }
        }
コード例 #4
0
        // Update method for player character. Note that it does not replace the
        // update method in Game1.cs
        public void Update(GameTime gameTime)
        {
            if (gaugeLevel <= .25f)
            {
                multiplier = 1;
            }
            else if (.25 < gaugeLevel & gaugeLevel <= .6f)
            {
                multiplier = 2;
            }
            else if (.6f < gaugeLevel & gaugeLevel <= .85f)
            {
                multiplier = 3;
            }
            else if (gaugeLevel > .85f)
            {
                multiplier = 4;
            }
            if (alive || respawning)
            {
                // Decrease the food gauge by ~2.5% per second.
                gaugeLevel -= .00035f;

                // Get new keyboard state and assign it to PC keyboard state.
                keyboardState = Keyboard.GetState();
                gamePadState  = GamePad.GetState(PlayerIndex.One);

                // Call to PC move method.
                Move();

                // Call to PC fire method.
                Fire();

                // Update previous keyboard state.
                prevKeyboardState = keyboardState;
                flySprite.UpdateFrame((float)gameTime.ElapsedGameTime.TotalSeconds);
                // Make sure gauge can't fall below 0 or above 1.
                gaugeLevel = MathHelper.Clamp(gaugeLevel, 0, 1.0f);
            }
            else
            {
                // If we're not respawning we're dying. This call evaluates to !(true) while the death animation is still going.
                // Once we're done animating the death sprite, we're now in respawn mode.
                respawning = !(deathSprite.UpdateFrameOnce((float)gameTime.ElapsedGameTime.TotalSeconds));
            }
            // Respawn function.
            if (respawning)
            {
                // If you're out of lives, this runs once and nothing happens except that you're completely dead at this point.
                if (lives <= 0)
                {
                    respawning    = false;
                    doneAnimating = true;
                }
                // Increment the counter to know when to come back in.
                respawnCounter++;
                // Keep updating the flying animation for continuity.
                flySprite.UpdateFrame((float)gameTime.ElapsedGameTime.TotalSeconds);

                // If we have enough lives, put the player back in the default position after 1.5 seconds.
                if (lives > 0 && respawnCounter == respawnTime)
                {
                    position = new Vector2(viewportRect.Width / 2 - (width / 2), viewportRect.Height * .9f);
                }
                // After another 1.5 seconds, if the palyer has enough lives, take away the invincibility.
                // Collsisions are checked in Collisions.cs which uses the respawning boolean to figure out whether to count the hits.
                if (lives > 0 && respawnCounter == respawnTime * 2)
                {
                    respawning        = false;
                    alive             = true;
                    deathSprite.Frame = 0;
                }
            }

            // Update fireballs by calling each one.
            foreach (Bullet fireball in fireballs)
            {
                fireball.Update(viewportRect);
            }
        }