예제 #1
0
 public void Update()
 {
     if (isActive)
     {
         // move projectile
         transform.Translate(movementVector);
         hitData.hitboxBounds = transform.GetRenderPosition(hitData.hitboxBounds);
         // check for hit
         if (otherHitResolver.CheckForHit(hitData))
         {
             Dissipate();
             if (optionalFunction != null)
             {
                 optionalFunction();
             }
         }
     }
 }
예제 #2
0
        // runs the current step of the attack
        // returns true if the attack has finished, false if it is still going on
        public bool NextStep(Vector2 direction)
        {
            currentStep++;

            if (currentStep <= totalSteps && actionFrames.ContainsKey(currentStep))
            {
                // move
                if (actionFrames[currentStep].isMovement)
                {
                    playerMovement.MoveTowards(actionFrames[currentStep].movementTranslation);
                }

                // activate hitbox
                if (actionFrames[currentStep].isAttack)
                {
                    // check if this is the first frame of an attack and mark its id
                    // else set the following active frame ids to the same as the previous
                    if (!actionFrames.ContainsKey(currentStep - 1) || !actionFrames[currentStep - 1].isAttack)
                    {
                        actionFrames[currentStep].hitbox.moveCurrentUseID++;
                    }
                    else
                    {
                        actionFrames[currentStep].hitbox.moveCurrentUseID = actionFrames[currentStep - 1].hitbox.moveCurrentUseID;
                    }

                    actionFrames[currentStep].hitbox.hitboxBounds = Transform.GetCustomRenderPosition(actionFrames[currentStep].hitbox.hitboxBounds, new Vector2(parentTransform.position.X + (actionFrames[currentStep].hitbox.positionOffset.X * direction.X), parentTransform.position.Y + actionFrames[currentStep].hitbox.positionOffset.Y));
                    // check for hit
                    if (otherHitResolver.CheckForHit(actionFrames[currentStep].hitbox))
                    {
                        //TODO: fix cancel state for invincible
                        playerMovement.cancelState = actionFrames[currentStep].hitbox.cancelStrength;
                        // run optional hit function when we have made contact
                        if (actionFrames[currentStep].optionalHitFunction != null)
                        {
                            actionFrames[currentStep].optionalHitFunction();
                        }
                    }
                }


                // run optional function
                if (actionFrames[currentStep].optionalFunction != null)
                {
                    actionFrames[currentStep].optionalFunction();
                }

                // run optional sound effect if it exists
                if (actionFrames[currentStep].optionalSound != null)
                {
                    actionFrames[currentStep].optionalSound.Play();
                }
            }

            // when move is over return true and reset cancel state
            if (currentStep >= totalSteps)
            {
                playerMovement.cancelState = CancelState.none;
                return(true);
            }
            return(false);
        }