Skip to content

Commit

Permalink
feat: planes turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceh121 committed Oct 28, 2023
1 parent b8288c2 commit d2765ae
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 21 deletions.
7 changes: 7 additions & 0 deletions android/assets/machinegunPlanes.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 10 additions & 6 deletions core/src/me/vinceh121/wanderer/entity/DisplayModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,18 @@ public List<Attribute> 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
Expand Down
79 changes: 69 additions & 10 deletions core/src/me/vinceh121/wanderer/entity/plane/AbstractPlane.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<DisplayModel> 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);
Expand All @@ -34,35 +39,75 @@ 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();
}
}
}

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());
Expand Down Expand Up @@ -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;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class AbstractPlaneMeta implements IMeta {
private Array<DisplayModel> explosionParts = new Array<>();
private String collisionModel;
private final PlaneSpeedProfile normal = new PlaneSpeedProfile(), turbo = new PlaneSpeedProfile();
private float turboTime;
private float maxTurboTime;

public Array<DisplayModel> getDisplayModels() {
return displayModels;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit d2765ae

Please sign in to comment.