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; } } }
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; } } }
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; }
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; } } } }
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; } }
//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>(); }
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; } }
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; }
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; }
private void Start() { dir = Vector2.left; state = KoopaState.Walking; spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); }
private IEnumerator Reset() { yield return(new WaitForSeconds(6)); state = KoopaState.Walking; }
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); } } }
private void TransitionWalking() { State = KoopaState.Walking; Velocity = new Vector2(ENEMY_SPEED, 0); }
private void TransitionShellSpinning(Vector2 pos, Vector2 vel) { State = KoopaState.ShellSpinning; Position = pos; Velocity = vel; }
private void TransitionShellIdle() { State = KoopaState.ShellIdle; Velocity = new Vector2(0, 0); shellIdleTimer = 280; }