Skip to content

Commit

Permalink
feat: started planes
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceh121 committed Oct 27, 2023
1 parent 29ed8af commit 3f2c3d2
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 0 deletions.
65 changes: 65 additions & 0 deletions android/assets/machinegunPlanes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"j_scout01": {
"collisionModel": "orig/j_scout01.n/collide.obj",
"normal": {
"minSpeed": 40,
"maxSpeed": 70,
"acceleration": 3.5,
"decceleration": 5
},
"displayModels": [
{
"displayModel": "orig/j_scout01.n/wings.obj",
"displayTexture": "orig/j_scout01.n/texture_wingnone.ktx",
"children": [
{
"displayModel": "orig/j_scout01.n/aileronl.obj",
"displayTexture": "orig/j_scout01.n/texture_wingnone.ktx",
"animationChannel": "wingVert",
"relativeTransform": {
"translation": [
-6.154,
2.943,
0.887
],
"rotation": [
0.0,
0.0,
0.030538492,
-0.9995336
],
"scale": [
1,
1,
1
]
}
},
{
"displayModel": "orig/j_scout01.n/aileronr.obj",
"displayTexture": "orig/j_scout01.n/texture_wingnone.ktx",
"animationChannel": "wingVert",
"relativeTransform": {
"translation": [
6.0,
2.943,
0.887
],
"rotation": [
0.0,
0.0,
0.030538514,
0.9995336
],
"scale": [
1,
1,
1
]
}
}
]
}
]
}
}
3 changes: 3 additions & 0 deletions core/src/me/vinceh121/wanderer/IMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import me.vinceh121.wanderer.entity.AbstractEntity;

