/// <summary> /// Initialize the character /// </summary> new public virtual void Start() { moveStick = new ControlStick(); jumpAlarm = ScriptableObject.CreateInstance <Alarm>(); hitLagAlarm = ScriptableObject.CreateInstance <Alarm>(); spriteRenderer = this.gameObject.GetComponentInChildren <SpriteRenderer>(); timer = 0; velocity = new Vector3(0f, 0f, 0f); position = new Vector2(0f, 0f); knockback = new Vector3(0f, 0f, 0f); jumpCount = 0; // Pool the states currentState = new StateIdle(this); stateAttack = new StateAttack(this); stateCrouch = new StateCrouch(this); stateIdle = new StateIdle(this); stateDash = new StateDash(this); stateJump = new StateJump(this); stateRun = new StateRun(this); stateHurt = new StateHurt(this); stateFall = new StateFall(this); playerContactFilter.layerMask = playerMask; timerSpeed = 1; canJump = true; canAttack = true; }
void DoneLanding() { anim.Stop(); sJump = StateJump.none; throwingRock = false; charMovement.throwingRock = false; }
public override StateBase <Hero> update(Hero hero) { StateBase <Hero> next = this; if (hero.want == Hero.wantAction.JUMP) { hero.jump(); hero.animCtrl.SetBool("isJumping", true); next = new StateJump(); hero.fire(); return(next); } bool ran = hero.move(); if (!ran) { hero.animCtrl.SetBool("isRunning", false); next = new StateIdle(); } if (hero.want == Hero.wantAction.ATTACK) { hero.attack(); } return(next); }
void JumpCompleteDelegate(tk2dAnimatedSprite sprite, int clipId) { if(dJump == DirectionJump.left && sJump == StateJump.launch){// && //!anim.IsPlaying("Jump_Left")){ anim.Play("Jump_Left"); anim.animationCompleteDelegate = null; sJump = StateJump.air; } else if(dJump == DirectionJump.right && sJump == StateJump.launch){// && //!anim.IsPlaying("Jump_Left")){ anim.Play("Jump_Right"); anim.animationCompleteDelegate = null; sJump = StateJump.air; } }
void LandCompleteDelegate(tk2dAnimatedSprite sprite, int clipId) { /* if(dJump == DirectionJump.left){ sJump = StateJump.none; anim.Play("Idle_Left"); anim.animationCompleteDelegate = null; charMovement.state = CharacterMovement.states.idleLeft; } else if(dJump == DirectionJump.right){ sJump = StateJump.none; anim.Play("Idle_Right"); anim.animationCompleteDelegate = null; charMovement.state = CharacterMovement.states.idleRight; } charMovement.landing = false; doneLanding = true; falling = false;*/ if(lastClip == "Idle_Left" || lastClip == "Walk_Left"){ dJump = DirectionJump.left; sJump = StateJump.none; anim.Play("Idle_Left"); anim.animationCompleteDelegate = null; charMovement.state = CharacterMovement.states.idleLeft; } else if(lastClip == "Idle_Right" || lastClip == "Walk_Right"){ dJump = DirectionJump.right; sJump = StateJump.none; anim.Play("Idle_Right"); anim.animationCompleteDelegate = null; charMovement.state = CharacterMovement.states.idleRight; } charMovement.landing = false; doneLanding = true; falling = false; throwingRock = false; charMovement.throwingRock = false; }
// Update is called once per frame void Update() { // Jump direction //if(charMovement.state == CharacterMovement.states.jump && !anim.IsPlaying("InitialJump_Left")) //{ if(Input.GetKeyDown(KeyCode.F) && !throwingRock && canThrowRock ){ throwingRock = true; if(dJump == DirectionJump.left || lastClip == "Idle_Left" || lastClip == "Walk_Left"){ anim.Play("Throw_Left"); } else if(dJump == DirectionJump.right || lastClip == "Idle_Right" || lastClip == "Walk_Right"){ anim.Play("Throw_Right"); } anim.animationCompleteDelegate = ThrowCompleteDelegate; anim.animationEventDelegate = RockDelegate; /*Vector3 loc = this.transform.position; if(isRockLeft){ loc.x -= 2; } else{ loc.x += 2; } loc.y += 1f; Instantiate(rockPrefab, loc, Quaternion.identity);*/ } if(sJump == StateJump.air) { if (dJump == DirectionJump.left) { if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A)) { dJump = DirectionJump.right; lastClip = "Idle_Right"; anim.Play("Jump_Right"); moveLanternRight(); } } else if (dJump == DirectionJump.right) { if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D)) { dJump = DirectionJump.left; lastClip = "Idle_Left"; anim.Play("Jump_Left"); moveLanternLeft(); } } } //} //Jumping animation if(charMovement.inCutscene){ this.transform.FindChild("Hero_Sprite").GetComponent<MeshRenderer>().enabled = false; anim.Stop(); } else{ this.transform.FindChild("Hero_Sprite").GetComponent<MeshRenderer>().enabled = true; } if(charMovement.state == CharacterMovement.states.jump && sJump == StateJump.none && !anim.IsPlaying("InitialJump_Left")){ doneLanding = false; if (lastClip == "Idle_Left" || lastClip == "Walk_Left"){ dJump = DirectionJump.left; sJump = StateJump.launch; anim.Play("InitialJump_Left"); anim.animationCompleteDelegate = JumpCompleteDelegate; } if (lastClip == "Idle_Right" || lastClip == "Walk_Right"){ dJump = DirectionJump.right; sJump = StateJump.launch; anim.Play("InitialJump_Right"); anim.animationCompleteDelegate = JumpCompleteDelegate; } } //falling animation else if(!charMovement.isGrounded && !anim.IsPlaying("Falling_Left")&& !falling && charMovement.state != CharacterMovement.states.jump && !throwingRock){ charMovement.state = CharacterMovement.states.falling; falling = true; doneLanding = false; dJump = DirectionJump.left; sJump = StateJump.air; if(lastClip == "Idle_Right" || lastClip == "Walk_Right"){ anim.Play("Falling_Right"); anim.animationCompleteDelegate = null; } else if(lastClip == "Idle_Left" || lastClip == "Walk_Left"){ anim.Play("Falling_Left"); anim.animationCompleteDelegate = null; }; } //Landing animation else if(charMovement.landing && !anim.IsPlaying("Land_Right") && !anim.IsPlaying("Land_Left")){ if(lastClip == "Idle_Right" || lastClip == "Walk_Right"){ anim.Play("Land_Right"); anim.animationCompleteDelegate = LandCompleteDelegate; } else if(lastClip == "Idle_Left" || lastClip == "Walk_Left"){ anim.Play("Land_Left"); anim.animationCompleteDelegate = LandCompleteDelegate; } if(audioState == AudioState.grass) audio.playGrassLanding(); else if (audioState == AudioState.dry) audio.playDryLanding(); else if (audioState == AudioState.wet) audio.playWetLanding(); } //Idle Left animation else if(charMovement.state == CharacterMovement.states.idleLeft && !anim.IsPlaying("Land_Left") && !anim.IsPlaying("Idle_Left") && !throwingRock){ anim.Play("Idle_Left"); anim.animationCompleteDelegate = null; lastClip = "Idle_Left"; } else if(charMovement.state == CharacterMovement.states.idleLeft && !anim.IsPlaying("Land_Left") && !anim.IsPlaying("Idle_Left") && throwingRock){ charMovement.throwingRock = true; } //Walking Left animation else if(charMovement.state == CharacterMovement.states.walkLeft && doneLanding && !anim.IsPlaying("Walk_Left") && !throwingRock){ anim.Play("Walk_Left"); anim.animationEventDelegate = WalkingEventDelegate; anim.animationCompleteDelegate = null; lastClip = "Walk_Left"; moveLanternLeft(); //if(audioState == AudioState.grass) } else if(charMovement.state == CharacterMovement.states.walkLeft && doneLanding && !anim.IsPlaying("Walk_Left") && throwingRock){ charMovement.throwingRock = true; } //Idle Right animation else if(charMovement.state == CharacterMovement.states.idleRight && !anim.IsPlaying("Land_Right") && !anim.IsPlaying("Idle_Right") && !throwingRock){ anim.Play("Idle_Right"); anim.animationCompleteDelegate = null; lastClip = "Idle_Right"; } else if(charMovement.state == CharacterMovement.states.idleRight && !anim.IsPlaying("Land_Right") && !anim.IsPlaying("Idle_Right") && throwingRock){ charMovement.throwingRock = true; } //Walking Right animation else if(charMovement.state == CharacterMovement.states.walkRight && doneLanding && !anim.IsPlaying("Walk_Right") && !throwingRock){ anim.Play("Walk_Right"); anim.animationCompleteDelegate = null; anim.animationEventDelegate = WalkingEventDelegate; lastClip = "Walk_Right"; moveLanternRight(); } }