refactor: Pong Reset Key Press Moved Into PongScoreboard

This commit is contained in:
Syntriax 2024-01-30 12:28:34 +03:00
parent a9c7b8b660
commit 677fec7acc
2 changed files with 16 additions and 3 deletions

View File

@ -1,5 +1,9 @@
using System;
using Microsoft.Xna.Framework.Input;
using Syntriax.Engine.Core;
using Syntriax.Engine.Input;
namespace Pong.Behaviours;
@ -15,6 +19,18 @@ public class PongScoreboard(int WinScore) : BehaviourOverride
public int WinScore { get; } = WinScore;
protected override void OnFirstActiveFrame()
{
KeyboardInputsBehaviour? buttonInputs = null!;
if (!BehaviourController.TryGetBehaviour(out buttonInputs))
buttonInputs = BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
buttonInputs.RegisterOnRelease(Keys.Space, (_, _1) => Reset());
}
public void ScoreToLeft()
{
ScoreLeft++;

View File

@ -192,9 +192,6 @@ public class Game1 : Game
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
if (Keyboard.GetState().IsKeyDown(Keys.Space))
pongScoreboard.Reset();
gameManager.Update(gameTime.ToEngineTime());
while (physicsTimer + 0.01f < gameTime.TotalGameTime.TotalMilliseconds * .001f)//seconds)
{