Exemplo n.º 1
0
    System.Func <Vector3, Vector2> SwitchDirection(WalkingDirection direction)
    {
        System.Func <Vector3, Vector2> value;
        switch (direction)
        {
        case WalkingDirection.left:
            value = WalkLeft;
            break;

        case WalkingDirection.right:
            value = WalkRight;
            break;

        case WalkingDirection.up:
            value = WalkUp;
            break;

        case WalkingDirection.down:
            value = WalkDown;
            break;

        default:
            return(null);
        }
        return(value);
    }
Exemplo n.º 2
0
    public override void _PhysicsProcess(float delta)
    {
        velocity.x  = 0;
        velocity.y += Overlord.STANDARD_GRAVITY;
        if (parent.TestMove(parent.Transform, velocity) &&
            !parent.TestMove(parent.Transform, new Vector2(speed * 5 * (int)direction, velocity.y))
            )
        {
            direction = direction == WalkingDirection.Left ? WalkingDirection.Right : WalkingDirection.Left;
            changeDirection((int)direction);
        }
        velocity.x = speed * (int)direction;

        var collision = parent.MoveAndSlide(velocity);

        if (Math.Abs(collision.x) < speed)
        {
            direction = direction == WalkingDirection.Left ? WalkingDirection.Right : WalkingDirection.Left;
            changeDirection((int)direction);
        }
        if (collision.y == 0)
        {
            velocity.y = 0;
        }
    }
Exemplo n.º 3
0
 protected CurveWalker(Curve curve, XYZ initPosition = null,
                       WalkingDirection direction    = WalkingDirection.StartToEnd)
 {
     WalkingCurve    = curve;
     CurrentPosition = initPosition ?? WalkingCurve.GetEndPoint(0);
     Direction       = direction;
 }
Exemplo n.º 4
0
    Vector3 VectorDirectiod(WalkingDirection dir)
    {
        Vector3 tmp;

        if (dir == WalkingDirection.up)
        {
            tmp = Vector3.up;
        }
        else if (dir == WalkingDirection.down)
        {
            tmp = Vector3.down;
        }
        else if (dir == WalkingDirection.left)
        {
            tmp = Vector3.left;
        }
        else if (dir == WalkingDirection.right)
        {
            tmp = Vector3.right;
        }
        else
        {
            tmp = Vector3.zero;
        }
        return(tmp);
    }
Exemplo n.º 5
0
        public void OnFire(int playerIndex, Vector2 position, WalkingDirection walkingDirection)
        {
            var bullet = new BulletSprite(bulletTexture, position, walkingDirection, playerIndex);

            bullet.font = HUDFont;
            bulllets.Add(bullet);
        }
        public void Update(GameTime gameTime, WalkingDirection newWalkingDirection)
        {
            if (newWalkingDirection == WalkingDirection.Idle)
            {
                walkingDirection = WalkingDirection.Idle;
                currentAnimation.Stop();
            }
            else if (newWalkingDirection != walkingDirection)
            {
                walkingDirection = newWalkingDirection;
                currentAnimation.Stop();

                if (newWalkingDirection == WalkingDirection.Down)
                {
                    currentAnimation = Down;
                }
                if (newWalkingDirection == WalkingDirection.Up)
                {
                    currentAnimation = Up;
                }
                if (newWalkingDirection == WalkingDirection.Left)
                {
                    currentAnimation = Left;
                }
                if (newWalkingDirection == WalkingDirection.Right)
                {
                    currentAnimation = Right;
                }

                currentAnimation.Start(Repeat.Mode.Loop);
            }

            currentAnimation.Update(gameTime);
        }
    public void PlayFootFeedbackSound()
    {
        WalkingDirection direction = CurrentWalkingDirection;

        // FEEDBACK : PLAY WALK SOUND
        FxManager.Instance.PlayFx(walkFxTag, transform.position, Quaternion.Euler(0, 0, direction == WalkingDirection.Right ? 135 : 45), Vector3.one);
    }
 public ChangeDirectionEventArgs(WalkingDirection walkingDirection, int iterUpFrame, int iterDownFrame, int iterRightFrame, int iterLeftFrame)
 {
     WalkingDirection = walkingDirection;
     IterUpFrame      = iterUpFrame;
     IterDownFrame    = iterDownFrame;
     IterLeftFrame    = iterLeftFrame;
     IterRightFrame   = iterRightFrame;
 }
Exemplo n.º 9
0
 private void MainCharacter_ChangePosition(object sender, ChangeDirectionEventArgs e)
 {
     IterUpFrame      = e.IterUpFrame;
     IterDownFrame    = e.IterDownFrame;
     IterLeftFrame    = e.IterLeftFrame;
     IterRightFrame   = e.IterRightFrame;
     walkingDirection = e.WalkingDirection;
 }