/**
* TODO rename to prototype, that's more semantically correct
*/
public interface IMeta {
/**
* Returns a new instance of the concerned entity meta. Perhaps a default if
Expand Down
2 changes: 2 additions & 0 deletions core/src/me/vinceh121/wanderer/MetaRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import me.vinceh121.wanderer.character.CharacterMeta;
import me.vinceh121.wanderer.entity.PropMeta;
import me.vinceh121.wanderer.entity.guntower.MachineGunGuntowerMeta;
import me.vinceh121.wanderer.entity.plane.MachineGunPlaneMeta;

public final class MetaRegistry {
private static final Logger LOG = LogManager.getLogger(MetaRegistry.class);
Expand Down Expand Up @@ -50,6 +51,7 @@ public void loadDefaults() throws StreamReadException, DatabindException, IOExce
this.readMetas(Gdx.files.internal("characters.json"), CharacterMeta.class);
this.readMetas(Gdx.files.internal("props.json"), PropMeta.class);
this.readMetas(Gdx.files.internal("machinegunGuntowers.json"), MachineGunGuntowerMeta.class);
this.readMetas(Gdx.files.internal("machinegunPlanes.json"), MachineGunPlaneMeta.class);
}

public void clear() {
Expand Down
4 changes: 4 additions & 0 deletions core/src/me/vinceh121/wanderer/building/AbstractBuilding.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected void onInteractContact(final btCollisionObject colObj0, final btCollis
if (!(this.game.getControlledEntity() instanceof CharacterW)) {
return;
}

final CharacterW chara = (CharacterW) this.game.getControlledEntity();

// if collided objects are interaction zone and player character
Expand All @@ -81,6 +82,7 @@ protected void onInteractStop(final btCollisionObject colObj0, final btCollision
if (!(this.game.getControlledEntity() instanceof CharacterW)) {
return;
}

final CharacterW chara = (CharacterW) this.game.getControlledEntity();

// if collided objects are interaction zone and player character
Expand Down Expand Up @@ -172,6 +174,7 @@ public void enterBtWorld(final btDiscreteDynamicsWorld world) {
@Override
public void leaveBtWorld(final btDiscreteDynamicsWorld world) {
super.leaveBtWorld(world);

if (this.interactZone != null && !this.interactZone.isDisposed()) {
world.removeCollisionObject(this.interactZone);
}
Expand Down Expand Up @@ -205,6 +208,7 @@ public void dispose() {
if (this.island != null) {
this.island.removeBuilding(this);
}

this.game.getPhysicsManager().removeContactListener(this.interactListener);
Gdx.app.postRunnable(() -> this.interactZone.dispose());
super.dispose();
Expand Down
107 changes: 107 additions & 0 deletions core/src/me/vinceh121/wanderer/entity/plane/AbstractPlane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package me.vinceh121.wanderer.entity.plane;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;

import me.vinceh121.wanderer.Wanderer;
import me.vinceh121.wanderer.building.ExplosionPart;
import me.vinceh121.wanderer.entity.AbstractClanLivingEntity;
import me.vinceh121.wanderer.entity.DisplayModel;
import me.vinceh121.wanderer.entity.IControllableEntity;
import me.vinceh121.wanderer.input.Input;
import me.vinceh121.wanderer.input.InputListener;
import me.vinceh121.wanderer.input.InputListenerAdapter;

public abstract class AbstractPlane extends AbstractClanLivingEntity implements IControllableEntity {
private final Array<DisplayModel> explosionParts = new Array<>();
private final PlaneSpeedProfile normal, turbo;
private boolean controlled;
private float speedUpTime;

public AbstractPlane(Wanderer game, AbstractPlaneMeta meta) {
super(game);

this.setCollideModel(meta.getCollisionModel());

for (final DisplayModel m : meta.getDisplayModels()) {
this.getModels().add(new DisplayModel(m));
}

for (final DisplayModel m : meta.getExplosionParts()) {
this.explosionParts.add(new DisplayModel(m));
}

this.normal = new PlaneSpeedProfile(meta.getNormal());
this.turbo = new PlaneSpeedProfile(meta.getTurbo());
}

@Override
public void tick(final float delta) {
super.tick(delta);

if (this.controlled) {
if (this.game.getInputManager().isPressed(Input.FLY_BOOST)) {
this.speedUpTime += delta; // FIXME upper clamp
} 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);

this.translate(0, 0, -speed * delta);

if (this.controlled) {
this.moveCamera();

if (this.game.getInputManager().isPressed(Input.FIRE)) {
this.fire();
}
}
}

protected void moveCamera() {
final Vector3 arm = new Vector3(0, 6, 17);
arm.mul(this.getRotation());
arm.add(this.getTranslation());

final Vector3 watch = new Vector3(0, 0, -50);
watch.mul(this.getRotation());
watch.add(this.getTranslation());

this.game.getCamera().position.set(arm);
this.game.getCamera().lookAt(watch);
}

public abstract void fire();

@Override
public void onDeath() {
this.game.removeEntity(this);
this.dispose();

for (final DisplayModel m : this.explosionParts) {
final ExplosionPart part = new ExplosionPart(this.game, m);
part.translate(this.getTranslation());
part.addEventListener("collideModelLoaded", e -> part.thrust(10));
this.game.addEntity(part);
}
}

@Override
public void onTakeControl() {
this.controlled = true;
}

@Override
public void onRemoveControl() {
this.controlled = false;
}

@Override
public InputListener getInputProcessor() {
return new InputListenerAdapter(50);
}
}
54 changes: 54 additions & 0 deletions core/src/me/vinceh121/wanderer/entity/plane/AbstractPlaneMeta.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package me.vinceh121.wanderer.entity.plane;

import com.badlogic.gdx.utils.Array;

import me.vinceh121.wanderer.IMeta;
import me.vinceh121.wanderer.entity.DisplayModel;

public abstract class AbstractPlaneMeta implements IMeta {
private Array<DisplayModel> displayModels = new Array<>();
private Array<DisplayModel> explosionParts = new Array<>();
private String collisionModel;
private final PlaneSpeedProfile normal = new PlaneSpeedProfile(), turbo = new PlaneSpeedProfile();
private float turboTime;

public Array<DisplayModel> getDisplayModels() {
return displayModels;
}

public void setDisplayModels(Array<DisplayModel> displayModels) {
this.displayModels = displayModels;
}

public Array<DisplayModel> getExplosionParts() {
return explosionParts;
}

public void setExplosionParts(Array<DisplayModel> explosionParts) {
this.explosionParts = explosionParts;
}

public String getCollisionModel() {
return collisionModel;
}

public void setCollisionModel(String collisionModel) {
this.collisionModel = collisionModel;
}

public PlaneSpeedProfile getNormal() {
return this.normal;
}

public PlaneSpeedProfile getTurbo() {
return this.turbo;
}

public float getTurboTime() {
return turboTime;
}

public void setTurboTime(float turboTime) {
this.turboTime = turboTime;
}
}
14 changes: 14 additions & 0 deletions core/src/me/vinceh121/wanderer/entity/plane/MachineGunPlane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.vinceh121.wanderer.entity.plane;

import me.vinceh121.wanderer.Wanderer;

public class MachineGunPlane extends AbstractPlane {

public MachineGunPlane(Wanderer game, MachineGunPlaneMeta meta) {
super(game, meta);
}

@Override
public void fire() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package me.vinceh121.wanderer.entity.plane;

import me.vinceh121.wanderer.Wanderer;
import me.vinceh121.wanderer.entity.AbstractEntity;

public class MachineGunPlaneMeta extends AbstractPlaneMeta {

@Override
public AbstractEntity create(Wanderer game) {
return new MachineGunPlane(game, this);
}
}
Loading

0 comments on commit 3f2c3d2

Please sign in to comment.