Beispiel #1
0
    private void HandleBoomJump()
    {
        Movement();
        if (canJump)
        {
            canJump = !canJump;
            OnPlayerJump?.Invoke(canJump);
            ExplosionAnimator.SetBool("isTriggered", true);
            // Trigger Explosion Sound Here
            BoomJumpSource.Play();
            RB.velocity = new Vector2(RB.velocity.x, 0);
            RB.AddForce(Vector2.up * explosiveForce, ForceMode2D.Impulse);
            // Damage player
            DamagePlayer(explosiveDamage);
        }

        Collider2D[] cols = Physics2D.OverlapCapsuleAll(ExplosionCollider.bounds.center, ExplosionCollider.size, CapsuleDirection2D.Horizontal, 0);
        foreach (Collider2D col in cols)
        {
            if (col.GetComponent <TNT>() != null)
            {
                TNT tnt = col.GetComponent <TNT>();
                tnt.Detonate(true);
            }
        }


        if (PlayerAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1)
        {
            if (!grounded)
            {
                SetState(PlayerStates.IN_AIR);
            }
        }
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Awake()
    {
        Player = this;

        psm = new Dictionary <PlayerStates, Action>
        {
            { PlayerStates.IDLE, HandleIdle },
            { PlayerStates.RUN, HandleRun },
            { PlayerStates.BOOM_JUMP, HandleBoomJump },
            { PlayerStates.IN_AIR, HandleInAir },
            { PlayerStates.WALL_GRAB, HandleWallGrab },
            { PlayerStates.BOOM_DEAD, HandleDead },
            { PlayerStates.SPIKE_DEAD, HandleDead },
            { PlayerStates.SUCCESS, HandleSuccess }
        };

        // Set players' starting state.
        SetState(PlayerStates.IDLE);

        animStates = new Dictionary <PlayerStates, string>()
        {
            { PlayerStates.IDLE, idleAnim },
            { PlayerStates.RUN, runAnim },
            { PlayerStates.BOOM_JUMP, bjAnim },
            { PlayerStates.IN_AIR, inAirAnim },
            { PlayerStates.WALL_GRAB, wallGrabAnim },
            { PlayerStates.SPIKE_DEAD, spikeDeadAnim },
            { PlayerStates.BOOM_DEAD, boomDeadAnim },
            { PlayerStates.SUCCESS, victoryAnim }
        };

        RB = GetComponent <Rigidbody2D>();
        PlayerSpriteRenderer = GetComponent <SpriteRenderer>();
        MainCollider         = GetComponent <CapsuleCollider2D>();
        PlayerAnimator       = GetComponent <Animator>();
        ExplosionAnimator    = transform.GetChild(0).GetComponent <Animator>();
        ExplosionCollider    = transform.GetChild(0).GetComponent <CapsuleCollider2D>();
        BoomJumpSource       = ExplosionAnimator.GetComponent <AudioSource>();
        wDetector            = transform.GetChild(1).GetComponent <WallDetect>();

        if (!MainCollider.enabled)
        {
            MainCollider.enabled = true;
        }

        // Set the players starting current health.
        if (curPlayerHealth != maxPlayerHealth)
        {
            curPlayerHealth = maxPlayerHealth;
        }

        bombCoolDownTimer = bombCoolDownTime;

        // When player starts, they are disabled. After pressing any key for Intro Quip, reenable the player script component.
        enabled = false;
    }
        public void Explode(Bitmap bitmap, Rect bound, long startDelay, long duration)
        {
            ExplosionAnimator explosion = new ExplosionAnimator(this, bitmap, bound);

            explosion.AnimationEnd += (s, e) =>
            {
                if (mExplosions.Count != 0)
                {
                    mExplosions.Remove(s);
                }
            };

            explosion.StartDelay = startDelay;
            explosion.SetDuration(duration);
            mExplosions.Add(explosion);
            explosion.Start();
        }
Beispiel #4
0
 private void HandleBombJumpCoolDownTimer()
 {
     if (!canJump)
     {
         if (currentState != PlayerStates.SPIKE_DEAD || currentState != PlayerStates.BOOM_DEAD)
         {
             if (bombCoolDownTimer > 0)
             {
                 bombCoolDownTimer -= Time.deltaTime;
             }
             else
             {
                 ExplosionAnimator.SetBool("isTriggered", false);
                 canJump           = true;
                 bombCoolDownTimer = bombCoolDownTime;
                 OnPlayerJump?.Invoke(canJump);
             }
         }
     }
 }