mirror of
https://github.com/TheRavenwoodArts/LunaLightXMG.git
synced 2026-07-30 22:55:03 -07:00
refactored test game music so it can be toggled on/off
This commit is contained in:
+64
-49
@@ -43,7 +43,9 @@ namespace LunaLightXMG
|
||||
// Debugging
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -195,7 +161,7 @@ namespace LunaLightXMG
|
||||
|
||||
// Test player input and movement with abstracted player class
|
||||
player.Draw(spriteBatch);
|
||||
|
||||
|
||||
foreach (var enemy in enemies)
|
||||
{
|
||||
enemy.Draw(spriteBatch);
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
// ---------------------------------------
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user