powerup fixes
This commit is contained in:
		
							parent
							
								
									b47901313b
								
							
						
					
					
						commit
						a0b25b9cfb
					
				
					 7 changed files with 26 additions and 34 deletions
				
			
		|  | @ -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 <Column className="PlayerInfo"> | ||||
|         <h3> | ||||
|             Playing as {lastJsonMessage.player.name} | ||||
|         </h3> | ||||
|         <table> | ||||
|             <tbody> | ||||
|             <ScoreRow name="magazine" value={lastJsonMessage.tank?.magazine}/> | ||||
|             <ScoreRow name="controls" value={lastJsonMessage.controls}/> | ||||
|             <ScoreRow name="position" value={position}/> | ||||
|             <ScoreRow name="orientation" value={lastJsonMessage.tank?.orientation}/> | ||||
|             <ScoreRow name="bullet speed" value={lastJsonMessage.tank?.bulletStats.speed}/> | ||||
|             <ScoreRow name="bullet acceleration" value={lastJsonMessage.tank?.bulletStats.acceleration}/> | ||||
|             <ScoreRow name="smart bullets" value={lastJsonMessage.tank?.bulletStats.smart}/> | ||||
|             <ScoreRow name="explosive bullets" value={lastJsonMessage.tank?.bulletStats.explosive}/> | ||||
|             {lastJsonMessage.tank && <> | ||||
|                 <ScoreRow name="magazine" value={`${lastJsonMessage.tank.usedBullets} / ${lastJsonMessage.tank.maxBullets}`}/> | ||||
|                 <ScoreRow name="position" value={`(${Math.round(lastJsonMessage.tank.pixelPosition.x)}|${Math.round(lastJsonMessage.tank.pixelPosition.y)})`}/> | ||||
|                 <ScoreRow name="orientation" value={lastJsonMessage.tank.orientation}/> | ||||
|                 <ScoreRow name="bullet speed" value={lastJsonMessage.tank.bulletStats.speed}/> | ||||
|                 <ScoreRow name="bullet acceleration" value={lastJsonMessage.tank.bulletStats.acceleration}/> | ||||
|                 <ScoreRow name="smart bullets" value={lastJsonMessage.tank.bulletStats.smart}/> | ||||
|                 <ScoreRow name="explosive bullets" value={lastJsonMessage.tank.bulletStats.explosive}/> | ||||
|                 <ScoreRow name="moving" value={lastJsonMessage.tank.moving}/> | ||||
|             </>} | ||||
| 
 | ||||
|             <ScoreRow name="controls" value={lastJsonMessage.controls}/> | ||||
|             <ScoreRow name="kills" value={lastJsonMessage.player.scores.kills}/> | ||||
|             <ScoreRow name="deaths" value={lastJsonMessage.player.scores.deaths}/> | ||||
|             <ScoreRow name="walls destroyed" value={lastJsonMessage.player.scores.wallsDestroyed}/> | ||||
|  | @ -73,7 +72,6 @@ export default function PlayerInfo({player}: { player: string }) { | |||
|             <ScoreRow name="pixels moved" value={lastJsonMessage.player.scores.pixelsMoved}/> | ||||
|             <ScoreRow name="score" value={lastJsonMessage.player.scores.overallScore}/> | ||||
| 
 | ||||
|             <ScoreRow name="moving" value={lastJsonMessage.tank?.moving}/> | ||||
|             <ScoreRow name="connections" value={lastJsonMessage.player.openConnections}/> | ||||
|             </tbody> | ||||
|         </table> | ||||
|  |  | |||
|  | @ -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; | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| export type Player = { | ||||
|  |  | |||
|  | @ -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; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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; | ||||
| } | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -1,4 +1,3 @@ | |||
| using System.Diagnostics; | ||||
| using DotNext.Threading; | ||||
| 
 | ||||
| namespace TanksServer.Interactivity; | ||||
|  |  | |||
|  | @ -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); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter