diff --git a/assets/levels/level_1.json b/assets/levels/level_1.json index 10f2a41..22b0c4d 100644 --- a/assets/levels/level_1.json +++ b/assets/levels/level_1.json @@ -1,5 +1,5 @@ { - "BaseBallSpeed": 0.1, + "BaseBallSpeed": 3, "Bricks": [ { "Colour": "DiscGreen", diff --git a/assets/levels/level_2.json b/assets/levels/level_2.json index c01c75d..8ab9a64 100644 --- a/assets/levels/level_2.json +++ b/assets/levels/level_2.json @@ -1,5 +1,5 @@ { - "BaseBallSpeed": 0.125, + "BaseBallSpeed": 5, "Bricks": [ { "Colour": "DiscGreen", diff --git a/objects/Level.cs b/objects/Level.cs index 0913c0f..45a4e5f 100644 --- a/objects/Level.cs +++ b/objects/Level.cs @@ -109,14 +109,14 @@ public void OnRendering(object sender) ((QuadBatchRenderer)sender).FlushAntiGhost(); } - public void OnUpdate(float DeltaTime) + public void OnUpdate() { if (bricks.Count <= 0) { DiscWindow.Instance.LevelWon(); return; } - ball.OnUpdate(this, DeltaTime); + ball.OnUpdate(this); } } } diff --git a/objects/components/Ball.cs b/objects/components/Ball.cs index 96d6e8b..f33af59 100644 --- a/objects/components/Ball.cs +++ b/objects/components/Ball.cs @@ -58,7 +58,7 @@ public void OnKeyDown(HashSet keys) } } - public void OnUpdate(Level level, float DeltaTime) + public void OnUpdate(Level level) { if (Released is false) { @@ -69,7 +69,7 @@ public void OnUpdate(Level level, float DeltaTime) return; } - Position += Velocity * DeltaTime; + Position += Velocity; Position.X = Math.Clamp(Position.X, -171, 171); Position.Y = Math.Clamp(Position.Y, -171, 171); @@ -104,7 +104,7 @@ public void OnUpdate(Level level, float DeltaTime) { CoolDown = 5; brick.Die(); - Speed *= 1.0000001f; + Speed *= 1.1f; Score++; if (brick.GetBrickType() == BrickType.LIFE) DiscWindow.Instance.Paddle.AddLife(); diff --git a/objects/components/Paddle.cs b/objects/components/Paddle.cs index c0dcb84..6664dc2 100644 --- a/objects/components/Paddle.cs +++ b/objects/components/Paddle.cs @@ -42,14 +42,14 @@ public void ResetPaddle() public void OnKeyDown(HashSet keys) { if (keys.Contains(Key.A) && X < 14) - VelocityX = 0.05f; + VelocityX = 0.75f; else if (keys.Contains(Key.D) && X > -14) - VelocityX = -0.05f; + VelocityX = -0.75f; } - public void OnUpdate(float DeltaTime) + public void OnUpdate() { - X += VelocityX * DeltaTime; + X += VelocityX; VelocityX = 0; X = Clamp(X, -15, 15); VertexUtils.UpdateQuad(X, -150.0f, 0.3f, 0.03f, ref Vertices,0); diff --git a/renderer/Windows/DiscWindow.axaml.cs b/renderer/Windows/DiscWindow.axaml.cs index f15545a..9b7ed05 100644 --- a/renderer/Windows/DiscWindow.axaml.cs +++ b/renderer/Windows/DiscWindow.axaml.cs @@ -20,11 +20,12 @@ public partial class DiscWindow : Window { private HashSet keys = new HashSet(); private static readonly WaveOutEvent MusicPlayer = new(); - private readonly Stopwatch stopwatch = new(); private readonly ScoreBoard ScoreBoard; private int CurrentLevel = 1; private bool GameRestart = false; + private readonly DispatcherTimer ticker = new() { Interval = new TimeSpan(0, 0, 0, 0, 1000 / 60) }; + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public static DiscWindow Instance { get; set; } #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. @@ -37,10 +38,11 @@ public DiscWindow() Instance = this; Level = new("assets.levels.level_1.json"); ScoreBoard = ScoreBoard.Load(); - stopwatch.Start(); MusicPlayer.Init(new Mp3FileReader(AssetUtil.OpenEmbeddedFile("assets.sounds.music.mp3"))); MusicPlayer.Volume = 0.25f; - MusicPlayer.Play(); + //MusicPlayer.Play(); + ticker.Tick += delegate { tick(); }; + ticker.IsEnabled = true; GC.Collect(2,GCCollectionMode.Aggressive,true,true); GC.WaitForPendingFinalizers(); } @@ -57,7 +59,7 @@ protected override void OnKeyUp(KeyEventArgs e) base.OnKeyUp(e); } - public override void Render(DrawingContext context) + protected void tick() { if (GameRestart) { @@ -94,10 +96,13 @@ public override void Render(DrawingContext context) } GameRestart = true; } - float DeltaTime = (float)Instance.stopwatch.Elapsed.TotalMilliseconds; - Instance.stopwatch.Restart(); - Instance.Level.OnUpdate(DeltaTime); - Instance.Paddle.OnUpdate(DeltaTime); + Level.OnUpdate(); + Paddle.OnUpdate(); + } + + public override void Render(DrawingContext context) + { + GLView.Render(context); base.Render(context); Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Render); @@ -115,10 +120,10 @@ protected void FinishNewUser(int LastScoreData, string UserNameData) protected override void OnClosing(CancelEventArgs e) { + ticker.IsEnabled = false; SoundUtils.CleanUp(); MusicPlayer.Stop(); MusicPlayer.Dispose(); - stopwatch.Stop(); Renderer.Dispose(); ScoreBoard.Save(ScoreBoard); base.OnClosing(e);