Exemplo n.º 10
0
        public Node(Point position, WalkingDirection walkingDirection)
        {
            this.Position         = position;
            this.walkingDirection = walkingDirection;

            G      = H = F = 0;
            parent = null;
        }
Exemplo n.º 11
0
 public BulletSprite(Texture2D texture, Vector2 startingPosition, WalkingDirection direction, int bulletOwner) : base(texture,
                                                                                                                      startingPosition)
 {
     this.bulletOwner = bulletOwner;
     this.direction   = direction;
     frameHeight      = texture.Height;
     frameWidth       = texture.Width;
     origin           = new Vector2(texture.Width / 2f, texture.Height / 2f);
 }
Exemplo n.º 12
0
 public MainCharacter(Game game, Texture2D texture, Vector2 beginPosition, Rectangle window) : base(game)
 {
     textureMainCharacter = texture;
     Position             = beginPosition;
     this.window          = window;
     walkingDirection     = WalkingDirection.Right;
     RectangleInitialize();
     sizeOfSprite         = new Rectangle(0, 0, upFrameOfTextureMC[0].Width, upFrameOfTextureMC[0].Height);
     this.ChangePosition += MainCharacter_ChangePosition;
 }
Exemplo n.º 13
0
 void Start()                                    //вызывается на старте игры
 {
     countExistenceChangeDirection = 0;
     fall            = 0;
     _direction      = WalkingDirection.idle;    //присваеваем на старте стоять на месте
     changeDirection = WalkingDirection.idle;
     _V3Left         = new Vector3(-changePos, 0, 0);
     _V3Right        = new Vector3(changePos, 0, 0);
     _V3Up           = new Vector3(0, changePos, 0);
     _V3Down         = new Vector3(0, -changePos, 0);
 }
Exemplo n.º 14
0
    void Update()
    {
        if (Time.time - fall >= fallspeed && _direction != WalkingDirection.idle)
        {
            Vector3 updatePosition = transform.localPosition;
            Vector3 tempPosition;
            bool    checkGoSide = false;
            if (changeDirection != WalkingDirection.idle && IntegerCheck(updatePosition))
            {
                if (countExistenceChangeDirection <= 1)
                {
                    tempPosition = goSide(AlignPosition(updatePosition, changeDirection));
                    if (_borderBlock.CheckWalk(tempPosition, VectorDirectiod(changeDirection)))
                    {
                        updatePosition = tempPosition;
                        checkGoSide    = true;
                    }
                    countExistenceChangeDirection++;
                }
                else
                {
                    NullifyTurn();
                }
            }
            if (!checkGoSide)
            {
                tempPosition = goAhead(updatePosition);
                if (_borderBlock.CheckWalk(tempPosition, VectorDirectiod(_direction)))
                {
                    updatePosition = tempPosition;
                }
                else
                {
                    _direction = WalkingDirection.idle;
                    NullifyTurn();
                    updatePosition = new Vector3(Mathf.Round(updatePosition.x), Mathf.Round(updatePosition.y), updatePosition.z);
                }
            }
            else
            {
                _direction = changeDirection;
                goAhead    = goSide;
                NullifyTurn();
            }

            transform.localPosition = updatePosition;
            fall = Time.time;
        }
    }
Exemplo n.º 15
0
 // Update is called once per frame
 void Update()
 {
     if (!m_IsEatingFood)
     {
         m_WalkingTime -= Time.deltaTime;
         int direction = m_WalkingDirection == WalkingDirection.Left ? -1 : 1;
         this.transform.Translate(direction * m_WalkingSpeed, 0.0f, 0.0f);
         if (m_WalkingTime <= 0.0f)
         {
             m_WalkingTime      = 4.0f;
             m_WalkingDirection = (WalkingDirection)(((int)(m_WalkingDirection) + 1) & 1);
             m_Animator.SetInteger("walkingDirection", (int)m_WalkingDirection);
         }
     }
 }
Exemplo n.º 16
0
        /// <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);
            }
        }
