Пример #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            switch (state)
            {
            case KoopaState.Walking:

                // Detects if Mario hits Koopa from the top
                Vector3 hit   = collision.contacts[0].normal;
                float   angle = Vector3.Angle(hit, Vector3.up);

                if (Mathf.Approximately(angle, 180))
                {
                    state = KoopaState.InShell;
                    Debug.Log("Hit on top");
                }
                break;

            case KoopaState.InShell:
                state = KoopaState.Zooming;
                dir  *= -1;
                speed = 10;
                Reset();
                StartCoroutine(Reset());
                break;
            }
        }
    }
Пример #2
0
    private void Update()
    {
        if (isActive)
        {
            Move();

            if (lives == 3)
            {
                State = KoopaState.Moving;
            }
            else
            {
                State = KoopaState.Stomp;
            }
        }
        else
        {
            if (Logic.Instance.Player == null)
            {
                Logic.Instance.Player = GameObject.FindGameObjectWithTag("Player");
            }
            else
            if (transform.position.x - Logic.Instance.Player.transform.position.x <= necessary_distance_for_activation)
            {
                isActive = true;
            }
        }
    }
Пример #3
0
        public Koopa(IFactory spriteFactory, Point position, bool isRedKoopa) : base(spriteFactory, position, new Vector2())
        {
            this.isRedKoopa        = isRedKoopa;
            this.gravity           = new Gravity(this);
            this.koopaStateMachine = new KoopaWalkLeftState(this);

            this.hitboxColor  = Color.Red;
            this.hitboxOffset = -2;
        }
Пример #4
0
 void Update()
 {
     if (move && status == KoopaState.Stand)
     {
         isKiller = true;
     }
     else
     {
         isKiller = false;
     }
     sr.flipX = rb.velocity.x > 0;
     if (Active)
     {
         if (status == KoopaState.Fly)
         {
             rb.constraints  = RigidbodyConstraints2D.FreezeRotation;
             fly             = false;
             jump            = false;
             rb.gravityScale = 1;
             status          = KoopaState.Run;
             move            = true;
         }
         else if (status == KoopaState.Run)
         {
             status = KoopaState.Stand;
             move   = false;
         }
         else if (status == KoopaState.Stand || status == KoopaState.Alive)
         {
             status = KoopaState.Stand;
             move   = !move;
         }
         time   = AliveTime;
         Active = false;
     }
     else
     {
         if (!move)
         {
             time -= Time.deltaTime;
             if (time <= 0f)
             {
                 if (status == KoopaState.Stand)
                 {
                     status = KoopaState.Alive;
                     move   = false;
                 }
                 else if (status == KoopaState.Alive)
                 {
                     status = KoopaState.Run;
                     move   = true;
                 }
                 time = AliveTime;
             }
         }
     }
 }
Пример #5
0
        public void ChangeKoopaState(KoopaState state)
        {
            this.koopaStateMachine = state;

            if (this.koopaStateMachine is KoopaFeetOutOfShellState || this.koopaStateMachine is KoopaShellState)
            {
                this.HitboxType = HitboxTypes.Half;
            }
            else
            {
                this.HitboxType = HitboxTypes.Full;
            }
        }
Пример #6
0
    //private int current_state = 0;

    void Start()
    {
        rigidKoopaGreen = GetComponent <Rigidbody2D>();
        transKoopaGreen = GetComponent <Transform>();
        animKoopaGreen  = GetComponent <Animator>();
        boxKoopaGreen   = GetComponent <BoxCollider2D> ();
        sprite          = GetComponent <SpriteRenderer> ();

        velX = -Mathf.Abs(velX);
        KoopaState current_state = KoopaState.NORMAL;

        gC = GameObject.Find("global_controller").GetComponent <scr_GameController>();
    }
Пример #7
0
        public void SetKoopaState(KoopaState S)
        {
            State = S;
            switch (State)
            {
            case KoopaState.KS_Walking:
            {
                width         = 16;
                height        = 27;
                AnimatedCount = 2;
                newy         -= 11;
                WalkStep      = 1;


                Animated = true;
            } break;

            case KoopaState.KS_Shield:
            {
                width         = 16;
                height        = 27;
                ReturningTime = 0;
                OffsetIndex   = 0;

                ImageIndex = 4;
                //newy -= 11;
                Animated = false;
            } break;

            case KoopaState.KS_Returning:
            {
                OffsetIndex = 0;
                //Animated = false;
            } break;

            case KoopaState.KS_ShieldMoving:
            {
                width  = 16;
                height = 27;
                //newy -= 11;

                WalkStep      = 4;
                AnimatedCount = 4;
                OffsetIndex   = 4;
                Animated      = true;
            } break;
            }
        }
Пример #8
0
 void Awake()
 {
     rb = GetComponent <Rigidbody2D> ();
     sr = GetComponent <SpriteRenderer> ();
     an = GetComponent <Animator> ();
     if (!isFly)
     {
         status = KoopaState.Run;
     }
     if (fly)
     {
         rb.gravityScale = 0;
         rb.constraints  = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
     }
     currentSpeed = speed;
     time         = AliveTime;
 }
Пример #9
0
    public void switch_state(KoopaState state_switching_to)
    {
        switch (state_switching_to)
        {
        case KoopaState.NORMAL:
            velX         = -Mathf.Abs(velX);
            time_counter = 0;
            break;

        case KoopaState.SHELL_STANDBY:
            velX         = 0;
            velX         = -Mathf.Abs(velX);
            time_counter = 0;
            animKoopaGreen.SetBool("Stop", true);
            break;

        case KoopaState.SHELL_SLIDING:
            animKoopaGreen.SetBool("Stop", false);
            time_counter = 0;
            break;
        }
        combo_counter = 0;
        current_state = state_switching_to;
    }
