コード例 #1
0
ファイル: Mobile.cs プロジェクト: deccer/ValhallaClone
 public void Walk(WalkingDirection direction)
 {
 }
コード例 #2
0
ファイル: BeeKeeper.cs プロジェクト: Nailz/MonoGame-Samples
 /// <summary>
 /// Returns movement information according to the current virtual thumbstick input, given that advancement
 /// along the Y axis is greater than along the X axis.
 /// </summary>
 /// <param name="movement">Vector indicating the current beekeeper movement.</param>      
 /// <param name="tempDirection">Enum describing the input direction.</param>
 /// <param name="smokeAdjustment">Adjustment to smoke position according to input direction.</param>
 private void DetermineDirectionDominantY(Vector2 movement, ref WalkingDirection tempDirection,
     ref Vector2 smokeAdjustment)
 {
     if (movement.Y > 0)
     {
         if (movement.X > 0.25f)
         {
             tempDirection = WalkingDirection.RightDown;
             smokeAdjustment = new Vector2(UIConstants.SprayRightOffset, UIConstants.SprayDownOffset);
         }
         else if (movement.X < -0.25f)
         {
             tempDirection = WalkingDirection.LeftDown;
             smokeAdjustment = new Vector2(-UIConstants.SprayLeftOffset, UIConstants.SprayDownOffset);
         }
         else
         {
             tempDirection = WalkingDirection.Down;
             smokeAdjustment = Vector2.Zero;
         }
     }
     else
     {
         if (movement.X > 0.25f)
         {
             tempDirection = WalkingDirection.RightUp;
             smokeAdjustment = new Vector2(UIConstants.SprayRightOffset, UIConstants.SprayUpOffset);
         }
         else if (movement.X < -0.25f)
         {
             tempDirection = WalkingDirection.LeftUp;
             smokeAdjustment = new Vector2(-UIConstants.SprayLeftOffset, UIConstants.SprayUpOffset);
         }
         else
         {
             tempDirection = WalkingDirection.Up;
             smokeAdjustment = Vector2.Zero;
         }
     }
 }
コード例 #3
0
ファイル: BeeKeeper.cs プロジェクト: Nailz/MonoGame-Samples
        /// <summary>
        /// Returns movement information according to the current virtual thumbstick input.
        /// </summary>
        /// <param name="movement">Vector indicating the current beekeeper movement.</param>
        /// <param name="tempDirection">Enum describing the inpot direction.</param>
        /// <param name="smokeAdjustment">Adjustment to smoke position according to input direction.</param>
        private void DetermineDirection(Vector2 movement, ref WalkingDirection tempDirection,
            ref Vector2 smokeAdjustment)
        {
            if (movement == Vector2.Zero)
            {
                return;
            }

            if (Math.Abs(movement.X) > Math.Abs(movement.Y))
            {
                DetermineDirectionDominantX(movement, ref tempDirection, ref smokeAdjustment);
            }
            else
            {
                DetermineDirectionDominantY(movement, ref tempDirection, ref smokeAdjustment);
            }
        }