Exemplo n.º 17
0
        void updateMovement(GameTime gameTime)
        {
            var keyboardState = Keyboard.GetState();
            var pressedKeys   = keyboardState.GetPressedKeys();

            int   pixelsPerSecond = 100;
            float movementSpeed   = (float)(pixelsPerSecond * (gameTime.ElapsedGameTime.TotalSeconds));

            Vector2 movementVector = Vector2.Zero;

            if (pressedKeys.Length == 0)
            {
                whichFrame = 0;
                currentWalkingDirection = WalkingDirection.down;
            }
            else
            {
                if (keyboardState.IsKeyDown(Keys.A))
                {
                    if (!isTouchingLeft)
                    {
                        movementVector += new Vector2(-movementSpeed, 0);
                    }
                    currentWalkingDirection = WalkingDirection.left;
                }

                else if (keyboardState.IsKeyDown(Keys.D))
                {
                    if (!isTouchingRight)
                    {
                        movementVector += new Vector2(movementSpeed, 0);
                    }
                    currentWalkingDirection = WalkingDirection.right;
                }

                if (keyboardState.IsKeyDown(Keys.Space))
                {
                    Jump();
                }

                position += movementVector;
            }
        }
Exemplo n.º 18
0
 protected void MoveDown(Keys keys)
 {
     if (Keyboard.GetState().IsKeyDown(keys))
     {
         walkingDirection = WalkingDirection.Down;
         if (Position.Y < window.Bottom)
         {
             Position.Y += 5;
             if (IterDownFrame < downFrameOfTextureMC.Length - 1)
             {
                 IterDownFrame++;
             }
             else
             {
                 IterDownFrame = 0;
             }
         }
     }
 }
Exemplo n.º 19
0
 protected void MoveLeft(Keys keys)
 {
     if (Keyboard.GetState().IsKeyDown(keys))
     {
         if (Position.X > window.Left)
         {
             walkingDirection = WalkingDirection.Left;
             Position.X      -= 5;
             if (IterLeftFrame < leftFrameOfTextureMC.Length - 1)
             {
                 IterLeftFrame++;
             }
             else
             {
                 IterLeftFrame = 0;
             }
         }
     }
 }
Exemplo n.º 20
0
 protected void MoveRight(Keys keys)
 {
     if (Keyboard.GetState().IsKeyDown(keys))
     {
         if (Position.X < window.Right)
         {
             walkingDirection = WalkingDirection.Right;
             Position.X      += 5;
             if (IterRightFrame < rightFrameOfTextureMC.Length - 1)
             {
                 IterRightFrame++;
             }
             else
             {
                 IterRightFrame = 0;
             }
         }
     }
 }
Exemplo n.º 21
0
 protected void MoveUp(Keys keys)
 {
     if (Keyboard.GetState().IsKeyDown(keys))
     {
         walkingDirection = WalkingDirection.Up;
         if (Position.Y > window.Top)
         {
             Position.Y -= 5;
             if (IterUpFrame < upFrameOfTextureMC.Length - 1)
             {
                 IterUpFrame++;
             }
             else
             {
                 IterUpFrame = 0;
             }
         }
     }
 }
Exemplo n.º 22
0
 /// <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;
         }
     }
 }
Exemplo n.º 23
0
 /// <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="tempDirection">Enum describing the input direction.</param>
 /// <param name="smokeAjustment">Adjustment to smoke position according to input direction.</param>
 private void DetermineDirectionDominantY(ref WalkingDirection tempDirection, ref Vector2 smokeAjustment)
 {
     if (VirtualThumbsticks.LeftThumbstick.Y > 0)
     {
         if (VirtualThumbsticks.LeftThumbstick.X > 0.25f)
         {
             tempDirection  = WalkingDirection.RightDown;
             smokeAjustment = new Vector2(85, 0);
         }
         else if (VirtualThumbsticks.LeftThumbstick.X < -0.25f)
         {
             tempDirection  = WalkingDirection.LeftDown;
             smokeAjustment = new Vector2(-85, 0);
         }
         else
         {
             tempDirection  = WalkingDirection.Down;
             smokeAjustment = Vector2.Zero;
         }
     }
     else
     {
         if (VirtualThumbsticks.LeftThumbstick.X > 0.25f)
         {
             tempDirection  = WalkingDirection.RightUp;
             smokeAjustment = new Vector2(85, 30);
         }
         else if (VirtualThumbsticks.LeftThumbstick.X < -0.25f)
         {
             tempDirection  = WalkingDirection.LeftUp;
             smokeAjustment = new Vector2(-85, 30);
         }
         else
         {
             tempDirection  = WalkingDirection.Up;
             smokeAjustment = Vector2.Zero;
         }
     }
 }
Exemplo n.º 24
0
 internal void DirectionSelection(WalkingDirection direction)
 {
     if (direction == _direction)
     {
         return;
     }
     if (_direction == WalkingDirection.idle)
     {
         _direction = direction;
         goAhead    = SwitchDirection(_direction);
     }
     else
     {
         if (changeDirection != direction)
         {
             //checkedChangeDirection = false;
             changeDirection = direction;
             goSide          = SwitchDirection(changeDirection);
         }
         countExistenceChangeDirection = 0;
     }
 }
