diff --git a/tank-frontend/src/PlayerInfo.tsx b/tank-frontend/src/PlayerInfo.tsx index 7f54c06..37c479e 100644 --- a/tank-frontend/src/PlayerInfo.tsx +++ b/tank-frontend/src/PlayerInfo.tsx @@ -46,25 +46,24 @@ export default function PlayerInfo({player}: { player: string }) { if (!lastJsonMessage || readyState !== ReadyState.OPEN) return <>; - let position = ''; - if (lastJsonMessage.tank) - position = `(${Math.round(lastJsonMessage.tank.position.x)}|${Math.round(lastJsonMessage.tank.position.y)})`; - return

Playing as {lastJsonMessage.player.name}

- - - - - - - - + {lastJsonMessage.tank && <> + + + + + + + + + } + @@ -73,7 +72,6 @@ export default function PlayerInfo({player}: { player: string }) { -
diff --git a/tank-frontend/src/serverCalls.tsx b/tank-frontend/src/serverCalls.tsx index 57ae781..36d2e74 100644 --- a/tank-frontend/src/serverCalls.tsx +++ b/tank-frontend/src/serverCalls.tsx @@ -15,18 +15,14 @@ export type Scores = { }; type Tank = { - readonly position: { x: number; y: number }; + readonly pixelPosition: { x: number; y: number }; readonly orientation: number; readonly moving: boolean; readonly bulletStats: BulletStats; readonly reloadingUntil: string; readonly nextShotAfter: string; - readonly magazine: { - readonly empty: boolean; - readonly usedBullets: number; - readonly maxBullets: number; - readonly displayString: string; - }; + readonly usedBullets: number; + readonly maxBullets: number; } export type Player = { diff --git a/tanks-backend/TanksServer/GameLogic/CollectPowerUp.cs b/tanks-backend/TanksServer/GameLogic/CollectPowerUp.cs index 840c043..938f2f5 100644 --- a/tanks-backend/TanksServer/GameLogic/CollectPowerUp.cs +++ b/tanks-backend/TanksServer/GameLogic/CollectPowerUp.cs @@ -1,5 +1,3 @@ -using System.Diagnostics; - namespace TanksServer.GameLogic; internal sealed class CollectPowerUp : ITickStep @@ -47,13 +45,13 @@ internal sealed class CollectPowerUp : ITickStep switch (powerUp.Type) { case PowerUpType.MagazineSize: - tank.MaxBullets = (byte)int.Clamp(tank.MaxBullets + 1, 1, 32); + tank.MaxBullets = int.Clamp(tank.MaxBullets + 1, 1, 32); break; case PowerUpType.BulletAcceleration: tank.BulletStats = tank.BulletStats with { - Acceleration = tank.BulletStats.Acceleration * _rules.BulletAccelerationUpgradeStrength + Acceleration = tank.BulletStats.Acceleration + _rules.BulletAccelerationUpgradeStrength }; break; @@ -68,7 +66,7 @@ internal sealed class CollectPowerUp : ITickStep case PowerUpType.BulletSpeed: tank.BulletStats = tank.BulletStats with { - Speed = tank.BulletStats.Speed * _rules.BulletSpeedUpgradeStrength + Speed = tank.BulletStats.Speed + _rules.BulletSpeedUpgradeStrength }; break; diff --git a/tanks-backend/TanksServer/GameLogic/GameRules.cs b/tanks-backend/TanksServer/GameLogic/GameRules.cs index 2d338b3..1ebf548 100644 --- a/tanks-backend/TanksServer/GameLogic/GameRules.cs +++ b/tanks-backend/TanksServer/GameLogic/GameRules.cs @@ -16,7 +16,7 @@ internal sealed class GameRules public double ShootDelayMs { get; set; } - public double BulletSpeed { get; set; } + public double BulletSpeed { get; set; } = 75; public int SpawnDelayMs { get; set; } @@ -28,7 +28,7 @@ internal sealed class GameRules public double SmartBulletInertia { get; set; } = 1; - public double BulletAccelerationUpgradeStrength { get; set; } = 0.1; + public double BulletAccelerationUpgradeStrength { get; set; } = 15; - public double BulletSpeedUpgradeStrength { get; set; } = 0.1; + public double BulletSpeedUpgradeStrength { get; set; } = 5; } diff --git a/tanks-backend/TanksServer/GameLogic/MapEntityManager.cs b/tanks-backend/TanksServer/GameLogic/MapEntityManager.cs index 31cb28c..dd674a1 100644 --- a/tanks-backend/TanksServer/GameLogic/MapEntityManager.cs +++ b/tanks-backend/TanksServer/GameLogic/MapEntityManager.cs @@ -33,9 +33,8 @@ internal sealed class MapEntityManager( public void SpawnTank(Player player, FloatPosition position) { - var tank = new Tank(player) + var tank = new Tank(player, position) { - Position = position, Rotation = Random.Shared.NextDouble(), MaxBullets = _rules.MagazineSize, BulletStats =new BulletStats(_rules.BulletSpeed, 0, false, false) diff --git a/tanks-backend/TanksServer/Interactivity/DroppablePackageRequestConnection.cs b/tanks-backend/TanksServer/Interactivity/DroppablePackageRequestConnection.cs index 4e5536a..49dccc2 100644 --- a/tanks-backend/TanksServer/Interactivity/DroppablePackageRequestConnection.cs +++ b/tanks-backend/TanksServer/Interactivity/DroppablePackageRequestConnection.cs @@ -1,4 +1,3 @@ -using System.Diagnostics; using DotNext.Threading; namespace TanksServer.Interactivity; diff --git a/tanks-backend/TanksServer/Models/Tank.cs b/tanks-backend/TanksServer/Models/Tank.cs index ee955ea..7147349 100644 --- a/tanks-backend/TanksServer/Models/Tank.cs +++ b/tanks-backend/TanksServer/Models/Tank.cs @@ -4,13 +4,13 @@ using TanksServer.GameLogic; namespace TanksServer.Models; -internal sealed class Tank(Player owner) : IMapEntity +internal sealed class Tank(Player owner, FloatPosition position) : IMapEntity { private double _rotation; [JsonIgnore] public Player Owner { get; } = owner; - public double Rotation + [JsonIgnore] public double Rotation { get => _rotation; set @@ -25,7 +25,9 @@ internal sealed class Tank(Player owner) : IMapEntity public bool Moving { get; set; } - public required FloatPosition Position { get; set; } + [JsonIgnore] public FloatPosition Position { get; set; } = position; + + public PixelPosition PixelPosition => Position.ToPixelPosition(); [JsonIgnore] public PixelBounds Bounds => Position.GetBoundsForCenter(MapService.TileSize);