Пример #10
0
 private void Start()
 {
     dir            = Vector2.left;
     state          = KoopaState.Walking;
     spriteRenderer = gameObject.GetComponent <SpriteRenderer>();
 }
Пример #11
0
    private IEnumerator Reset()
    {
        yield return(new WaitForSeconds(6));

        state = KoopaState.Walking;
    }
Пример #12
0
        public void SetKoopaState(KoopaState S)
        {
            State = S;
            switch (State)
            {
                case KoopaState.KS_Walking:
                    {
                        width = 16;
                        height = 27;
                        AnimatedCount = 2;
                        newy -= 11;
                        WalkStep = 1;

                        Animated = true;
                    } break;
                case KoopaState.KS_Shield:
                    {
                        width = 16;
                        height = 27;
                        ReturningTime = 0;
                        OffsetIndex = 0;

                        ImageIndex = 4;
                        //newy -= 11;
                        Animated = false;
                    } break;
                case KoopaState.KS_Returning:
                    {
                        OffsetIndex = 0;
                        //Animated = false;
                    } break;
                case KoopaState.KS_ShieldMoving:
                    {
                        width = 16;
                        height = 27;
                        //newy -= 11;

                        WalkStep = 4;
                        AnimatedCount = 4;
                        OffsetIndex = 4;
                        Animated = true;

                    } break;
            }
        }
Пример #13
0
 public override void HandleCollision(CollisionDirection collisionDirection, GameObject gameObject)
 {
     if (gameObject is Mario)
     {
         if (((Mario)gameObject).IsInvincible())
         {
             this.koopaStateMachine.HandleFireBallDeathTransition(true);
         }
         else if (collisionDirection == CollisionDirection.Top)
         {
             if (!(this.koopaStateMachine is KoopaShellState))
             {
                 this.koopaStateMachine.HandleShellTransition();
             }
             else
             {
                 if (this.XSpeed != 0.0f)
                 {
                     this.XSpeed = 0.0f;
                 }
                 else
                 {
                     if (((Mario)gameObject).PositionInGame.X > this.positionInGame.X)
                     {
                         this.XSpeed = -5.5f;
                     }
                     else
                     {
                         this.XSpeed = 5.5f;
                     }
                 }
             }
         }
         else if (collisionDirection == CollisionDirection.Right)
         {
             if (this.koopaStateMachine is KoopaShellState && this.XSpeed == 0.0f)
             {
                 this.XSpeed = -5.5f;
             }
             else if (this.koopaStateMachine is KoopaFeetOutOfShellState)
             {
                 this.koopaStateMachine.HandleShellTransition();
                 this.XSpeed = -5.5f;
             }
         }
         else if (collisionDirection == CollisionDirection.Left)
         {
             if (this.koopaStateMachine is KoopaShellState && this.XSpeed == 0.0f)
             {
                 this.XSpeed = 5.5f;
             }
             else if (this.koopaStateMachine is KoopaFeetOutOfShellState)
             {
                 this.koopaStateMachine.HandleShellTransition();
                 this.XSpeed = 5.5f;
             }
         }
     }
     else if (gameObject is Block || gameObject is Gate || gameObject is Button)
     {
         if (collisionDirection == CollisionDirection.Bottom || collisionDirection == CollisionDirection.None)
         {
             if (gameObject is StateBlock && ((StateBlock)gameObject).State is BumpedState)
             {
                 this.YSpeed = -6;
                 this.koopaStateMachine.HandleFireBallDeathTransition(true);
             }
             else
             {
                 this.YSpeed = 0.0f;
             }
         }
         else if (collisionDirection == CollisionDirection.Left || collisionDirection == CollisionDirection.Right)
         {
             if (this.koopaStateMachine is KoopaWalkLeftState || this.koopaStateMachine is KoopaWalkRightState)
             {
                 if (this.isWalkingLeft)
                 {
                     this.koopaStateMachine = new KoopaWalkRightState(this);
                 }
                 else
                 {
                     this.koopaStateMachine = new KoopaWalkLeftState(this);
                 }
             }
             else if (!(this.koopaStateMachine is KoopaFireBallDeathState))
             {
                 this.XSpeed = -this.XSpeed;
             }
         }
     }
     else if (gameObject is Koopa || gameObject is Goomba)
     {
         if (collisionDirection == CollisionDirection.Left || collisionDirection == CollisionDirection.Right)
         {
             if (this.koopaStateMachine is KoopaWalkLeftState || this.koopaStateMachine is KoopaWalkRightState)
             {
                 if (this.isWalkingLeft)
                 {
                     this.koopaStateMachine = new KoopaWalkRightState(this);
                 }
                 else
                 {
                     this.koopaStateMachine = new KoopaWalkLeftState(this);
                 }
             }
         }
     }
     else if (gameObject is FireBall || gameObject is Sword)
     {
         if (gameObject.PositionInGame.X < this.positionInGame.X)
         {
             this.koopaStateMachine.HandleFireBallDeathTransition(true);
         }
         else
         {
             this.koopaStateMachine.HandleFireBallDeathTransition(false);
         }
     }
 }
Пример #14
0
 private void TransitionWalking()
 {
     State    = KoopaState.Walking;
     Velocity = new Vector2(ENEMY_SPEED, 0);
 }
Пример #15
0
 private void TransitionShellSpinning(Vector2 pos, Vector2 vel)
 {
     State    = KoopaState.ShellSpinning;
     Position = pos;
     Velocity = vel;
 }
Пример #16
0
 private void TransitionShellIdle()
 {
     State          = KoopaState.ShellIdle;
     Velocity       = new Vector2(0, 0);
     shellIdleTimer = 280;
 }