Exemplo n.º 25
0
        /// <summary>
        /// Returns movement information according to the current virtual thumbstick input.
        /// </summary>
        /// <param name="tempDirection">Enum describing the inpot direction.</param>
        /// <param name="smokeAjustment">Adjustment to smoke position according to input direction.</param>
        private void DetermineDirection(ref WalkingDirection tempDirection, ref Vector2 smokeAjustment)
        {
            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))
                {
                    DetermineDirectionDominantX(ref tempDirection, ref smokeAjustment);
                }
                else
                {
                    DetermineDirectionDominantY(ref tempDirection, ref smokeAjustment);
                }
            }
        }
Exemplo n.º 26
0
        void updateInput()
        {
            var keyboardState = Keyboard.GetState();
            var pressedKeys   = keyboardState.GetPressedKeys();

            isMoving = false;
            isFiring = false;
            if (pressedKeys.Length != 0)
            {
                foreach (var Key in pressedKeys)
                {
                    if (keyMap.left.Equals(Key))
                    {
                        currentWalkingDirection = WalkingDirection.left;
                        isMoving = true;
                    }
                    else if (keyMap.right.Equals(Key))
                    {
                        currentWalkingDirection = WalkingDirection.right;
                        isMoving = true;
                    }
                    else if (keyMap.down.Equals(Key))
                    {
                        currentWalkingDirection = WalkingDirection.down;
                        isMoving = true;
                    }
                    else if (keyMap.up.Equals(Key))
                    {
                        currentWalkingDirection = WalkingDirection.up;
                        isMoving = true;
                    }
                    else if (keyMap.fire.Equals(Key))
                    {
                        isFiring = true;
                    }
                }
            }
        }
 public void InitGenericWalker(int _maxHealth, int _startingDamage, float _startingSpeed, float _startingAttackSpeed, WalkerType _type, EnemyWalkingTrack _myTrack, LayerMask _attackMask)
 {
     AttackLayerMask     = _attackMask;
     myTrack             = _myTrack;
     maxHealth           = _maxHealth;
     startingDamage      = _startingDamage;
     startingSpeed       = _startingSpeed;
     startingAttackSpeed = _startingAttackSpeed;
     myType         = _type;
     currentHealth  = maxHealth;
     nextTrackIndex = _type == WalkerType.Enemy ? 0 : _myTrack.Points - 1;
     alive          = true;
     if (myType == WalkerType.Enemy)
     {
         indexDiff = 1;
         if (myTrack.side == EnemyWalkingTrackSide.Left)
         {
             walkingDirection = WalkingDirection.Right;
         }
         else
         {
             walkingDirection = WalkingDirection.Left;
         }
     }
     else
     {
         indexDiff = -1;
         if (myTrack.side == EnemyWalkingTrackSide.Left)
         {
             walkingDirection = WalkingDirection.Left;
         }
         else
         {
             walkingDirection = WalkingDirection.Right;
         }
     }
 }
Exemplo n.º 28
0
        /// <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);
        }
