mirror of
https://github.com/Royce551/Water.git
synced 2025-01-22 10:52:00 -05:00
preliminary implementation
This commit is contained in:
parent
185d87a560
commit
a82fb5ab4f
12 changed files with 112 additions and 50 deletions
|
@ -38,8 +38,8 @@ namespace FrivoloCo.Screens.Menu
|
|||
|
||||
public override void Initialize()
|
||||
{
|
||||
if (MediaPlayer.State != MediaState.Playing)
|
||||
MediaPlayer.Play(Song.FromUri("mainmenu", new("Assets/Music/mainmenu.ogg", UriKind.Relative)));
|
||||
if (Game.Audio.Tracks.Find(x => x.FilePath == "Assets/Music/mainmenu.ogg") is null)
|
||||
Game.Audio.SwitchToTrack("Assets/Music/mainmenu.ogg", true);
|
||||
|
||||
rc = new RenderContainer(Game.GraphicsDevice)
|
||||
{
|
||||
|
|
|
@ -15,6 +15,8 @@ namespace FrivoloCo.Screens.Play
|
|||
{
|
||||
public class CustomerStation : GameObject
|
||||
{
|
||||
public float StereoPan { get; init; }
|
||||
|
||||
public bool IsEmpty => customer is null;
|
||||
|
||||
private Customer customer;
|
||||
|
@ -135,7 +137,7 @@ namespace FrivoloCo.Screens.Play
|
|||
};
|
||||
AddChild(Game.AddObject(box));
|
||||
box.AddChild(Game.AddObject(tb));
|
||||
SoundEffect.FromFile(customer.WantToOrderSound).Play();
|
||||
Game.Audio.PlayEffect(customer.WantToOrderSound, true, 1, StereoPan);
|
||||
|
||||
state.TimeDelayBetweenCustomers = state.TimeDelayBetweenCustomersMax;
|
||||
}
|
||||
|
@ -154,19 +156,19 @@ namespace FrivoloCo.Screens.Play
|
|||
switch (customer.Happiness)
|
||||
{
|
||||
case >= 0.61:
|
||||
SoundEffect.FromFile(customer.ThankYouHappySound).Play();
|
||||
Game.Audio.PlayEffect(customer.ThankYouHappySound, true, 1, StereoPan);
|
||||
break;
|
||||
case <= 0.60 and >= 0.45:
|
||||
SoundEffect.FromFile(customer.ThankYouImpatientSound).Play();
|
||||
Game.Audio.PlayEffect(customer.ThankYouImpatientSound, true, 1, StereoPan);
|
||||
break;
|
||||
case <= 0.45 and >= 0.20:
|
||||
SoundEffect.FromFile(customer.ThankYouImpatientSound).Play();
|
||||
Game.Audio.PlayEffect(customer.ThankYouImpatientSound, true, 1, StereoPan);
|
||||
break;
|
||||
case <= 0.20 and >= 0.01:
|
||||
SoundEffect.FromFile(customer.ThankYouAngerySound).Play();
|
||||
Game.Audio.PlayEffect(customer.ThankYouAngerySound, true, 1, StereoPan);
|
||||
break;
|
||||
case <= 0:
|
||||
SoundEffect.FromFile(customer.ImDoneSound).Play();
|
||||
Game.Audio.PlayEffect(customer.ImDoneSound, true, 1, StereoPan);
|
||||
state.Strikes++;
|
||||
progress.TotalStrikes++;
|
||||
happy = false;
|
||||
|
@ -176,7 +178,7 @@ namespace FrivoloCo.Screens.Play
|
|||
{
|
||||
progress.Money += (decimal)(10 * customer.Happiness * progress.Day);
|
||||
progress.CustomersServed++;
|
||||
SoundEffect.FromFile("Assets/Gameplay/kaching.wav").Play();
|
||||
Game.Audio.PlayEffect("Assets/Gameplay/kaching.wav", true, 1, StereoPan);
|
||||
}
|
||||
customer = null;
|
||||
}
|
||||
|
@ -213,11 +215,11 @@ namespace FrivoloCo.Screens.Play
|
|||
wasRightOrder = true;
|
||||
}
|
||||
}
|
||||
SoundEffect.FromFile("Assets/Gameplay/Ian/hereyougo.wav").Play();
|
||||
Game.Audio.PlayEffect("Assets/Gameplay/hereyougo.wav", true, 1, StereoPan);
|
||||
scheduledObjectRemoval = state.CurrentlyDraggedItem;
|
||||
if (!wasRightOrder)
|
||||
{
|
||||
SoundEffect.FromFile(customer.WrongOrderSound).Play();
|
||||
Game.Audio.PlayEffect(customer.WrongOrderSound, true, 1, StereoPan);
|
||||
state.Strikes++;
|
||||
progress.TotalStrikes++;
|
||||
return;
|
||||
|
@ -267,17 +269,17 @@ namespace FrivoloCo.Screens.Play
|
|||
customer.Patience -= gameTime.ElapsedGameTime.TotalSeconds;
|
||||
if (!customer.HasBeenImpatient && customer.Happiness <= 0.60 && customer.Happiness >= 0.45)
|
||||
{
|
||||
SoundEffect.FromFile(customer.ImpatientSound).Play();
|
||||
Game.Audio.PlayEffect(customer.ImpatientSound, true, 1, StereoPan);
|
||||
customer.HasBeenImpatient = true;
|
||||
}
|
||||
else if (!customer.HasBeenImpatienter && customer.Happiness <= 0.45 && customer.Happiness >= 0.20)
|
||||
{
|
||||
SoundEffect.FromFile(customer.ImpatienterSound).Play();
|
||||
Game.Audio.PlayEffect(customer.ImpatienterSound, true, 1, StereoPan);
|
||||
customer.HasBeenImpatienter = true;
|
||||
}
|
||||
else if (!customer.HasBeenAngery && customer.Happiness <= 0.20 && customer.Happiness >= 0.01)
|
||||
{
|
||||
SoundEffect.FromFile(customer.AngerySound).Play();
|
||||
Game.Audio.PlayEffect(customer.AngerySound, true, 1, StereoPan);
|
||||
customer.HasBeenAngery = true;
|
||||
}
|
||||
else if (customer.Happiness <= 0)
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace FrivoloCo.Screens.Play
|
|||
{
|
||||
Game.Input.KeyDown += Input_KeyDown;
|
||||
|
||||
MediaPlayer.Play(Song.FromUri("failure", new("Assets/Gameplay/failure.ogg", UriKind.Relative)));
|
||||
Game.Audio.SwitchToTrack("Assets/Gameplay/failure.ogg", true);
|
||||
|
||||
var rc = new RenderContainer(Game.GraphicsDevice)
|
||||
{
|
||||
|
@ -112,7 +112,8 @@ namespace FrivoloCo.Screens.Play
|
|||
{
|
||||
if (e.Key == Microsoft.Xna.Framework.Input.Keys.Escape)
|
||||
{
|
||||
MediaPlayer.Stop();
|
||||
Game.Audio.StopPlayingAllTracks();
|
||||
Game.Audio.StopAllEffects();
|
||||
ScreenManager.ChangeScreen(new MenuScreen());
|
||||
}
|
||||
}
|
||||
|
@ -128,12 +129,12 @@ namespace FrivoloCo.Screens.Play
|
|||
if (!hasPlayedBeingFired && counter >= 5 && counter <= 9.5)
|
||||
{
|
||||
hasPlayedBeingFired = true;
|
||||
SoundEffect.FromFile("Assets/Gameplay/Customers/Victor/fired.wav").Play();
|
||||
Game.Audio.PlayEffect("Assets/Gameplay/Customers/Victor/fired.wav", true);
|
||||
}
|
||||
if (!hasPlayedDontFireMe && counter >= 9.6)
|
||||
{
|
||||
hasPlayedDontFireMe = true;
|
||||
SoundEffect.FromFile("Assets/Gameplay/Ian/dontfiremepls.wav").Play();
|
||||
Game.Audio.PlayEffect("Assets/Gameplay/Ian/dontfiremepls.wav", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,15 +58,15 @@ namespace FrivoloCo.Screens.Play
|
|||
if (progressState.SongPlayed >= 6)
|
||||
progressState.SongPlayed = 1;
|
||||
if (progressState.SongPlayed == 1)
|
||||
MediaPlayer.Play(Song.FromUri("gameplay-1", new("Assets/Music/gameplay-1.ogg", UriKind.Relative)));
|
||||
Game.Audio.SwitchToTrack("Assets/Music/gameplay-1.ogg", true);
|
||||
else if (progressState.SongPlayed == 2)
|
||||
MediaPlayer.Play(Song.FromUri("gameplay-2", new("Assets/Music/gameplay-2.ogg", UriKind.Relative)));
|
||||
Game.Audio.SwitchToTrack("Assets/Music/gameplay-2.ogg", true);
|
||||
else if (progressState.SongPlayed == 3)
|
||||
MediaPlayer.Play(Song.FromUri("gameplay-3", new("Assets/Music/gameplay-3.ogg", UriKind.Relative)));
|
||||
Game.Audio.SwitchToTrack("Assets/Music/gameplay-3.ogg", true);
|
||||
else if (progressState.SongPlayed == 4)
|
||||
MediaPlayer.Play(Song.FromUri("gameplay-4", new("Assets/Music/gameplay-4.ogg", UriKind.Relative)));
|
||||
Game.Audio.SwitchToTrack("Assets/Music/gameplay-4.ogg", true);
|
||||
else if (progressState.SongPlayed == 5)
|
||||
MediaPlayer.Play(Song.FromUri("gameplay-5", new("Assets/Music/gameplay-5.ogg", UriKind.Relative)));
|
||||
Game.Audio.SwitchToTrack("Assets/Music/gameplay-5.ogg", true);
|
||||
progressState.SongPlayed++;
|
||||
// Playfield
|
||||
rc = new RenderContainer(Game.GraphicsDevice)
|
||||
|
@ -116,27 +116,32 @@ namespace FrivoloCo.Screens.Play
|
|||
|
||||
s1 = new CustomerStation(State, progressState)
|
||||
{
|
||||
RelativePosition = new(18, 98, 365, 534)
|
||||
RelativePosition = new(18, 98, 365, 534),
|
||||
StereoPan = -0.5f
|
||||
};
|
||||
co.AddChild(Game.AddObject(s1));
|
||||
s2 = new CustomerStation(State, progressState)
|
||||
{
|
||||
RelativePosition = new(398, 98, 365, 534)
|
||||
RelativePosition = new(398, 98, 365, 534),
|
||||
StereoPan = -0.25f
|
||||
};
|
||||
co.AddChild(Game.AddObject(s2));
|
||||
s3 = new CustomerStation(State, progressState)
|
||||
{
|
||||
RelativePosition = new(778, 98, 365, 534)
|
||||
RelativePosition = new(778, 98, 365, 534),
|
||||
StereoPan = 0f
|
||||
};
|
||||
co.AddChild(Game.AddObject(s3));
|
||||
s4 = new CustomerStation(State, progressState)
|
||||
{
|
||||
RelativePosition = new(1158, 98, 365, 534)
|
||||
RelativePosition = new(1158, 98, 365, 534),
|
||||
StereoPan = 0.25f
|
||||
};
|
||||
co.AddChild(Game.AddObject(s4));
|
||||
s5 = new CustomerStation(State, progressState)
|
||||
{
|
||||
RelativePosition = new(1538, 98, 365, 534)
|
||||
RelativePosition = new(1538, 98, 365, 534),
|
||||
StereoPan = 0.5f
|
||||
};
|
||||
co.AddChild(Game.AddObject(s5));
|
||||
|
||||
|
@ -209,12 +214,12 @@ namespace FrivoloCo.Screens.Play
|
|||
State.Paused = !State.Paused;
|
||||
if (State.Paused)
|
||||
{
|
||||
MediaPlayer.Pause();
|
||||
Game.Audio.PauseAllTracks();
|
||||
Window.Title = "Game paused, hit ESC to continue";
|
||||
}
|
||||
else
|
||||
{
|
||||
MediaPlayer.Resume();
|
||||
Game.Audio.ResumeAllTracks();
|
||||
Window.Title = title;
|
||||
} // temporary stopgap solution
|
||||
}
|
||||
|
@ -243,13 +248,13 @@ namespace FrivoloCo.Screens.Play
|
|||
{
|
||||
State.Paused = true;
|
||||
inactivePause = true;
|
||||
MediaPlayer.Pause();
|
||||
Game.Audio.PauseAllTracks();
|
||||
}
|
||||
else if (Game.MainGame.IsActive && inactivePause)
|
||||
{
|
||||
State.Paused = false;
|
||||
inactivePause = false;
|
||||
MediaPlayer.Resume();
|
||||
Game.Audio.ResumeAllTracks();
|
||||
}
|
||||
|
||||
if (State.Paused) return;
|
||||
|
@ -294,7 +299,7 @@ namespace FrivoloCo.Screens.Play
|
|||
|
||||
if (State.Strikes >= 3)
|
||||
{
|
||||
MediaPlayer.Stop();
|
||||
Game.Audio.StopPlayingAllTracks();
|
||||
ScreenManager.ChangeScreen(new FailScreen(progressState));
|
||||
return;
|
||||
}
|
||||
|
@ -304,7 +309,7 @@ namespace FrivoloCo.Screens.Play
|
|||
State.TimeDelayBetweenCustomers = 999;
|
||||
if (CustomersAreNotStillPresent)
|
||||
{
|
||||
MediaPlayer.Stop();
|
||||
Game.Audio.StopPlayingAllTracks();
|
||||
delayBeforeScreenAdvance -= gameTime.ElapsedGameTime.TotalSeconds;
|
||||
if (delayBeforeScreenAdvance <= 0)
|
||||
{
|
||||
|
|
|
@ -57,9 +57,9 @@ namespace FrivoloCo.Screens.Play
|
|||
};
|
||||
tb.Text = $"Day\n{state.Day}\nat FrivoloCo!\n\n${state.Money:0..00}";
|
||||
co.AddChild(Game.AddObject(tb));
|
||||
MediaPlayer.Stop();
|
||||
var fx = SoundEffect.FromFile("Assets/Music/gamestart.wav");
|
||||
fx.Play();
|
||||
Game.Audio.StopPlayingAllTracks();
|
||||
Game.Audio.StopAllEffects();
|
||||
Game.Audio.PlayEffect("Assets/Music/gamestart.wav", true);
|
||||
}
|
||||
|
||||
private double fadeIn = 0;
|
||||
|
|
|
@ -42,8 +42,7 @@ namespace FrivoloCo.Screens
|
|||
rc.AddChild(Game.AddObject(sp));
|
||||
AddChild(rc);
|
||||
|
||||
MediaPlayer.IsRepeating = true;
|
||||
MediaPlayer.Play(Song.FromUri("mainmenu", new("Assets/Music/mainmenu.ogg", UriKind.Relative)));
|
||||
Game.Audio.SwitchToTrack("Assets/Music/mainmenu.ogg", true);
|
||||
}
|
||||
|
||||
private double counter = 0;
|
||||
|
|
|
@ -41,22 +41,46 @@ namespace Water.Audio
|
|||
return audioService?.Initialize() ?? false;
|
||||
}
|
||||
|
||||
public void PlayTrack(string filePath) => audioService?.PlayTrack(filePath);
|
||||
public void PlayTrack(string filePath, bool isLooping) => audioService?.PlayTrack(filePath, isLooping);
|
||||
|
||||
public void SwitchToTrack(string filePath)
|
||||
public void SwitchToTrack(string filePath, bool isLooping)
|
||||
{
|
||||
StopPlayingAllTracks();
|
||||
PlayTrack(filePath);
|
||||
PlayTrack(filePath, isLooping);
|
||||
}
|
||||
|
||||
public void StopPlayingAllTracks()
|
||||
{
|
||||
foreach (var track in Tracks)
|
||||
{
|
||||
track.IsLooping = false;
|
||||
track.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void PauseAllTracks()
|
||||
{
|
||||
foreach (var track in Tracks)
|
||||
track.Pause();
|
||||
}
|
||||
|
||||
public void ResumeAllTracks()
|
||||
{
|
||||
foreach (var track in Tracks)
|
||||
{
|
||||
track.IsLooping = false;
|
||||
track.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void StopAllEffects()
|
||||
{
|
||||
foreach (var effect in Effects)
|
||||
{
|
||||
effect.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayEffect(string filePath, bool canOnlyPlayOnce, float rate = 0f, float pan = 0f) => audioService?.PlayEffect(filePath, canOnlyPlayOnce, rate, pan);
|
||||
|
||||
private List<IAudioTrack> tracksToRemove = new();
|
||||
|
@ -68,7 +92,13 @@ namespace Water.Audio
|
|||
{
|
||||
if (track is IAudioTrack t)
|
||||
{
|
||||
if (t.IsLeftOver && t.AutoDispose)
|
||||
if (t.IsStopped && t.IsLooping)
|
||||
{
|
||||
t.Restart();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t.IsLeftOver && t.AutoDispose && !t.IsLooping)
|
||||
t.Dispose();
|
||||
|
||||
if (t.IsDisposed)
|
||||
|
@ -82,8 +112,10 @@ namespace Water.Audio
|
|||
foreach (var effect in Effects)
|
||||
{
|
||||
if (effect.IsLeftOver)
|
||||
{
|
||||
effect.Dispose();
|
||||
effectsToRemove.Add(effect);
|
||||
effectsToRemove.Add(effect);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var track in tracksToRemove)
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Water.Audio.BASS
|
|||
else return true;
|
||||
}
|
||||
|
||||
public void PlayTrack(string filePath) => new BASSMusicTrack(Audio, filePath).Play();
|
||||
public void PlayTrack(string filePath, bool isLooping) => new BASSMusicTrack(Audio, filePath, isLooping).Play();
|
||||
|
||||
public void PlayEffect(string filePath, bool canOnlyPlayOnce, float rate = 0f, float pan = 0f)
|
||||
{
|
||||
|
|
|
@ -52,6 +52,8 @@ namespace Water.Audio.BASS
|
|||
|
||||
public bool IsStopped => Bass.ChannelIsActive(Stream) == PlaybackState.Stopped;
|
||||
|
||||
public bool IsLooping { get; set; }
|
||||
|
||||
public bool IsLeftOver => HasPlayed && IsStopped;
|
||||
|
||||
public bool AutoDispose { get; }
|
||||
|
@ -65,9 +67,10 @@ namespace Water.Audio.BASS
|
|||
public double Time => Bass.ChannelBytes2Seconds(Stream, Bass.ChannelGetPosition(Stream) * 1000);
|
||||
|
||||
private AudioManager audioManager;
|
||||
public BASSMusicTrack(AudioManager audioManager, string path, bool autoDispose = true)
|
||||
public BASSMusicTrack(AudioManager audioManager, string path, bool isLooping, bool autoDispose = true)
|
||||
{
|
||||
this.audioManager = audioManager;
|
||||
IsLooping = isLooping;
|
||||
FilePath = path;
|
||||
AutoDispose = autoDispose;
|
||||
Volume = 1f;
|
||||
|
@ -97,7 +100,7 @@ namespace Water.Audio.BASS
|
|||
{
|
||||
CheckIfDisposed();
|
||||
|
||||
if (IsPlaying || IsPaused)
|
||||
if (IsPlaying)
|
||||
throw new Exception("Kyaa! Tried to play a track that's already playing");
|
||||
|
||||
var previous = Time;
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Water.Audio
|
|||
|
||||
public bool Initialize();
|
||||
|
||||
public void PlayTrack(string filePath);
|
||||
public void PlayTrack(string filePath, bool isLooping);
|
||||
|
||||
public void PlayEffect(string filePath, bool canOnlyPlayOnce, float rate = 1f, float pan = 0f);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ namespace Water.Audio
|
|||
|
||||
public bool IsPlaying { get; }
|
||||
|
||||
public bool IsLooping { get; set; }
|
||||
|
||||
public bool IsPaused { get; }
|
||||
|
||||
public bool IsStopped { get; }
|
||||
|
@ -35,5 +37,7 @@ namespace Water.Audio
|
|||
public double Volume { get; set; }
|
||||
|
||||
public double Time { get; }
|
||||
|
||||
public void Restart();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Water.Screens
|
|||
box = new Box()
|
||||
{
|
||||
RelativePosition = new(0, 0, 100, 20),
|
||||
Color = Color.White * 0.3f,
|
||||
Color = Color.White * 0.15f,
|
||||
Layout = Layout.AnchorBottom
|
||||
};
|
||||
framerateText = new(new(0, 0, 10, 10), Game.Fonts.Get("Assets/IBMPLEXSANS-MEDIUM.TTF", 15), "", Color.Black)
|
||||
|
@ -71,6 +71,8 @@ namespace Water.Screens
|
|||
}
|
||||
}
|
||||
|
||||
private int infoOverlay = 1;
|
||||
|
||||
private void Input_KeyDown(object sender, Input.KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Keys.LeftControl)
|
||||
|
@ -80,6 +82,12 @@ namespace Water.Screens
|
|||
|
||||
showExtended = true;
|
||||
}
|
||||
else if (e.Key == Keys.LeftAlt && Game.Input.IsKeyHeld(Keys.LeftControl))
|
||||
{
|
||||
infoOverlay++;
|
||||
if (infoOverlay == 4)
|
||||
infoOverlay = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deinitialize()
|
||||
|
@ -96,7 +104,15 @@ namespace Water.Screens
|
|||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
updatesPerSecond = 1 / gameTime.ElapsedGameTime.TotalSeconds;
|
||||
if (showExtended) framerateText.Text = $"{Math.Round(drawsPerSecond, 0)} frames/s, {Math.Round(updatesPerSecond, 0)} updates/s, {Game.AllObjects.Count} objects, {ScreenManager.Screens.Count} screens";
|
||||
if (showExtended)
|
||||
{
|
||||
framerateText.Text = infoOverlay switch
|
||||
{
|
||||
1 => $"{Math.Round(drawsPerSecond, 0)} frames/s, {Math.Round(updatesPerSecond, 0)} updates/s, {Game.AllObjects.Count} objects, {ScreenManager.Screens.Count} screens",
|
||||
2 => $"{Game.Audio.Tracks.Count} tracks, {Game.Audio.Effects.Count} effects",
|
||||
_ or 3 => $"i don't have anything for this yet lol"
|
||||
};
|
||||
}
|
||||
else framerateText.Text = $"{Math.Round(drawsPerSecond, 0)} fps";
|
||||
|
||||
if (WaterGame.UseExperimentalDrawingMode) framerateText.Text += " EXD";
|
||||
|
|
Loading…
Reference in a new issue