mirror of
https://github.com/TheRavenwoodArts/LunaLightXMG.git
synced 2026-07-30 23:35:02 -07:00
Merge branch 'main' into Level-Handling
This commit is contained in:
+8
-11
@@ -12,7 +12,7 @@ namespace LunaLightXMG
|
||||
private float rotation;
|
||||
private Vector2 position;
|
||||
private Rectangle levelBounds;
|
||||
private readonly float camSpeed = 0.1f;
|
||||
private readonly float camSpeed = 5.0f;
|
||||
|
||||
// Screen Shake
|
||||
private float shakeTimeRemaining = 0f;
|
||||
@@ -64,16 +64,13 @@ namespace LunaLightXMG
|
||||
levelBounds = bounds;
|
||||
}
|
||||
|
||||
public void Follow(Vector2 targetPostion)
|
||||
public void Follow(GameTime gameTime, Vector2 targetPostion)
|
||||
{
|
||||
position += (targetPostion - position) * camSpeed;
|
||||
if (Math.Abs(position.X - targetPostion.X) < 0.1f)
|
||||
float smoothSpeed = camSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
|
||||
position = Vector2.Lerp(position, targetPostion, smoothSpeed);
|
||||
if (Vector2.Distance(position, targetPostion) < 1.0f)
|
||||
{
|
||||
position.X = targetPostion.X;
|
||||
}
|
||||
if (Math.Abs(position.Y - targetPostion.Y) < 0.1f)
|
||||
{
|
||||
position.Y = targetPostion.Y;
|
||||
position = targetPostion;
|
||||
}
|
||||
ClampToBounds();
|
||||
}
|
||||
@@ -91,8 +88,8 @@ namespace LunaLightXMG
|
||||
|
||||
if (shakeTimeRemaining > 0)
|
||||
{
|
||||
float shakeX = util.ChooseFromRange(-shakeMagnitudeCurrent, shakeMagnitudeCurrent);
|
||||
float shakeY = util.ChooseFromRange(-shakeMagnitudeCurrent, shakeMagnitudeCurrent);
|
||||
float shakeX = util.RandomFromRange(-shakeMagnitudeCurrent, shakeMagnitudeCurrent);
|
||||
float shakeY = util.RandomFromRange(-shakeMagnitudeCurrent, shakeMagnitudeCurrent);
|
||||
position.X += shakeX;
|
||||
position.Y += shakeY;
|
||||
shakeTimeRemaining -= (float)gameTime.ElapsedGameTime.TotalSeconds;
|
||||
|
||||
+3
-2
@@ -136,7 +136,7 @@ namespace LunaLightXMG
|
||||
// test render handler zoom
|
||||
renderHandler.UpdateZoom();
|
||||
// Update camera position
|
||||
camera2D.Follow(player.position);
|
||||
camera2D.Follow(gameTime, player.position);
|
||||
camera2D.UpdateScreenShake(gameTime);
|
||||
// camera testing
|
||||
TestCameraWhilePlaying();
|
||||
@@ -182,7 +182,7 @@ namespace LunaLightXMG
|
||||
for (int i = 0; i < numberOfEnemies; i++)
|
||||
{
|
||||
Vector2 spawnPosition = new Vector2(16 + i * 3, -16);
|
||||
Enemy enemy = new(spawnPosition, util.ChooseFromRange(1,3));
|
||||
Enemy enemy = new(spawnPosition, util.RandomFromRange(1,3));
|
||||
enemy.LoadContent(Content);
|
||||
enemies.Add(enemy);
|
||||
}
|
||||
@@ -234,6 +234,7 @@ namespace LunaLightXMG
|
||||
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.DrawString(debugFont, $"Press R to reset level.", new Vector2(10, 270), Color.White);
|
||||
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
+3
-3
@@ -7,9 +7,9 @@ namespace LunaLightXMG
|
||||
public class RenderHandler
|
||||
{
|
||||
// fields
|
||||
private GraphicsDevice graphicsDevice;
|
||||
private SpriteBatch spriteBatch;
|
||||
private RenderTarget2D renderTarget;
|
||||
private readonly GraphicsDevice graphicsDevice;
|
||||
private readonly SpriteBatch spriteBatch;
|
||||
private readonly RenderTarget2D renderTarget;
|
||||
private Rectangle renderDestination;
|
||||
|
||||
private readonly float retroWidth;
|
||||
|
||||
+2
-2
@@ -4,14 +4,14 @@ namespace LunaLightXMG
|
||||
{
|
||||
public class Utilities
|
||||
{
|
||||
private Random random;
|
||||
private readonly Random random;
|
||||
|
||||
public Utilities(int seed = 42)
|
||||
{
|
||||
random = new Random(seed);
|
||||
}
|
||||
|
||||
public float ChooseFromRange(float num1, float num2)
|
||||
public float RandomFromRange(float num1, float num2)
|
||||
{
|
||||
return (float)(num1 + (num2 - num1) * random.NextDouble());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user