コード例 #4
0
ファイル: BeeKeeper.cs プロジェクト: Nailz/MonoGame-Samples
        /// <summary>
        /// Renders the beekeeper.
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Draw(GameTime gameTime)
        {
            if (!(gamePlayScreen.IsActive && gamePlayScreen.IsStarted))
            {
                base.Draw(gameTime);
                return;
            }

            // Make sure not to draw the beekeeper while flashing
            if (isStung || isFlashing)
            {
                if (stungDrawingCounter != stungDrawingInterval)
                {
                    if (isDrawnLastStungInterval)
                    {
                        return;
                    }
                }
            }

            scaledSpriteBatch.Begin();

            // if stung we want to show another animation
            if (isStung)
            {
                scaledSpriteBatch.Draw(Game.Content.Load<Texture2D>("Textures/hit"), position, Color.White);
                scaledSpriteBatch.End();
                return;
            }

            // If collecting honey, draw the appropriate animation
            if (IsCollectingHoney)
            {
                AnimationDefinitions[BeekeeperCollectingHoneyAnimationKey].Draw(scaledSpriteBatch, position,
                    SpriteEffects.None);
                scaledSpriteBatch.End();
                return;
            }


            if (isDepositingHoney)
            {
                if (velocity != Vector2.Zero)
                {
                    isDepositingHoney = false;
                    AudioManager.StopSound("DepositingIntoVat_Loop");
                }

                // We want the deposit duration to sync with the deposit  
                // animation
                // So we manage the timing ourselves
                if (depositHoneyUpdatingTimer != TimeSpan.Zero &&
                    depositHoneyUpdatingTimer + depositHoneyUpdatingInterval < gameTime.TotalGameTime)
                {
                    depositHoneyTimerCounter++;
                    depositHoneyUpdatingTimer = TimeSpan.Zero;
                }

                AnimationDefinitions[BeekeeperDepositingHoneyAnimationKey].Draw(scaledSpriteBatch, position,
                    SpriteEffects.None);

                if (depositHoneyTimerCounter == honeyDepositFrameCount - 1)
                {
                    isDepositingHoney = false;
                    depositHoneyCallback.Invoke(null);
                    AnimationDefinitions[BeekeeperDepositingHoneyAnimationKey].PlayFromFrameIndex(0);
                }

                scaledSpriteBatch.End();
                return;
            }

            bool hadDirectionChanged = false;

            // See if the direction changed
            if (newDirection != direction)
            {
                hadDirectionChanged = true;
                direction = newDirection;
            }

            if (hadDirectionChanged)
            {
                // Update the animation
                lastFrameCounter = 0;
                AnimationDefinitions[LegAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
                AnimationDefinitions[ShootingAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
                AnimationDefinitions[BodyAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
            }
            else
            {
                // Because our animation is 8 cells, but the row is 16 cells,
                // we need to reset the counter after 8 rounds

                if (lastFrameCounter == 8)
                {
                    lastFrameCounter = 0;
                    AnimationDefinitions[LegAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
                    AnimationDefinitions[ShootingAnimationKey].PlayFromFrameIndex(
                        lastFrameCounter + (int)direction);
                    AnimationDefinitions[BodyAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
                }
                else
                {
                    lastFrameCounter++;
                }
            }


            AnimationDefinitions[LegAnimationKey].Draw(scaledSpriteBatch, position, 1f, SpriteEffects.None);


            if (needToShootSmoke)
            {
                // Draw the body
                AnimationDefinitions[ShootingAnimationKey].Draw(scaledSpriteBatch, position, 1f, SpriteEffects.None);

                // If true we need to draw smoke
                if (smokeAdjustment != Vector2.Zero)
                {
                    AnimationDefinitions[SmokeAnimationKey].Draw(scaledSpriteBatch, position + smokeAdjustment, 1f,
                        currentEffect);
                }
            }
            else
            {
                AnimationDefinitions[BodyAnimationKey].Draw(scaledSpriteBatch, position, 1f, SpriteEffects.None);
            }
            scaledSpriteBatch.End();

            base.Draw(gameTime);
        }
コード例 #5
0
ファイル: Bomberman.cs プロジェクト: Lapuh1st/BoomGame
        /// <summary>
        /// Returns movement information according to the current virtual thumbstick input.
        /// </summary>
        /// <param name="tempDirection">
        /// Enum describing the inpot direction.
        /// </param>
        private void determineDirection(ref WalkingDirection tempDirection)
        {
            if (!VirtualThumbsticks.LeftThumbstickCenter.HasValue)
            {
                return;
            }

            Rectangle touchPointRectangle = new Rectangle((int)VirtualThumbsticks.LeftThumbstickCenter.Value.X, (int)VirtualThumbsticks.LeftThumbstickCenter.Value.Y, 1, 1);

            if (ThumbStickArea.Intersects(touchPointRectangle))
            {
                if (Math.Abs(VirtualThumbsticks.LeftThumbstick.X) > Math.Abs(VirtualThumbsticks.LeftThumbstick.Y))
                {
                    tempDirection = VirtualThumbsticks.LeftThumbstick.X > 0 ? WalkingDirection.Right : WalkingDirection.Left;
                }
                else
                {
                    tempDirection = VirtualThumbsticks.LeftThumbstick.Y > 0 ? WalkingDirection.Down : WalkingDirection.Up;
                }
            }
        }
コード例 #6
0
ファイル: Bomberman.cs プロジェクト: Lapuh1st/BoomGame
        /// <summary>
        /// Renders the beekeeper.
        /// </summary>
        /// <param name="gameTime">Game Time obj </param>
        public override void Draw(GameTime gameTime)
        {
            if (!(GamePlayScreen.IsActive && GamePlayScreen.IsStarted))
            {
                base.Draw(gameTime);
                return;
            }

            SpriteBatch.Begin();

            bool hadDirectionChanged = false;
            WalkingDirection tempDirection = direction;

            determineDirection(ref tempDirection);

            // Indicate the direction has changed
            if (tempDirection != direction)
            {
                hadDirectionChanged = true;
                direction = tempDirection;
            }

            if (hadDirectionChanged)
            {
                // Update the animation
                lastFrameCounter = 0;
                AnimationDefinitions[BOMBER_ANIMATION_KEY].PlayFromFrameIndex(lastFrameCounter + (int)direction);
            }
            else
            {
                // Because our animation is 10 cells, and the row is 10 cells,
                // we need to reset the counter after 10 rounds

                if (lastFrameCounter == 10)
                {
                    lastFrameCounter = 0;
                    AnimationDefinitions[BOMBER_ANIMATION_KEY].PlayFromFrameIndex(lastFrameCounter + (int)direction);
                }
                else
                {
                    lastFrameCounter++;
                }
            }

            AnimationDefinitions[BOMBER_ANIMATION_KEY].Draw(SpriteBatch, FramePosition, SpriteEffects.None, new Vector2(20, 5), ColisionAreaRect);

            SpriteBatch.End();

            base.Draw(gameTime);
        }