diff --git a/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java b/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java index f369ba7..871500e 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java +++ b/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java @@ -223,10 +223,10 @@ public class GuiRenderer { nvgSave(vgId); drawCrosshair(width, height, client.getInputHandler().isScopeEnabled()); + drawHeldItemStackInfo(width, height, client.getMyPlayer()); if (!client.getInputHandler().isScopeEnabled()) { drawChat(width, height, client); drawHealthBar(width, height, client.getMyPlayer()); - drawHeldItemStackInfo(width, height, client.getMyPlayer()); } if (client.getInputHandler().isDebugEnabled()) { drawDebugInfo(width, height, client); @@ -259,9 +259,13 @@ public class GuiRenderer { float cx = w / 2f; float cy = h / 2f; float size = 20f; - if (scopeEnabled) size = 3f; + if (scopeEnabled) { + size = 3f; + nvgStrokeColor(vgId, GuiUtils.rgba(1, 0, 0, 0.5f, colorA)); + } else { + nvgStrokeColor(vgId, GuiUtils.rgba(1, 1, 1, 0.25f, colorA)); + } - nvgStrokeColor(vgId, GuiUtils.rgba(1, 1, 1, 0.25f, colorA)); nvgBeginPath(vgId); nvgMoveTo(vgId, cx - size / 2, cy); nvgLineTo(vgId, cx + size / 2, cy); @@ -329,14 +333,6 @@ public class GuiRenderer { } private void drawChat(float w, float h, Client client) { - float chatWidth = w / 3; - float chatHeight = h / 4; - - nvgFillColor(vgId, GuiUtils.rgba(0, 0, 0, 0.25f, colorA)); - nvgBeginPath(vgId); - nvgRect(vgId, 0, h - chatHeight - 16, chatWidth, chatHeight); - nvgFill(vgId); - var chat = client.getChat(); nvgFontSize(vgId, 12f); nvgFontFaceId(vgId, jetbrainsMonoFont); diff --git a/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java b/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java index e6599b5..8b12991 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java +++ b/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java @@ -77,6 +77,8 @@ public class SoundManager { load("block_break_1", "sound/m_block_break_1.wav"); load("block_place_1", "sound/m_block_place_1.wav"); load("chat", "sound/chat.wav"); + load("hit_1", "sound/m_hit_1.wav"); + load("hit_2", "sound/m_hit_2.wav"); } public void load(String name, String resource) { diff --git a/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java b/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java index 6f5f2c2..c982118 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/ProjectileManager.java @@ -190,7 +190,18 @@ public class ProjectileManager { if (!server.getTeamManager().isProtected(hitPlayer)) { Gun gun = (Gun) projectile.getSourceItem(); float damage = gun.getBaseDamage(); - if (playerHitType == 1) damage *= 2; + if (playerHitType == 1) {// headshot. + damage *= 2; + if (projectile.getPlayer() != null) { + var shooter = projectile.getPlayer(); + server.getPlayerManager().getHandler(shooter).sendDatagramPacket(new SoundMessage("hit_1", 1, shooter.getPosition(), shooter.getVelocity())); + } + } else { + if (projectile.getPlayer() != null) { + var shooter = projectile.getPlayer(); + server.getPlayerManager().getHandler(shooter).sendDatagramPacket(new SoundMessage("hit_2", 1, shooter.getPosition(), shooter.getVelocity())); + } + } hitPlayer.setHealth(hitPlayer.getHealth() - damage); Vector3f impactAcceleration = new Vector3f(projectile.getVelocity()).normalize().mul(3); hitPlayer.getVelocity().add(impactAcceleration); diff --git a/server/src/main/java/nl/andrewl/aos2_server/config/ServerConfig.java b/server/src/main/java/nl/andrewl/aos2_server/config/ServerConfig.java index 99e36fe..be30a50 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/config/ServerConfig.java +++ b/server/src/main/java/nl/andrewl/aos2_server/config/ServerConfig.java @@ -13,13 +13,13 @@ public class ServerConfig { }; public static class PhysicsConfig { - public float gravity = 9.81f * 3; + public float gravity = 9.81f; public float walkingSpeed = 4; public float crouchingSpeed = 1.5f; public float sprintingSpeed = 9; public float movementAcceleration = 2; public float movementDeceleration = 1; - public float jumpVerticalSpeed = 8; + public float jumpVerticalSpeed = 7; } public static class ActionsConfig { @@ -34,6 +34,7 @@ public class ServerConfig { public float teamSpawnProtection = 10; public float movementAccuracyDecreaseFactor = 0.01f; public boolean friendlyFire = false; + public float healthRegenPerSecond = 0.01f; } public static class TeamConfig { diff --git a/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java b/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java index a1800ff..c5b5764 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/logic/PlayerActionManager.java @@ -90,6 +90,11 @@ public class PlayerActionManager { lastResupplyAt = now; } + if (server.getConfig().actions.healthRegenPerSecond != 0 && player.getHealth() < 1) { + player.setHealth(player.getHealth() + server.getConfig().actions.healthRegenPerSecond * dt); + server.getPlayerManager().getHandler(player).sendDatagramPacket(new ClientHealthMessage(player.getHealth())); + } + if (player.isCrouching() != input.crouching()) { player.setCrouching(input.crouching()); updated = true; @@ -208,13 +213,13 @@ public class PlayerActionManager { boolean grounded = isGrounded(world); tickHorizontalVelocity(config, grounded); - if (isGrounded(world)) { + if (grounded) { if (input.jumping()) { velocity.y = config.jumpVerticalSpeed * (input.sprinting() ? 1.25f : 1f); updated = true; } } else { - velocity.y -= config.gravity * dt; + velocity.y -= config.gravity * dt * 2; // Apply double-gravity to players to make the game feel faster. updated = true; } @@ -237,7 +242,7 @@ public class PlayerActionManager { } } - private void tickHorizontalVelocity(ServerConfig.PhysicsConfig config, boolean doDeceleration) { + private void tickHorizontalVelocity(ServerConfig.PhysicsConfig config, boolean grounded) { var velocity = player.getVelocity(); var orientation = player.getOrientation(); Vector3f horizontalVelocity = new Vector3f( @@ -253,7 +258,9 @@ public class PlayerActionManager { if (acceleration.lengthSquared() > 0) { acceleration.normalize(); acceleration.rotateAxis(orientation.x, 0, 1, 0); - acceleration.mul(config.movementAcceleration); + float accelerationMagnitude = config.movementAcceleration; + if (!grounded) accelerationMagnitude *= 0.25f; + acceleration.mul(accelerationMagnitude); horizontalVelocity.add(acceleration); float maxSpeed; if (input.crouching()) { @@ -269,10 +276,11 @@ public class PlayerActionManager { horizontalVelocity.normalize(maxSpeed); } updated = true; - } else if (doDeceleration && horizontalVelocity.lengthSquared() > 0) { - Vector3f deceleration = new Vector3f(horizontalVelocity) - .negate().normalize() - .mul(Math.min(horizontalVelocity.length(), config.movementDeceleration)); + } else if (horizontalVelocity.lengthSquared() > 0) { + float baseDecel = config.movementDeceleration; + if (!grounded) baseDecel *= 0.25f; + float decelerationMagnitude = Math.min(horizontalVelocity.length(), baseDecel); + Vector3f deceleration = new Vector3f(horizontalVelocity).negate().normalize().mul(decelerationMagnitude); horizontalVelocity.add(deceleration); if (horizontalVelocity.length() < 0.1f) { horizontalVelocity.set(0); @@ -449,7 +457,7 @@ public class PlayerActionManager { if (collidingWithFloor) { // This is a special case! We need to check for fall damage. if (velocity.y < -20) { - float damage = velocity.y / 200f; + float damage = velocity.y / 50f; player.setHealth(player.getHealth() + damage); if (player.getHealth() <= 0) { server.getPlayerManager().playerKilled(player, player);