Implement boosting

This commit is contained in:
Sam 2018-09-12 19:20:22 +01:00 committed by Alexander Meech
parent 4b09c66cdc
commit 9526bc2eb5
4 changed files with 32 additions and 18 deletions

View File

@ -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<SealBreakerRoom>
_worldComponent.setBlockBreak(true);
_endComponent.setTimeout(TimeUnit.SECONDS.toMillis(90));
new NightVisionComponent(this);
}
@Override

View File

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

View File

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

View File

@ -48,7 +48,6 @@ public class MineKart extends SoloGame implements IPacketHandler
private final Map<Player, Kart> _karts;
private final List<Kart> _positions;
private final KartController _controller;
private final Comparator<Kart> _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();