Exemplo n.º 29
0
        /// <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);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Renders the beekeeper.
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Draw(GameTime gameTime)
        {
            if (!(gamePlayScreen.IsActive))
            {
                base.Draw(gameTime);
                return;
            }

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

            spriteBatch.Begin();

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

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


            if (isDepositingHoney)
            {
                if (VirtualThumbsticks.LeftThumbstick != 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[BeekeeperDesposingHoneyAnimationKey].Draw(spriteBatch, position,
                                                                               SpriteEffects.None);

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

                spriteBatch.End();
                return;
            }

            bool             hadDirectionChanged = false;
            WalkingDirection tempDirection       = direction;

            DetermineDirection(ref tempDirection, ref smokeAdjustment);

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

            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(spriteBatch, position, 1f, SpriteEffects.None);


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

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

            base.Draw(gameTime);
        }
Exemplo n.º 31
0
        public static void Draw(SpriteBatch spriteBatch, GameTime gameTime, MovingEntity movingEntity)
        {
            var livingEntityType = LivingEntityType.lookup[movingEntity.LivingEntityType];
            WalkingDirection newWalkingDirection = MovementUtils.GetWalkingDirectionFromVector(movingEntity.Direction);

            movingEntity.RendererInformation.Update(gameTime, newWalkingDirection);

            if (!movingEntity.IsWalking)
            {
                movingEntity.RendererInformation.currentAnimation.Reset();
            }

            var adjustedYPosition = movingEntity.Position.Y + movingEntity.YPositionDepthOffset;

            if (movingEntity.IsDead())
            {
                movingEntity.RendererInformation.Update(gameTime, WalkingDirection.Left);
                movingEntity.RendererInformation.currentAnimation.Reset();

                spriteBatch.Draw(movingEntity.RendererInformation.currentAnimation, new Vector2((int)movingEntity.Position.X, (int)movingEntity.Position.Y), rotation: MathHelper.Pi / 2, color: Color.White, layerDepth: GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X, adjustedYPosition));
            }
            else
            {
                spriteBatch.Draw(movingEntity.RendererInformation.currentAnimation, new Vector2((int)movingEntity.Position.X, (int)movingEntity.Position.Y), color: Color.White, layerDepth: GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X, adjustedYPosition));
            }

            // Draw Speech Bubble
            if (movingEntity.RendererInformation.SpeechLine != null)
            {
                var depth  = GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X, adjustedYPosition);
                var depth2 = GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X + 1, adjustedYPosition);

                var bubbleYOffset = (int)movingEntity.Position.Y - livingEntityType.SpriteBounds.Y - 20;

                var stringWidth      = font.MeasureString(movingEntity.RendererInformation.SpeechLine).X;
                var bubbleWidth      = stringWidth - 8;
                var bubbleStartPos   = new Vector2((int)movingEntity.Position.X - 10 - bubbleWidth, bubbleYOffset);
                var bubbleContentPos = new Vector2((int)movingEntity.Position.X - bubbleWidth, bubbleYOffset);
                var bubbleEndPos     = new Vector2((int)movingEntity.Position.X - 10, bubbleYOffset);

                // Draw bubble start
                spriteBatch.Draw(SimulationGame.ContentManager.Load <Texture2D>(@"GUI\SpeechBubble"), bubbleStartPos, new Rectangle(0, 0, 10, 27), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, depth);

                // Draw bubble content
                spriteBatch.Draw(SimulationGame.ContentManager.Load <Texture2D>(@"GUI\SpeechBubble"), bubbleContentPos, new Rectangle(10, 0, 20, 27), Color.White, 0.0f, Vector2.Zero, new Vector2((stringWidth - 18) / 20.0f, 1.0f), SpriteEffects.None, depth);

                // Draw string
                spriteBatch.DrawString(font, movingEntity.RendererInformation.SpeechLine, new Vector2(bubbleContentPos.X, bubbleYOffset + 5), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, depth2);

                // Draw bubble end
                spriteBatch.Draw(SimulationGame.ContentManager.Load <Texture2D>(@"GUI\SpeechBubble"), bubbleEndPos, new Rectangle(110, 0, 27, 27), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, depth);
            }

            // Draw Health
            if (movingEntity.CurrentLife < movingEntity.MaximumLife)
            {
                spriteBatch.Draw(healthTexture, new Vector2(movingEntity.Position.X - livingEntityType.SpriteBounds.X / 2, movingEntity.Position.Y - livingEntityType.SpriteBounds.Y),
                                 new Rectangle(0, 0, 1, 1), Color.Red, 0.0f, Vector2.Zero, new Vector2(((float)movingEntity.CurrentLife / (float)movingEntity.MaximumLife) * livingEntityType.SpriteBounds.X, 2.0f), SpriteEffects.None, GeometryUtils.GetLayerDepthFromPosition(movingEntity.Position.X, adjustedYPosition));
            }

            if (SimulationGame.IsDebug)
            {
                if (movingEntity.IsBlocking())
                {
                    SimulationGame.PrimitiveDrawer.Rectangle(movingEntity.UnionBounds.ToXnaRectangle(), Color.Red);
                }
                else if (movingEntity.IsHitable())
                {
                    SimulationGame.PrimitiveDrawer.Rectangle(movingEntity.HitBoxBounds.ToXnaRectangle(), Color.White);
                    SimulationGame.PrimitiveDrawer.Rectangle(movingEntity.BlockingBounds.ToXnaRectangle(), Color.Red);
                }
            }
        }
Exemplo n.º 32
0
        /// <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);
            }
        }
Exemplo n.º 33
0
 /// <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;
         }
     }
 }
Exemplo n.º 34
0
 Vector3 AlignPosition(Vector3 pos, WalkingDirection dir)
 {
     return((dir == WalkingDirection.up || dir == WalkingDirection.down) ?
            new Vector3(Mathf.Round(pos.x), pos.y, pos.z) : new Vector3(pos.x, Mathf.Round(pos.y), pos.z));
 }
Exemplo n.º 35
0
        /// <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;
                }
            }
        }
Exemplo n.º 36
0
 public void Walk(WalkingDirection direction)
 {
 }