/// <summary> /// Kill Balloon with no animation or sound effect to restart /// from a checkpoint. /// </summary> public void FastKill() { if (currentState != BALLOON_STATE.DYING) { currentState = BALLOON_STATE.DEAD; //Sound.StopAll(); } }
public void Kill() { if (currentState == BALLOON_STATE.INVULNERABLE) { return; } if (isBalloonAlive) { currentState = BALLOON_STATE.DYING; if (downSound != null) { downSound.Stop(AudioStopOptions.AsAuthored); downSound = null; } if (upSound != null) { upSound.Stop(AudioStopOptions.AsAuthored); upSound = null; } if (leftSound != null) { leftSound.Stop(AudioStopOptions.AsAuthored); leftSound = null; } if (rightSound != null) { rightSound.Stop(AudioStopOptions.AsAuthored); rightSound = null; } Sound.PlayCue("pop"); m_endExplosion.Effect.Trigger(Position); //same anim.PlaySequence(animations[DEAD_ANIM_INDEX]); Environment.Camera.MoveSpeed = Vector2.Zero; } }
public void goToEndSequence(float delay) { descentDelay = delay; currentState = BALLOON_STATE.ENDING_SEQUENCE; }
public override void Update(float elapsedTime) { switch (currentState) { case BALLOON_STATE.DYING: DesiredVelocity = Vector2.Zero; anim.Update(elapsedTime); Texture = anim.CurrentFrame; if (anim.Done) { currentState = BALLOON_STATE.DEAD; } break; case BALLOON_STATE.DEAD: DesiredVelocity = Vector2.Zero; m_dead = true; Environment.restartEntities(); break; case BALLOON_STATE.ENDING_SEQUENCE: enableDown = false; enableUp = false; enableLeft = false; enableRight = false; descentDelay -= elapsedTime; if (descentDelay <= 0.0f) { endingDescent = true; } goto case BALLOON_STATE.ALIVE; case BALLOON_STATE.INVULNERABLE: currentSpecialStateRemainingTime -= elapsedTime; if (currentSpecialStateRemainingTime <= 0) { currentState = BALLOON_STATE.ALIVE; Visible = true; } else { Visible = !Visible; } goto case BALLOON_STATE.ALIVE; case BALLOON_STATE.ALIVE: { int dirX, dirY; ProcessControls(out dirX, out dirY); //DEFAULT ACTION Vector2 origVel = DesiredVelocity; Vector2 vel = DesiredVelocity; Vector2 pos = Position; pos.Y -= m_distortedPosition; if (dirY == 0) { for (int i = 0; i < tracks.Length; i++) { if (Math.Sign(tracks[i] - pos.Y) != Math.Sign(tracks[i] - PreviousPosition.Y)) { vel.Y = DEFAULT_SPEED.Y; pos.Y = tracks[i]; } } } else { if ((dirY < 0 && pos.Y + m_distortedPosition < tracks.First()) || (dirY > 0 && pos.Y + m_distortedPosition > tracks.Last())) { vel.Y = DEFAULT_SPEED.Y; pos.Y = Math.Min(MathUtils.Clamp(pos.Y + m_distortedPosition, tracks.First(), tracks.Last()) - m_distortedPosition, TOP_POSITION_BUFFER); } else { if (endingDescent) { vel.Y = MOVE_VEL / 2 * dirY; } else { vel.Y = MOVE_VEL * dirY; } } if (CLOSE_TO_EPSILON > Math.Abs(TOP_POSITION_BUFFER - pos.Y) && vel.Y < 0) { vel.Y = DEFAULT_SPEED.Y; } } bool atLeft = Environment.Camera.Rect.Left + LEFT_POSITION_BUFFER >= Position.X; bool atRight = Environment.Camera.Rect.Right - RIGHT_POSITION_BUFFER <= Position.X; if ((atLeft && vel.X < DEFAULT_SPEED.X) || (atRight && vel.X > DEFAULT_SPEED.X)) { vel.X = DEFAULT_SPEED.X; pos.X = MathUtils.Clamp(pos.X, Environment.Camera.Rect.Left + LEFT_POSITION_BUFFER, Environment.Camera.Rect.Right - RIGHT_POSITION_BUFFER); } else { if (endingDescent) { vel.X = DEFAULT_SPEED.X * dirX; } else { vel.X = DEFAULT_SPEED.X + MOVE_VEL * dirX; } } // Distorted position. UpdateDistortion(elapsedTime); // Trigger OnTempChange. if (PositionToRung(pos.Y) != m_lastRung) { int last = m_lastRung; m_lastRung = PositionToRung(pos.Y); Environment.OnTempChange(m_lastRung); } PreviousPosition = pos; // previousPosition always reflects the real un-distorted position. pos.Y += m_distortedPosition; Position = pos; DesiredVelocity = vel; Vector2 cameraRelativeVelocity = origVel - DEFAULT_SPEED; if (cameraRelativeVelocity.Y > CLOSE_TO_EPSILON) { if (tracks.Last() > Position.Y) { anim.PlaySequence(animations[DOWN_ANIM_INDEX]); } } else if (cameraRelativeVelocity.Y < -CLOSE_TO_EPSILON) { if (tracks.First() < Position.Y) { anim.PlaySequence(animations[UP_ANIM_INDEX]); } } else if (cameraRelativeVelocity.X < -CLOSE_TO_EPSILON) { if (!atLeft) { anim.PlaySequence(animations[BACK_ANIM_INDEX]); } } else if (cameraRelativeVelocity.X > CLOSE_TO_EPSILON) { if (!atRight) { anim.PlaySequence(animations[FORWARD_ANIM_INDEX]); } } else { anim.PlaySequence(animations[ALIVE_ANIM_INDEX]); } lastDirX = dirX; lastDirY = dirY; if (m_distortState != DistortState.NONE) { drippingWet.Effect.Trigger(Position); } } break; } anim.Update(elapsedTime); Registration = originalRegistration + anim.CurrentOffset; Texture = anim.CurrentFrame; base.Update(elapsedTime); }
private void Initialize() { Zindex = ZSettings.Balloon; Scale = 0.5f; m_dead = false; endingDescent = false; //Setting states currentState = BALLOON_STATE.INVULNERABLE; currentSpecialStateRemainingTime = INVULNERABILITY_TIME; DesiredVelocity = DEFAULT_SPEED; originalRegistration = new Vector2(285.0f, 165.0f); Registration = originalRegistration; CreateCollisionBody(Environment.CollisionWorld, BodyType.Dynamic, CollisionFlags.FixedRotation); AddCollisionCircle(30.0f, Vector2.Zero); drippingWet = new ParticleEntity(Environment, "DrippingWet"); drippingWet.Zindex = ZSettings.Balloon - 0.01f; // Just in front of balloon. AddChild(drippingWet); animations = new Sequence[NUMBER_OF_ANIMATION_STATES]; float defaultDuration = 0.1f; //LOADING DEAD ANIMATION Sequence seq = new Sequence(Environment.contentManager); seq.AddFrame("balloon\\BalloonPop1", 0.2f); seq.AddFrame("balloon\\BalloonPop2", 0.4f, new Vector2(291 - 279, 215 - 171)); seq.AddFrame(null, 2.0f, new Vector2(291 - 279, 215 - 171)); animations[DEAD_ANIM_INDEX] = seq; //LOADING ALIVE ANIMATION seq = new Sequence(Environment.contentManager); seq.AddFrame("balloon\\BalloonNorm1", 0.3f); seq.AddFrame("balloon\\BalloonNorm2", 0.3f); seq.Loop = true; animations[ALIVE_ANIM_INDEX] = seq; //LOADING INVULNERABLE ANIMATION seq = new Sequence(Environment.contentManager); seq.AddFrame("balloon\\BalloonNorm2", defaultDuration); seq.Loop = false; animations[INVULNERABLE_ANIM_INDEX] = seq; //LOADING UP ANIMATION seq = new Sequence(Environment.contentManager); seq.AddFrame("balloon\\BalloonUp", float.PositiveInfinity); seq.Loop = true; animations[UP_ANIM_INDEX] = seq; //LOADING DOWN ANIMATION seq = new Sequence(Environment.contentManager); seq.AddFrame("balloon\\BalloonFall", float.PositiveInfinity, new Vector2(0.0f, -10.0f)); seq.Loop = true; animations[DOWN_ANIM_INDEX] = seq; //LOADING FORWARD ANIMATION seq = new Sequence(Environment.contentManager); seq.AddFrame("balloon\\BalloonForward1", 0.15f, new Vector2(50, 20)); seq.AddFrame("balloon\\BalloonForward2", 0.15f, new Vector2(50, 20)); seq.Loop = true; animations[FORWARD_ANIM_INDEX] = seq; //LOADING BACK ANIMATION seq = new Sequence(Environment.contentManager); seq.AddFrame("balloon\\BalloonBack1", 0.3f); seq.AddFrame("balloon\\BalloonBack2", 0.3f); seq.Loop = true; animations[BACK_ANIM_INDEX] = seq; //particle effect m_endExplosion = new ParticleEntity(Environment, "balloon Explosion"); // here is where i add the particel effect m_endExplosion.Zindex = ZSettings.Balloon - 0.01f; AddChild(m_endExplosion); anim.PlaySequence(animations[ALIVE_ANIM_INDEX]); Texture = anim.CurrentFrame; PreviousPosition = Position; SnapToRung(); }