From 9526bc2eb5218ce96e64729a4bf3100f273fec3b Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 12 Sep 2018 19:20:22 +0100 Subject: [PATCH] Implement boosting --- .../game/nano/game/games/copycat/CopyCat.java | 3 +++ .../game/nano/game/games/minekart/Kart.java | 9 +++++++- .../game/games/minekart/KartController.java | 22 ++++++++++++------- .../nano/game/games/minekart/MineKart.java | 16 ++++++-------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/copycat/CopyCat.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/copycat/CopyCat.java index 533fae414..d28606ff6 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/copycat/CopyCat.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/copycat/CopyCat.java @@ -29,6 +29,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.nano.NanoManager; import mineplex.game.nano.game.GameType; +import mineplex.game.nano.game.components.player.NightVisionComponent; import mineplex.game.nano.game.event.PlayerGameRespawnEvent; import mineplex.game.nano.game.games.copycat.CopyCat.SealBreakerRoom; import mineplex.game.nano.game.roomed.Room; @@ -70,6 +71,8 @@ public class CopyCat extends RoomedSoloGame _worldComponent.setBlockBreak(true); _endComponent.setTimeout(TimeUnit.SECONDS.toMillis(90)); + + new NightVisionComponent(this); } @Override diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/Kart.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/Kart.java index ea88e556a..44185ac3b 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/Kart.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/Kart.java @@ -28,6 +28,8 @@ public class Kart private boolean _crashed; private long _crashedAt; + private long _boostAt; + private long _completedAt; Kart(Player driver) @@ -171,7 +173,12 @@ public class Kart public boolean isBoosting() { - return !UtilTime.elapsed(_driftLast, 1200); + return !UtilTime.elapsed(_boostAt, 1000) || !UtilTime.elapsed(_driftLast, 1200); + } + + public void setBoost() + { + _boostAt = System.currentTimeMillis(); } public void setCrashed(boolean crashed) diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/KartController.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/KartController.java index a6d1247ce..2a203fb6a 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/KartController.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/KartController.java @@ -19,7 +19,7 @@ public class KartController LEFT, RIGHT } - void applyAirResistance(Kart kart) + static void applyAirResistance(Kart kart) { Vector velocity = kart.getVelocity(); @@ -33,7 +33,7 @@ public class KartController } } - void collideBlock(Kart kart) + static void collideBlock(Kart kart) { if (kart.isCrashed()) { @@ -42,10 +42,16 @@ public class KartController Location location = kart.getVehicle().getLocation(); Block next = location.getBlock(); + Vector velocity = kart.getVelocity(); + + if (next.getRelative(BlockFace.DOWN).getType() == Material.GOLD_BLOCK) + { + velocity.multiply(1.1); + kart.setBoost(); + } if (next.getType() != Material.AIR) { - Vector velocity = kart.getVelocity(); double length = velocity.length(); if (next.getRelative(BlockFace.UP).getType() != Material.AIR) @@ -79,7 +85,7 @@ public class KartController } } - void accelerate(Kart kart) + static void accelerate(Kart kart) { if (kart.isCrashed() || kart.getFrontWaysInput() <= 0) { @@ -103,7 +109,7 @@ public class KartController velocity.add(acceleration.multiply(0.01)); } - void brake(Kart kart) + static void brake(Kart kart) { if (kart.getFrontWaysInput() >= 0) { @@ -113,7 +119,7 @@ public class KartController kart.getVelocity().multiply(0.95); } - void turn(Kart kart) + static void turn(Kart kart) { Vector velocity = kart.getVelocity(); double speed = velocity.length(); @@ -139,7 +145,7 @@ public class KartController velocity.normalize().multiply(speed); } - void drift(Kart kart) + static void drift(Kart kart) { if (kart.isBoosting()) { @@ -174,7 +180,7 @@ public class KartController } } - void applyTopSpeed(Kart kart, int position) + static void applyTopSpeed(Kart kart, int position) { if (kart.isCrashed()) { diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/MineKart.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/MineKart.java index ee936c9ac..af2766b7d 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/MineKart.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/minekart/MineKart.java @@ -48,7 +48,6 @@ public class MineKart extends SoloGame implements IPacketHandler private final Map _karts; private final List _positions; - private final KartController _controller; private final Comparator _positionSorter = (o1, o2) -> { @@ -91,7 +90,6 @@ public class MineKart extends SoloGame implements IPacketHandler _keyCheckpoints = new ArrayList<>(); _karts = new HashMap<>(); _positions = new ArrayList<>(); - _controller = new KartController(); _teamComponent.setAdjustSpawnYaw(false); @@ -348,19 +346,19 @@ public class MineKart extends SoloGame implements IPacketHandler } } - _controller.applyAirResistance(kart); + KartController.applyAirResistance(kart); // Accelerate if (canControl) { - _controller.accelerate(kart); - _controller.brake(kart); - _controller.drift(kart); - _controller.turn(kart); - _controller.applyTopSpeed(kart, _positions.indexOf(kart)); + KartController.accelerate(kart); + KartController.brake(kart); + KartController.drift(kart); + KartController.turn(kart); + KartController.applyTopSpeed(kart, _positions.indexOf(kart)); } - _controller.collideBlock(kart); + KartController.collideBlock(kart); double velocityLength = kart.getVelocity().length();