Added score notification
This commit is contained in:
parent
9c328059fe
commit
64fe3d69dd
@ -1,4 +1,6 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Reflection;
|
||||||
|
using MessagePack;
|
||||||
|
|
||||||
namespace PongGame.Hubs;
|
namespace PongGame.Hubs;
|
||||||
|
|
||||||
@ -107,7 +109,7 @@ public struct PongGameState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public struct PongPaddleState {
|
public struct PongPaddleState {
|
||||||
public const float PADDLE_LENGTH = HEIGHT / 10;
|
public const float PADDLE_LENGTH = HEIGHT / 6;
|
||||||
public const float PADDLE_HALF_LENGTH = PADDLE_LENGTH / 2;
|
public const float PADDLE_HALF_LENGTH = PADDLE_LENGTH / 2;
|
||||||
public const float PADDLE_WIDTH = PADDLE_LENGTH / 5;
|
public const float PADDLE_WIDTH = PADDLE_LENGTH / 5;
|
||||||
public const float PADDLE_SPEED = 8;
|
public const float PADDLE_SPEED = 8;
|
||||||
@ -121,7 +123,17 @@ public struct PongGameState {
|
|||||||
|
|
||||||
public float Height;
|
public float Height;
|
||||||
public PongPaddleDirection Direction;
|
public PongPaddleDirection Direction;
|
||||||
public int Score;
|
[IgnoreMember] private int _score;
|
||||||
|
public int Score {
|
||||||
|
get => _score; set {
|
||||||
|
if (_score != value) {
|
||||||
|
_score = value;
|
||||||
|
_ = Task.Run(() => ScoreChanged.Invoke(this, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event EventHandler<int> ScoreChanged;
|
||||||
|
|
||||||
public static void Update(ref PongPaddleState state)
|
public static void Update(ref PongPaddleState state)
|
||||||
=> state.Height = Math.Clamp(state.Height + ((int)state.Direction) * PADDLE_SPEED, PADDLE_HALF_LENGTH, HEIGHT - PADDLE_HALF_LENGTH);
|
=> state.Height = Math.Clamp(state.Height + ((int)state.Direction) * PADDLE_SPEED, PADDLE_HALF_LENGTH, HEIGHT - PADDLE_HALF_LENGTH);
|
||||||
|
Loading…
Reference in New Issue
Block a user