// Use this for initialization void Start() { _animator = this.GetComponent <Animator>(); _marioMovement = this.GetComponent <MarioMovement>(); _rigidbody2D = this.GetComponent <Rigidbody2D>(); enable = true; }
public void Move() { if (movement != MarioMovement.Moving && movement != MarioMovement.Jumping) { movement = MarioMovement.Moving; Sprite = MarioSpriteFactory.Instance.CreateLittleMarioMovingSprite(); } }
public void Move() { if (movement != MarioMovement.Moving && movement != MarioMovement.Jumping) { Sprite = MarioSpriteFactory.Instance.CreateBigMarioMovingSprite(); movement = MarioMovement.Moving; } }
void Awake() { meleeAttackCollider = GetComponent <Collider2D>(); Assert.IsNotNull(meleeAttackCollider); weaponSpriteRenderer = GetComponent <SpriteRenderer>(); Assert.IsNotNull(weaponSpriteRenderer); marioMovement = transform.parent.GetComponent <MarioMovement>(); Assert.IsNotNull(marioMovement); }
public void SetIdleState() { if (marioMovement == MarioMovement.RunRight || (marioMovement == MarioMovement.JumpRight && mario.isCollideGround)) { marioMovement = MarioMovement.IdleRight; } else if (marioMovement == MarioMovement.RunLeft || (marioMovement == MarioMovement.JumpLeft && mario.isCollideGround)) { marioMovement = MarioMovement.IdleLeft; } SwitchCurrentSprite(marioMovement); }
public void HandleJump() { if (marioMovement == MarioMovement.RunLeft || marioMovement == MarioMovement.IdleLeft) { marioMovement = MarioMovement.JumpLeft; } else if (marioMovement == MarioMovement.RunRight || marioMovement == MarioMovement.IdleRight) { marioMovement = MarioMovement.JumpRight; } SwitchCurrentSprite(marioMovement); }
public void HandleCrouch() { if ((marioMovement == MarioMovement.RunLeft || marioMovement == MarioMovement.IdleLeft) && marioState != MarioState.Small && !(isJumping)) { marioMovement = MarioMovement.CrouchLeft; return; } else if ((marioMovement == MarioMovement.RunRight || marioMovement == MarioMovement.IdleRight) && marioState != MarioState.Small && !(isJumping)) { marioMovement = MarioMovement.CrouchRight; return; } }
void Start() { big = star = fire = null; bricksLayer = LayerMask.NameToLayer("Obstacles"); enemyLayer = LayerMask.NameToLayer("Enemies"); runningEnemyLayer = LayerMask.NameToLayer("RunningEnemies"); _motion = GetComponent <MarioMovement>(); _collector = GetComponent <ItemCollector>(); _collector.OnItemCollision += pickItem; _marioCollider = GetComponent <BoxCollider2D>(); _currentY = transform.position.y; _audio = gameObject.AddComponent <AudioSource>(); _animator = GetComponent <Animator>(); }
public void MoveRight() { if ((marioMovement == MarioMovement.JumpLeft || marioMovement == MarioMovement.JumpRight)) { return; } else if (marioMovement == MarioMovement.RunLeft) { marioMovement = MarioMovement.TurnRight; turnFrames++; } else if (turnFrames == 0) { marioMovement = MarioMovement.RunRight; } SwitchCurrentSprite(marioMovement); }
private void HandleFlagPoleSequence() { if (flagpoleCount == ZERO) { BGMFactory.Instance.Play_LevelComplete(); marioMovement = MarioMovement.Flagpole; SwitchCurrentSprite(marioMovement); mario.position = flagpoleColPos; flagpoleSlide = flagpoleColPos; flagpoleCount++; } else if (mario.position.Y > -345) { SlideDownFlagPoll(); mario.position = flagpoleSlide; } else if (finishSequence) { if (mario.position.X < 6520) { if (marioState == MarioState.Big || marioState == MarioState.Fire) { flagpoleSlide.Y = -355; } flagpoleSlide.X++; mario.position = flagpoleSlide; } else { MarioGame.Instance.gameComplete = true; BGMFactory.Instance.DisableRepeatMode(); return; } } else if (mario.position.Y <= -345) { if (Score.flagAtBottom) { marioMovement = MarioMovement.RunRight; SwitchCurrentSprite(marioMovement); mario.position = new Vector2(6360, -381); flagpoleSlide = mario.position; finishSequence = true; } } }
private void SwitchCurrentSprite(MarioMovement newMovement) { switch (marioState) { case MarioState.Big: currentSprite = bigStates[newMovement]; break; case MarioState.Fire: currentSprite = fireStates[newMovement]; break; case MarioState.Small: currentSprite = smallStates[newMovement]; break; } }
public void Reset() { canGrow = true; starPower = false; isJumping = false; flagpoleSequence = false; flagpoleColPos = new Vector2(); flagpoleSlide = new Vector2(); finishSequence = false; flagpoleCount = 0; marioState = MarioState.Small; marioMovement = MarioMovement.IdleRight; currentSprite = smallStates[marioMovement]; SwitchCurrentSprite(marioMovement); stateTransitionTimeRemaining = ZERO; warpTimeRemaining = ZERO; blinkTimeRemaining = ZERO; }
public void Shrink() { canGrow = true; if (marioState == MarioState.Small) { mario.Die(); } else { //If facing left, set movement to be transition left. marioMovement = (MarioFacingLeft()) ? MarioMovement.ShrinkLeft : MarioMovement.ShrinkRight; marioState = MarioState.Small; SoundEffectFactory.Instance.PlayPipeSound(); UpdateSprite(); blinkTimeRemaining = blinkLength; stateTransitionTimeRemaining = (marioState == MarioState.Big) ? firePowerupTransitionLength : currentSprite.ClipLength; } }
private void FinishStateTransition() { //Gain mushroom if (marioState == MarioState.Big && (marioMovement == MarioMovement.GrowLeft || marioMovement == MarioMovement.GrowRight)) { marioMovement = (marioMovement == MarioMovement.GrowRight) ? MarioMovement.IdleRight : MarioMovement.IdleLeft; UpdateSprite(); } //Damaged to small else if (marioState == MarioState.Small && (marioMovement == MarioMovement.ShrinkLeft || marioMovement == MarioMovement.ShrinkRight)) { marioMovement = (marioMovement == MarioMovement.ShrinkRight) ? MarioMovement.IdleRight : MarioMovement.IdleLeft; UpdateSprite(); } marioPhysics.ignoreGravity = false; marioPhysics.velocity = marioPhysics.transitionVel; }
public void BuildSprite(MarioMovement marioState) { if (marioState == MarioMovement.NotMovingNotAnimated) { MarioSprite = new StaticSprite(marioMoving, new Rectangle(OriginPosX, OriginPosY, marioMoving.Width / FrameColumn, marioMoving.Height / FrameRow), startPosition); } else if (marioState == MarioMovement.AnimatedAndMoving) { MarioSprite = new AnimatedAndMovingSprite(marioMoving, FrameRow, FrameColumn, startPosition, maxWidth, minWidth); } else if (marioState == MarioMovement.MovingNotAnimated) { MarioSprite = new MovingNotAnimatedSprite(marioMoving, new Rectangle(OriginPosX, OriginPosY, marioMoving.Width / FrameColumn, marioMoving.Height / FrameRow), startPosition, maxHeight, minHeight); } else if (marioState == MarioMovement.AnimatedNotMoving) { MarioSprite = new AnimatedNotMovingSprite(marioMoving, FrameRow, FrameColumn, startPosition); } }
private void HandleTurnFrames() { if (marioMovement == MarioMovement.TurnLeft || marioMovement == MarioMovement.TurnRight) { turnFrames++; } if (turnFrames > 10) { turnFrames = 0; if (marioMovement == MarioMovement.TurnLeft) { marioMovement = MarioMovement.RunLeft; } else if (marioMovement == MarioMovement.TurnRight) { marioMovement = MarioMovement.RunRight; } SwitchCurrentSprite(marioMovement); } }
public void Grow() { if (canGrow) { marioState = MarioState.Big; //If facing left, set movement to be transition left. marioMovement = (MarioFacingLeft()) ? MarioMovement.GrowLeft : MarioMovement.GrowRight; ISprite oldSprite = currentSprite; UpdateSprite(); //Move us up since small sprite is smaller than big sprite if (oldSprite != null && currentSprite != null) { mario.ForceMove(0, -Math.Abs(currentSprite.Height - oldSprite.Height)); } //Play growing transition stateTransitionTimeRemaining = currentSprite.ClipLength; } canGrow = false; }
void OnCollisionEnter(Collision collision) { GameObject otherObject = collision.gameObject; MarioMovement marioMovement = otherObject.GetComponent <MarioMovement>(); // if marioMovement was found if (marioMovement != null) { float ourHeight = transform.position.y; float marioHeight = otherObject.transform.position.y; float marioHeightAdvantage = marioHeight - ourHeight; if (marioHeightAdvantage > killHeight) { Destroy(gameObject); } if (marioHeightAdvantage < killHeight) { Destroy(otherObject); } } }
public void SetGroundedState() { if (marioMovement == MarioMovement.JumpRight && !(marioMovement == MarioMovement.TurnRight)) { if (marioPhysics.isRunning || marioPhysics.marioMovingRight) { marioMovement = MarioMovement.RunRight; } else { marioMovement = MarioMovement.IdleRight; } } else if (marioMovement == MarioMovement.JumpLeft && !(marioMovement == MarioMovement.TurnLeft)) { if (marioPhysics.isRunning || marioPhysics.marioMovingLeft) { marioMovement = MarioMovement.RunLeft; } else { marioMovement = MarioMovement.IdleLeft; } } else if (!(marioMovement == MarioMovement.TurnRight) && !(marioMovement == MarioMovement.TurnLeft)) { if (marioMovement == MarioMovement.RunRight && marioPhysics.marioMovingLeft) { marioMovement = MarioMovement.RunLeft; } else if (marioMovement == MarioMovement.RunLeft && marioPhysics.marioMovingRight) { marioMovement = MarioMovement.RunRight; } } SwitchCurrentSprite(marioMovement); }
public void Crouch() { Sprite = MarioSpriteFactory.Instance.CreateBigMarioCrouchingSprite(); movement = MarioMovement.Crouching; }
void Awake() { marioMovement = transform.parent.GetComponent <MarioMovement>(); Assert.IsNotNull(marioMovement); }
public void Idle() { movement = MarioMovement.Idle; Sprite = MarioSpriteFactory.Instance.CreateBigMarioIdleSprite(); }
public void Jump() { Sprite = MarioSpriteFactory.Instance.CreateBigMarioJumpingSprite(); movement = MarioMovement.Jumping; }
public void Jump() { movement = MarioMovement.Jumping; Sprite = MarioSpriteFactory.Instance.CreateLittleMarioJumpingSprite(); }
public void Update(GameTime gameTime, int spriteXPos, int spriteYPos) { if (marioMovement != MarioMovement.Die) { //If we're transitioning, handle transition timer. if (stateTransitionTimeRemaining > ZERO) { stateTransitionTimeRemaining -= (float)gameTime.ElapsedGameTime.TotalSeconds; //To or from fire mario change colors if (marioState == MarioState.Fire || (marioState == MarioState.Big && (marioMovement != MarioMovement.GrowLeft && marioMovement != MarioMovement.GrowRight))) { int fireFrame = (int)((stateTransitionTimeRemaining / firePowerupTransitionLength) * firePowerupTransitionColors.Length); stateTransitionColor = firePowerupTransitionColors[fireFrame]; } //Else just draw white else { stateTransitionColor = Color.White; } if (stateTransitionTimeRemaining <= ZERO) { FinishStateTransition(); } } if (blinkTimeRemaining > ZERO) { blinkTimeRemaining -= (float)gameTime.ElapsedGameTime.TotalSeconds; blinkShow = !blinkShow; if (!blinkShow) { stateTransitionColor = Color.Transparent; } else if (stateTransitionTimeRemaining <= ZERO) { stateTransitionColor = Color.White; } } if (warpTimeRemaining > 0) { warpTimeRemaining -= (float)gameTime.ElapsedGameTime.TotalSeconds; bool vertical = warpDirection == Direction.Up || warpDirection == Direction.Down; float speed = ((vertical) ? mario.Bounds.Height : mario.Bounds.Width) / marioWarpMoveLength; float move = speed * (float)gameTime.ElapsedGameTime.TotalSeconds; if ((warpMoveFirst && warpTimeRemaining > marioWarpStillLength - 0.1f) || (!warpMoveFirst && warpTimeRemaining <= marioWarpMoveLength + 0.01f)) { if (vertical) { mario.ForceMove(ZERO, move * ((warpDirection == Direction.Up) ? -1 : 1)); } else { mario.ForceMove(move * ((warpDirection == Direction.Left) ? -1 : 1), ZERO); } } if (warpTimeRemaining <= ZERO) { //If we start with move, this is first phase, move to second if (warpMoveFirst) { MarioGame.Instance.SecondWarpPhase(); } //Otherwise finish warp else { MarioGame.Instance.FinishWarp(); mario.MarioEnterWarpZone(); } if (mario.MarioIsInWarpZone()) { mario.Jump(null, null); } else { marioPhysics.ignoreGravity = false; } } } if (starPower) { HandleStarPower(); } if (mario.isCollideGround) { isJumping = false; if (marioMovement == MarioMovement.JumpLeft) { marioMovement = MarioMovement.RunLeft; } else if (marioMovement == MarioMovement.JumpRight) { marioMovement = MarioMovement.RunRight; } SwitchCurrentSprite(marioMovement); } } else { HandleDeathAnimation(gameTime); } HandleTurnFrames(); if (flagpoleSequence && !MarioGame.Instance.gameComplete) { HandleFlagPoleSequence(); } currentSprite.Update(gameTime, spriteXPos, spriteYPos); }
private void Awake() { marioMovement = GetComponentInParent <MarioMovement>(); Assert.IsNotNull(marioMovement); }
public void KillMario() { marioMovement = MarioMovement.Die; deathAnimTimeRemaining = deathAnimLength; currentSprite = smallStates[marioMovement]; }
public void Crouch() { movement = MarioMovement.Crouching; Sprite = MarioSpriteFactory.Instance.CreateLittleMarioIdleSprite(); }
public void FlagSlide() { movement = MarioMovement.Slide; Sprite = MarioSpriteFactory.Instance.CreateBigMarioFlagSprite(); }
void Awake() { movement = gameObject.GetComponent <MarioMovement>(); velocity = new Vector2(0.0f, 0.0f); }