예제 #1
0
        /// <summary>
        /// Shoots a puff of smoke. If too many puffs of smoke have already been fired, the oldest one vanishes and
        /// is replaced with a new one.
        /// </summary>
        private void ShootSmoke()
        {
            SmokePuff availableSmokePuff;

            if (availableSmokePuffs.Count > 0)
            {
                // Take a smoke puff from the pool
                availableSmokePuff = availableSmokePuffs.Pop();
            }
            else
            {
                // Take the oldest smoke puff and use it
                availableSmokePuff = FiredSmokePuffs.Dequeue();
            }

            Vector2 beeKeeperCenter      = Bounds.Center.GetVector();
            Vector2 smokeInitialPosition = beeKeeperCenter;

            availableSmokePuff.Fire(smokeInitialPosition, GetSmokeVelocityVector());
            FiredSmokePuffs.Enqueue(availableSmokePuff);
        }
예제 #2
0
        /// <summary>
        /// Updates the beekeeper's status.
        /// </summary>
        /// <param name="gameTime">Game time information</param>
        public override void Update(GameTime gameTime)
        {
            if (!(gamePlayScreen.IsActive))
            {
                base.Update(gameTime);
                return;
            }

            if (IsCollectingHoney)
            {
                // We want this animation to use a sub animation
                // So must calculate when to call the sub animation
                if (collectiongHoneyFrameCounter > 3)
                {
                    AnimationDefinitions[BeekeeperCollectingHoneyAnimationKey].Update(gameTime, true, true);
                }
                else
                {
                    AnimationDefinitions[BeekeeperCollectingHoneyAnimationKey].Update(gameTime, true, false);
                }

                collectiongHoneyFrameCounter++;
            }
            else
            {
                collectiongHoneyFrameCounter = 0;
            }


            if (isDepositingHoney)
            {
                if (depositHoneyUpdatingTimer == TimeSpan.Zero)
                {
                    depositHoneyUpdatingTimer = gameTime.TotalGameTime;
                }

                AnimationDefinitions[BeekeeperDesposingHoneyAnimationKey].Update(gameTime, true);
            }

            // The oldest smoke puff might have expired and should therefore be recycled
            if ((FiredSmokePuffs.Count > 0) && (FiredSmokePuffs.Peek().IsGone))
            {
                availableSmokePuffs.Push(FiredSmokePuffs.Dequeue());
            }

            // If the beeKeeper is stung by a bee we want to create a flashing
            // effect.
            if (isStung || isFlashing)
            {
                stungDrawingCounter++;

                if (stungDrawingCounter > stungDrawingInterval)
                {
                    stungDrawingCounter      = 0;
                    isDrawnLastStungInterval = !isDrawnLastStungInterval;
                }
                // if time is up, end the flashing effect
                if (stungTime + stungDuration < gameTime.TotalGameTime)
                {
                    isStung = false;

                    if (stungTime + stungDuration + flashingDuration < gameTime.TotalGameTime)
                    {
                        isFlashing          = false;
                        stungDrawingCounter = -1;
                    }

                    AnimationDefinitions[LegAnimationKey].Update(gameTime, IsInMotion);
                }
            }
            else
            {
                AnimationDefinitions[LegAnimationKey].Update(gameTime, IsInMotion);
            }

            if (needToShootSmoke)
            {
                AnimationDefinitions[SmokeAnimationKey].Update(gameTime, needToShootSmoke);

                shootSmokePuffTimer -= gameTime.ElapsedGameTime;
                if (shootSmokePuffTimer <= TimeSpan.Zero)
                {
                    ShootSmoke();
                    shootSmokePuffTimer = shootSmokePuffTimerInitialValue;
                }
            }

            base.Update(gameTime);
        }