From d2765aed3d830f9069b9461f4479cc2092a697d3 Mon Sep 17 00:00:00 2001 From: vinceh121 Date: Sat, 28 Oct 2023 17:24:36 +0200 Subject: [PATCH] feat: planes turbo --- android/assets/machinegunPlanes.json | 7 ++ .../wanderer/entity/DisplayModel.java | 16 ++-- .../wanderer/entity/plane/AbstractPlane.java | 79 ++++++++++++++++--- .../entity/plane/AbstractPlaneMeta.java | 10 +-- 4 files changed, 91 insertions(+), 21 deletions(-) diff --git a/android/assets/machinegunPlanes.json b/android/assets/machinegunPlanes.json index 6e442d6..00d1999 100644 --- a/android/assets/machinegunPlanes.json +++ b/android/assets/machinegunPlanes.json @@ -1,12 +1,19 @@ { "j_scout01": { "collisionModel": "orig/j_scout01.n/collide.obj", + "maxTurboTime": 1.5, "normal": { "minSpeed": 40, "maxSpeed": 70, "acceleration": 3.5, "decceleration": 5 }, + "turbo": { + "minSpeed": 400, + "maxSpeed": 400, + "acceleration": 2, + "decceleration": 5 + }, "displayModels": [ { "displayModel": "orig/j_scout01.n/wings.obj", diff --git a/core/src/me/vinceh121/wanderer/entity/DisplayModel.java b/core/src/me/vinceh121/wanderer/entity/DisplayModel.java index a6e6dc4..9b36ab7 100644 --- a/core/src/me/vinceh121/wanderer/entity/DisplayModel.java +++ b/core/src/me/vinceh121/wanderer/entity/DisplayModel.java @@ -186,14 +186,18 @@ public List getTextureAttributes() { public void addTextureAttribute(final Attribute value) { this.textureAttributes.add(value); + + if (this.cacheDisplayModel != null) { + this.cacheDisplayModel.materials.get(0).set(value); + } } - public boolean removeTextureAttribute(final Attribute value) { - return this.textureAttributes.remove(value); - } - - public Attribute removeTextureAttribute(final int index) { - return this.textureAttributes.remove(index); + public void removeTextureAttribute(final Attribute value) { + this.textureAttributes.remove(value); + + if (this.cacheDisplayModel != null) { + this.cacheDisplayModel.materials.get(0).remove(value.type); + } } @Override diff --git a/core/src/me/vinceh121/wanderer/entity/plane/AbstractPlane.java b/core/src/me/vinceh121/wanderer/entity/plane/AbstractPlane.java index 7376f8a..9916ec3 100644 --- a/core/src/me/vinceh121/wanderer/entity/plane/AbstractPlane.java +++ b/core/src/me/vinceh121/wanderer/entity/plane/AbstractPlane.java @@ -1,5 +1,7 @@ package me.vinceh121.wanderer.entity.plane; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.Array; @@ -14,10 +16,13 @@ import me.vinceh121.wanderer.input.InputListenerAdapter; public abstract class AbstractPlane extends AbstractClanLivingEntity implements IControllableEntity { + private static final long DOUBLE_TAP_SENSITIVITY = 500; private final Array explosionParts = new Array<>(); private final PlaneSpeedProfile normal, turbo; - private boolean controlled; - private float speedUpTime; + private ColorAttribute colorAttr; + private boolean controlled, isTurbo; + private float speedUpTime, maxTurboTime, turboTime; + private long turboPressTime; public AbstractPlane(Wanderer game, AbstractPlaneMeta meta) { super(game); @@ -34,27 +39,39 @@ public AbstractPlane(Wanderer game, AbstractPlaneMeta meta) { this.normal = new PlaneSpeedProfile(meta.getNormal()); this.turbo = new PlaneSpeedProfile(meta.getTurbo()); + + this.maxTurboTime = meta.getMaxTurboTime(); } @Override public void tick(final float delta) { super.tick(delta); - + + if (this.isTurbo) { + this.turboTime = Math.max(0, this.turboTime - delta); + + if (this.turboTime == 0) { + this.unturbo(); + } + } + + final PlaneSpeedProfile profile = this.isTurbo ? this.turbo : this.normal; + if (this.controlled) { if (this.game.getInputManager().isPressed(Input.FLY_BOOST)) { - this.speedUpTime += delta; // FIXME upper clamp + this.speedUpTime = Math.min(delta + this.speedUpTime, profile.getAcceleration()); } else { this.speedUpTime = Math.max(0, this.speedUpTime - delta); } } - final float speedUpProgress = this.speedUpTime / this.normal.getAcceleration(); - final float speed = MathUtils.lerp(this.normal.getMinSpeed(), this.normal.getMaxSpeed(), speedUpProgress); + final float speedUpProgress = this.speedUpTime / profile.getAcceleration(); + final float speed = MathUtils.lerp(profile.getMinSpeed(), profile.getMaxSpeed(), speedUpProgress); - this.translate(0, 0, -speed * delta); + this.advance(speed * delta); if (this.controlled) { - this.moveCamera(); + this.moveCamera(delta); if (this.game.getInputManager().isPressed(Input.FIRE)) { this.fire(); @@ -62,7 +79,35 @@ public void tick(final float delta) { } } - protected void moveCamera() { + protected void advance(float dist) { + this.translate(0, 0, -dist); + } + + public void turbo() { + if (this.isTurbo) { + return; + } + + this.isTurbo = true; + this.turboTime = this.maxTurboTime; + this.colorAttr = ColorAttribute.createEmissive(this.getClan() == null ? Color.GRAY : this.getClan().getColor()); + + for (final DisplayModel mdl : this.getFlatModels()) { + mdl.addTextureAttribute(this.colorAttr); + } + + System.out.println("Turbo!"); + } + + protected void unturbo() { + this.isTurbo = false; + + for (final DisplayModel mdl : this.getFlatModels()) { + mdl.removeTextureAttribute(this.colorAttr); + } + } + + protected void moveCamera(final float delta) { final Vector3 arm = new Vector3(0, 6, 17); arm.mul(this.getRotation()); arm.add(this.getTranslation()); @@ -102,6 +147,20 @@ public void onRemoveControl() { @Override public InputListener getInputProcessor() { - return new InputListenerAdapter(50); + return new InputListenerAdapter(50) { + @Override + public boolean inputDown(Input in) { + if (in == Input.FLY_BOOST) { + if (System.currentTimeMillis() - turboPressTime < DOUBLE_TAP_SENSITIVITY) { + turbo(); + } + + turboPressTime = System.currentTimeMillis(); + return true; + } + + return false; + } + }; } } diff --git a/core/src/me/vinceh121/wanderer/entity/plane/AbstractPlaneMeta.java b/core/src/me/vinceh121/wanderer/entity/plane/AbstractPlaneMeta.java index 6888234..9ea599e 100644 --- a/core/src/me/vinceh121/wanderer/entity/plane/AbstractPlaneMeta.java +++ b/core/src/me/vinceh121/wanderer/entity/plane/AbstractPlaneMeta.java @@ -10,7 +10,7 @@ public abstract class AbstractPlaneMeta implements IMeta { private Array explosionParts = new Array<>(); private String collisionModel; private final PlaneSpeedProfile normal = new PlaneSpeedProfile(), turbo = new PlaneSpeedProfile(); - private float turboTime; + private float maxTurboTime; public Array getDisplayModels() { return displayModels; @@ -44,11 +44,11 @@ public PlaneSpeedProfile getTurbo() { return this.turbo; } - public float getTurboTime() { - return turboTime; + public float getMaxTurboTime() { + return maxTurboTime; } - public void setTurboTime(float turboTime) { - this.turboTime = turboTime; + public void setMaxTurboTime(float maxTurboTime) { + this.maxTurboTime = maxTurboTime; } }