public override void Update() { if (entering) { // set the Y position again on the first Update call, since the camera is finished being set up. Y = centerY; entering = false; } Level level = Scene as Level; X = level.Camera.X; delay -= Engine.DeltaTime; base.Update(); Visible = true; Player player = Scene.Tracker.GetEntity <Player>(); if (player != null) { LavaBlockerTrigger collidedTrigger = lavaBlockerTriggers.Find(trigger => player.CollideCheck(trigger)); if (collidedTrigger != null && (bool)lavaBlockerTriggerEnabled.GetValue(collidedTrigger)) { // player is in a lava blocker trigger and it is enabled; block the lava. Waiting = true; } } if (Waiting) { Y = Calc.Approach(Y, centerY, 128f * Engine.DeltaTime); loopSfx.Param("rising", 0f); if (player != null && player.X >= startX && !player.JustRespawned && player.StateMachine.State != 11) { Waiting = false; } } else if (!leaving && delay <= 0f) { loopSfx.Param("rising", 1f); if (Direction == DirectionMode.AlwaysDown || (Direction == DirectionMode.CoreModeBased && iceMode)) { Y += Speed * Engine.DeltaTime; } else { Y -= Speed * Engine.DeltaTime; } } topRect.Position.Y = Calc.Approach(topRect.Position.Y, TopOffset - topRect.Height + (leaving ? (-512) : sandwichDisplacement), (leaving ? 256 : 64) * Engine.DeltaTime); bottomRect.Position.Y = Calc.Approach(bottomRect.Position.Y, leaving ? 512 : -sandwichDisplacement, (leaving ? 256 : 64) * Engine.DeltaTime); lerp = Calc.Approach(lerp, iceMode ? 1 : 0, Engine.DeltaTime * 4f); bottomRect.SurfaceColor = Color.Lerp(RisingLava.Hot[0], RisingLava.Cold[0], lerp); bottomRect.EdgeColor = Color.Lerp(RisingLava.Hot[1], RisingLava.Cold[1], lerp); bottomRect.CenterColor = Color.Lerp(RisingLava.Hot[2], RisingLava.Cold[2], lerp); bottomRect.Spikey = lerp * 5f; bottomRect.UpdateMultiplier = (1f - lerp) * 2f; bottomRect.Fade = (iceMode ? 128 : 32); topRect.SurfaceColor = bottomRect.SurfaceColor; topRect.EdgeColor = bottomRect.EdgeColor; topRect.CenterColor = bottomRect.CenterColor; topRect.Spikey = bottomRect.Spikey; topRect.UpdateMultiplier = bottomRect.UpdateMultiplier; topRect.Fade = bottomRect.Fade; }
public override void Update() { if (sandwichHasToSetPosition) { sandwichHasToSetPosition = false; // should be 20px to the right, so that the right rect is at 300px and both rects have the same on-screen size (20px). X = SceneAs <Level>().Camera.Left + 20f; } delay -= Engine.DeltaTime; Y = SceneAs <Level>().Camera.Y - 10f; base.Update(); Visible = true; Player player = Scene.Tracker.GetEntity <Player>(); if (player != null) { LavaBlockerTrigger collidedTrigger = lavaBlockerTriggers.Find(trigger => player.CollideCheck(trigger)); if (collidedTrigger != null && (bool)lavaBlockerTriggerEnabled.GetValue(collidedTrigger)) { // player is in a lava blocker trigger and it is enabled; block the lava. waiting = true; } } if (waiting) { loopSfx.Param("rising", 0f); // the sandwich lava fade in animation is not handled here. if (lavaMode != LavaMode.Sandwich) { float target; if (lavaMode == LavaMode.LeftToRight) { // stop 32px to the left of the player. target = player.X - 32f; } else { // stop 32px to the right of the player. since lava is offset by 320px, that gives 320 - 32 = 288px. target = player.X - 288f; } if (!intro && player != null && player.JustRespawned) { X = Calc.Approach(X, target, 32f * speedMultiplier * Engine.DeltaTime); } } if (player == null || !player.JustRespawned) { waiting = false; } } else { if (lavaMode != LavaMode.Sandwich) { // this is the X position around which the speed factor will be set. At this position, speedFactor = 1. float positionThreshold; // the current lava position. float currentPosition; // the direction the lava moves at (1 = right, -1 = left). int direction; if (lavaMode == LavaMode.LeftToRight) { positionThreshold = SceneAs <Level>().Camera.Left + 21f; // if lava is too far away, drag it in. if (Right < positionThreshold - 96f) { Right = positionThreshold - 96f; } currentPosition = Right; direction = 1; } else { positionThreshold = SceneAs <Level>().Camera.Right - 21f; // if lava is too far away, drag it in. if (Left > positionThreshold + 96f) { Left = positionThreshold + 96f; } // note: positionThreshold and currentPosition are negative here because the direction is inversed. positionThreshold *= -1; currentPosition = -Left; direction = -1; } // those constants are just pulled from vanilla * 320 / 180, in an attempt to scale it for horizontal movement. float speedFactor = (currentPosition > positionThreshold) ? Calc.ClampedMap(currentPosition - positionThreshold, 0f, 56f, 1f, 0.5f) : Calc.ClampedMap(currentPosition - positionThreshold, 0f, 170f, 1f, 2f); if (delay <= 0f) { loopSfx.Param("rising", 1f); X += Speed * speedFactor * speedMultiplier * direction * Engine.DeltaTime; } } else { // sandwich lava moves at a constant speed depending on core mode. int direction = iceMode ? -1 : 1; loopSfx.Param("rising", 1f); X += 20f * speedMultiplier * direction * Engine.DeltaTime; } } // lerp both lava rects when changing core mode. lerp = Calc.Approach(lerp, iceMode ? 1 : 0, Engine.DeltaTime * 4f); if (leftRect != null) { leftRect.SurfaceColor = Color.Lerp(Hot[0], Cold[0], lerp); leftRect.EdgeColor = Color.Lerp(Hot[1], Cold[1], lerp); leftRect.CenterColor = Color.Lerp(Hot[2], Cold[2], lerp); leftRect.Spikey = lerp * 5f; leftRect.UpdateMultiplier = (1f - lerp) * 2f; leftRect.Fade = (iceMode ? 128 : 32); } if (rightRect != null) { rightRect.SurfaceColor = Color.Lerp(Hot[0], Cold[0], lerp); rightRect.EdgeColor = Color.Lerp(Hot[1], Cold[1], lerp); rightRect.CenterColor = Color.Lerp(Hot[2], Cold[2], lerp); rightRect.Spikey = lerp * 5f; rightRect.UpdateMultiplier = (1f - lerp) * 2f; rightRect.Fade = (iceMode ? 128 : 32); } if (lavaMode == LavaMode.Sandwich) { // move lava rects towards their intended positions: -340 (0 - its width) for the left rect, 280 for the right rect. // if leaving, move them away quickly instead. leftRect.Position.X = Calc.Approach(leftRect.Position.X, -340 + (sandwichLeaving ? -512 : 0), (sandwichLeaving ? 512 : 64) * Engine.DeltaTime); rightRect.Position.X = Calc.Approach(rightRect.Position.X, 280 + (sandwichLeaving ? 512 : 0), (sandwichLeaving ? 512 : 64) * Engine.DeltaTime); } }