add magazine system (cannot reload currently)
This commit is contained in:
parent
4e605d556c
commit
9ccb7c8df8
8 changed files with 86 additions and 32 deletions
|
@ -46,10 +46,10 @@ internal sealed class PlayerInfoConnection(
|
|||
private byte[]? GetMessageToSend()
|
||||
{
|
||||
var tank = entityManager.GetCurrentTankOfPlayer(player);
|
||||
var tankInfo = tank != null
|
||||
? new TankInfo(tank.Orientation, tank.ExplosiveBullets, tank.Position.ToPixelPosition(), tank.Moving)
|
||||
TankInfo? tankInfo = tank != null
|
||||
? new TankInfo(tank.Orientation, tank.Magazine.ToDisplayString(), tank.Position.ToPixelPosition(), tank.Moving)
|
||||
: null;
|
||||
var info = new PlayerInfo(player.Name, player.Scores, ControlsToString(player.Controls), tankInfo);
|
||||
var info = new PlayerInfo(player.Name, player.Scores, player.Controls.ToDisplayString(), tankInfo);
|
||||
var response = JsonSerializer.SerializeToUtf8Bytes(info, _context.PlayerInfo);
|
||||
|
||||
if (response.SequenceEqual(_lastMessage))
|
||||
|
@ -57,21 +57,4 @@ internal sealed class PlayerInfoConnection(
|
|||
|
||||
return _lastMessage = response;
|
||||
}
|
||||
|
||||
private static string ControlsToString(PlayerControls controls)
|
||||
{
|
||||
var str = new StringBuilder("[ ");
|
||||
if (controls.Forward)
|
||||
str.Append("▲ ");
|
||||
if (controls.Backward)
|
||||
str.Append("▼ ");
|
||||
if (controls.TurnLeft)
|
||||
str.Append("◄ ");
|
||||
if (controls.TurnRight)
|
||||
str.Append("► ");
|
||||
if (controls.Shoot)
|
||||
str.Append("• ");
|
||||
str.Append(']');
|
||||
return str.ToString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue