refactored test game music so it can be toggled on/off

This commit is contained in:
jme9
2025-03-20 13:26:27 -07:00
parent 1c5f4b1b12
commit 43903e6c42
2 changed files with 66 additions and 51 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ namespace LunaLightXMG
private bool shaking = false;
// Util
Utilities util;
readonly Utilities util;
// Getters and setters
public Vector2 Position
+62 -47
View File
@@ -44,6 +44,8 @@ namespace LunaLightXMG
private SpriteFont debugFont;
private Texture2D debugGrid;
// Keyboard input
private KeyboardState prevKeyState;
// Util
Utilities util;
@@ -78,7 +80,7 @@ namespace LunaLightXMG
graphics.ApplyChanges();
playerInput.HasControl = true; // May need to find a new home for this
prevKeyState = Keyboard.GetState();
base.Initialize();
// Initialize camera
@@ -87,49 +89,11 @@ namespace LunaLightXMG
camera2D.SetLevelBounds(new Rectangle(0,0,480,270)); // Testing - default 320x180
renderHandler.CalculateRenderDestination();
// Play music
// PlayBackgroundMusic(sinkBeats);
// Generate random platforms - test this idea out...
platforms = PlatformGenerator.CreatePlatforms(numOfPlatforms);
}
// Testing camera and render target handler ------------------------
private void TestCameraWhilePlaying()
{
KeyboardState keyboardState = Keyboard.GetState();
var KeyK = keyboardState.IsKeyDown(Keys.K);
var KeyL = keyboardState.IsKeyDown(Keys.L);
var KeyB = keyboardState.IsKeyDown(Keys.B);
var KeyN = keyboardState.IsKeyDown(Keys.N);
var KeyM = keyboardState.IsKeyDown(Keys.M);
var KeyP = keyboardState.IsKeyDown(Keys.P);
if (KeyK)
{
camera2D.Rotation -= 0.01f;
}
if (KeyL)
{
camera2D.Rotation += 0.01f;
}
if (KeyB)
{
renderHandler.ZoomIn();
}
if (KeyN)
{
renderHandler.ZoomNormalize();
}
if (KeyM)
{
renderHandler.ZoomOut();
}
if (KeyP)
{
camera2D.ScreenShake(0.5f, 5f);
}
}
// ---------------------------------------
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
@@ -176,7 +140,9 @@ namespace LunaLightXMG
camera2D.UpdateScreenShake(gameTime);
// camera testing
TestCameraWhilePlaying();
ToggleBackgroundMusic();
// Update keyState
prevKeyState = Keyboard.GetState();
base.Update(gameTime);
}
@@ -225,15 +191,17 @@ namespace LunaLightXMG
private void PlayBackgroundMusic(SoundEffect backgroundMusic)
{
if (backgroundMusicInstance == null || backgroundMusicInstance.State != SoundState.Playing)
if (backgroundMusicInstance == null)
{
if (backgroundMusicInstance != null)
{
backgroundMusicInstance.Dispose();
}
backgroundMusicInstance = backgroundMusic.CreateInstance();
backgroundMusicInstance.IsLooped = true;
}
if (backgroundMusicInstance.State == SoundState.Playing)
{
backgroundMusicInstance.Stop();
}
else
{
backgroundMusicInstance.Play();
}
}
@@ -263,8 +231,10 @@ namespace LunaLightXMG
spriteBatch.DrawString(debugFont, $"Camera Rotation Control - Rotate left: K, Rotate right: L", new Vector2(10, 190), Color.White);
spriteBatch.DrawString(debugFont, $"Render Target Zoom Control - Zoom in: B, Zoom normal: N, Zoom out: M", new Vector2(10, 210), Color.White);
spriteBatch.DrawString(debugFont, $"Render Target Zoom Control - Zoom in: U, Zoom normal: I, Zoom out: O", new Vector2(10, 210), Color.White);
spriteBatch.DrawString(debugFont, $"Press P to test screen shake.", new Vector2(10, 230), Color.White);
spriteBatch.DrawString(debugFont, $"Press M to toggle game music.", new Vector2(10, 250), Color.White);
spriteBatch.End();
}
@@ -289,5 +259,50 @@ namespace LunaLightXMG
}
#endregion
// Testing ------------------------
private void ToggleBackgroundMusic()
{
KeyboardState currKeyState = Keyboard.GetState();
if (prevKeyState.IsKeyUp(Keys.M) && currKeyState.IsKeyDown(Keys.M))
{
PlayBackgroundMusic(sinkBeats);
}
}
private void TestCameraWhilePlaying()
{
KeyboardState keyboardState = Keyboard.GetState();
var KeyK = keyboardState.IsKeyDown(Keys.K);
var KeyL = keyboardState.IsKeyDown(Keys.L);
var KeyU = keyboardState.IsKeyDown(Keys.U);
var KeyI = keyboardState.IsKeyDown(Keys.I);
var KeyO = keyboardState.IsKeyDown(Keys.O);
var KeyP = keyboardState.IsKeyDown(Keys.P);
if (KeyK)
{
camera2D.Rotation -= 0.01f;
}
if (KeyL)
{
camera2D.Rotation += 0.01f;
}
if (KeyU)
{
renderHandler.ZoomIn();
}
if (KeyI)
{
renderHandler.ZoomNormalize();
}
if (KeyO)
{
renderHandler.ZoomOut();
}
if (KeyP)
{
camera2D.ScreenShake(0.5f, 5f);
}
}
// ---------------------------------------
}
}