powerup fixes

This commit is contained in:
Vinzenz Schroeter 2024-05-08 01:01:11 +02:00
parent b47901313b
commit a0b25b9cfb
7 changed files with 26 additions and 34 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -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)

View file

@ -1,4 +1,3 @@
using System.Diagnostics;
using DotNext.Threading;
namespace TanksServer.Interactivity;

View file

@ -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);