Skip to content

Commit

Permalink
add sound effects during transit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Jan 25, 2025
1 parent 10aa20b commit dd6b74c
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions CentralStation/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Pathoschild.Stardew.CentralStation.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
Expand Down Expand Up @@ -192,14 +193,14 @@ private void OnDestinationPicked(string stopId, StopModel[] stops, StopNetwork n
Game1.warpFarmer(request, stop.ToTile?.X ?? 0, stop.ToTile?.Y ?? 0, toFacingDirection);
}

/// <summary>The action to perform when the player arrives in the location.</summary>
/// <summary>The action to perform when the player arrives at the destination.</summary>
/// <param name="stop">The stop that the player warped to.</param>
/// <param name="network">The network which the player travelled to reach the stop.</param>
private void OnWarped(StopModel stop, StopNetwork network)
{
GameLocation location = Game1.currentLocation;

// detect warp position
// auto-detect arrival spot if needed
if (stop.ToTile is null)
{
int tileX = 0;
Expand All @@ -219,6 +220,40 @@ private void OnWarped(StopModel stop, StopNetwork network)

Game1.player.Position = new Vector2(tileX * Game1.tileSize, tileY * Game1.tileSize);
}

// pause fade to simulate travel
// (setting a null message pauses without showing a message afterward)
const int pauseTime = 1500;
Game1.pauseThenMessage(pauseTime, null);

// play transit effects mid-fade
switch (network)
{
case StopNetwork.Bus:
Game1.playSound("busDriveOff");
break;

case StopNetwork.Boat:
Game1.playSound("waterSlosh");
DelayedAction.playSoundAfterDelay("waterSlosh", 500);
DelayedAction.playSoundAfterDelay("waterSlosh", 1000);
break;

case StopNetwork.Train:
{
Game1.playSound("trainLoop", out ICue cue);
cue.SetVariable("Volume", 100f); // default volume is zero
DelayedAction.functionAfterDelay(
() =>
{
Game1.playSound("trainWhistle"); // disguise end of looping sounds
cue.Stop(AudioStopOptions.Immediate);
},
pauseTime
);
}
break;
}
}

/// <summary>Deduct the cost of a ticket from the player's money, if they have enough.</summary>
Expand Down

0 comments on commit dd6b74c

Please sign in to comment.