Skip to content

Commit

Permalink
javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
wil committed Jun 17, 2024
1 parent 1d9d360 commit bc01cb1
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public static void main(String[] args) {
app.start();
}

/*
* (non-Javadoc)
/* (non-Javadoc)
* @see com.jme3.app.SimpleApplication#simpleInitApp()
*/
@Override
Expand Down
44 changes: 38 additions & 6 deletions modules/samples/src/main/java/org/je3gl/demo/core/Character2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,59 @@
import org.je3gl.renderer.Camera2DRenderer;
import org.je3gl.scene.control.AnimatedSprite2D;
import org.je3gl.scene.shape.Sprite;

import static org.je3gl.utilities.GeometryUtilities.*;
import static org.je3gl.utilities.MaterialUtilities.*;

/**
*
* Class where a small platform game is exemplified and how it can be controlled
* using the jMe3GL2 library.
*
* @author wil
* @version 1.0.0
* @since 3.0.0
*/
public class Character2D extends SimpleApplication {

/**
* The main method; uses zero arguments in args array
* @param args command line arguments
*/
public static void main(String[] args) {
Character2D app = new Character2D();
app.start();
}

/** Object in charge of managing the 'A' key */
private static final BooleanStateKeyboardInputHandler VK_LEFT = new BooleanStateKeyboardInputHandler(new Key(KeyInput.KEY_A, "left"));
/** Object in charge of managing the 'D' key */
private static final BooleanStateKeyboardInputHandler VK_RIGHT = new BooleanStateKeyboardInputHandler(new Key(KeyInput.KEY_D, "right"));
/** Object in charge of managing the 'SPACE' key */
private static final BooleanStateKeyboardInputHandler VK_JUMP = new BooleanStateKeyboardInputHandler(new Key(KeyInput.KEY_SPACE, "jump"));

/**
* Control of the character (player) in the scene.
*/
private static class Player extends CharacterBody2D {

/** Speed ​​of movement. */
private Vector2 velocity = new Vector2(0, 0);
/** Maximum speed. */
private final double speed = 2;

/** Constructor- */
public Player() { }

/* (non-Javadoc)
* @see org.je3gl.physics.control.PhysicsBody2D#ready()
*/
@Override
protected void ready() {

}

/* (non-Javadoc)
* @see org.je3gl.physics.control.PhysicsBody2D#physicsProcess(float)
*/
@Override
protected void physicsProcess(float delta) {
applyControls();
Expand All @@ -107,6 +127,9 @@ protected void physicsProcess(float delta) {
setLinearVelocity(0, getLinearVelocity().y);
}

/**
* Apply controls to activate different player actions.
*/
private void applyControls() {
velocity = new Vector2(0.0, 0.0);
Sprite sprite = (Sprite) ((Geometry) spatial).getMesh();
Expand All @@ -119,13 +142,17 @@ private void applyControls() {
sprite.flipH(false);
}

if (VK_JUMP.isActiveButNotHandled()) {
// jump
if (VK_JUMP.isActiveButNotHandled() && isOnFloor()) {
VK_JUMP.setHasBeenHandled(true);

applyImpulse(new Vector2(0, 4));
}
}

/**
* Depending on the player's status, an animation will be activated.
*/
private void applyAnimation() {
if (isOnFloor() || isOnWall()) {
if (Math.abs(velocity.x) > 0) {
Expand All @@ -139,6 +166,9 @@ private void applyAnimation() {
}
}

/* (non-Javadoc)
* @see com.jme3.app.SimpleApplication#simpleInitApp()
*/
@Override
public void simpleInitApp() {
Camera2DRenderer camera2DRenderer = new Camera2DRenderer(Camera2DRenderer.GLRendererType.GLX_25D, 5, 45);
Expand All @@ -159,10 +189,15 @@ public void simpleInitApp() {
prepareCharacter();
}

/**
* Prepare the character (2D model) and animations.
*/
@SuppressWarnings("unchecked")
private void prepareCharacter() {
Dyn4jAppState<PhysicsBody2D> dyn4jAppState = stateManager.getState(Dyn4jAppState.class);

// We load a JME3 object (j3o), this is possible thanks to the
// serialization of jMe3GL2 objects (supported)
Spatial player = assetManager.loadModel("Models/Rabbit.j3o");
player.getControl(AnimatedSprite2D.class).playAnimation("walk", 10);
rootNode.attachChild(player);
Expand All @@ -171,8 +206,6 @@ private void prepareCharacter() {
body2D.setGravityScale(2);

BodyFixture bf = new BodyFixture(dyn4jCreateCapsule(0.5, 1));


body2D.addFixture(bf);
body2D.setMass(MassType.NORMAL);
body2D.translate(0, 0);
Expand Down Expand Up @@ -242,6 +275,5 @@ private void prepareSimpleTerrain() {

dyn4jAppState.getPhysicsSpace().addBody(body2DGround);
rootNode.attachChild(ground);

}
}
24 changes: 23 additions & 1 deletion modules/samples/src/main/java/org/je3gl/demo/core/ExportJ2O.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,38 @@
import static org.je3gl.utilities.TextureUtilities.*;

/**
*
* Class where the export (serialization) of objects is exemplified.
* @author wil
* @version 1.0.0
* @since 3.0.0
*/
public class ExportJ2O extends SimpleApplication {

/** root path (absolute). */
private static final String ROOT_PATH ;
/** Margin used by JME materials (transparency). */
private static final float ALPHA_DISCARD_THRESHOLD;
// init
static {
ROOT_PATH = System.getProperty("user.dir") + "/src/main/resources/Models/";
ALPHA_DISCARD_THRESHOLD = 0.01f;
}

/**
* The main method; uses zero arguments in args array
* @param args command line arguments
*/
public static void main(String[] args) {
ExportJ2O app = new ExportJ2O();
app.start();
}

/** physical space dyn4j. */
Dyn4jAppState<PhysicsBody2D> dyn4jAppState;

/* (non-Javadoc)
* @see com.jme3.app.SimpleApplication#simpleInitApp()
*/
@Override
public void simpleInitApp() {
dyn4jAppState = new Dyn4jAppState<>(ThreadingType.SEQUENTIAL);
Expand All @@ -86,6 +97,9 @@ public void simpleInitApp() {
//j2oTanks();
}

/**
* Building a j2o model.
*/
private void j2oTanks() {
Node tanks = new Node("Tanks");
tanks.setQueueBucket(RenderQueue.Bucket.Transparent);
Expand Down Expand Up @@ -215,6 +229,9 @@ private void j2oTanks() {
export(tanks, "TankNavy.j2o");
}

/**
* Building a j3o model.
*/
private void j3oRabbit() {
Geometry player = new Geometry("AnimatedSprite2D", new Sprite(1.0F, 1.0F));
player.setMaterial(getUnshadedMaterialFromClassPath(assetManager, "Textures/Rabbit/tile_0040.png"));
Expand All @@ -240,6 +257,11 @@ private void j3oRabbit() {
export(player, "Rabbit.j3o");
}

/**
* Save the models to disk.
* @param obj model
* @param name path-name
*/
private static void export(Savable obj, String name) {
try {
BinaryExporter exporter = BinaryExporter.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import com.jme3.app.SimpleApplication;
import com.jme3.scene.Geometry;

import org.je3gl.physics.Dyn4jAppState;
import org.je3gl.physics.ThreadingType;
import org.je3gl.physics.control.PhysicsBody2D;
Expand All @@ -42,6 +43,7 @@
import static org.je3gl.utilities.GeometryUtilities.*;
import static org.je3gl.utilities.MaterialUtilities.*;
import static org.je3gl.utilities.TileMapUtilities.*;

import org.dyn4j.dynamics.BodyFixture;
import org.dyn4j.geometry.MassType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public static void main(String[] args) {
app.start();
}

/*
* (non-Javadoc)
/* (non-Javadoc)
* @see com.jme3.app.SimpleApplication#simpleInitApp()
*/
@Override
Expand Down
47 changes: 38 additions & 9 deletions modules/samples/src/main/java/org/je3gl/demo/core/Tanks2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;

import org.dyn4j.dynamics.BodyFixture;
import org.dyn4j.geometry.Mass;
import org.dyn4j.geometry.MassType;
import org.dyn4j.geometry.Vector2;

import org.je3gl.physics.Dyn4jAppState;
import org.je3gl.physics.ThreadingType;
import org.je3gl.physics.control.PhysicsBody2D;
Expand All @@ -59,21 +61,37 @@
import static org.je3gl.utilities.MaterialUtilities.*;

/**
*
* Class where the use of class {@link org.je3gl.physics.control.Vehicle2D} is
* exemplified, using articulations (Joint).
*
* @author wil
* @version 1.0.0
* @since 3.0.0
*/
public class Tanks2D extends SimpleApplication {

/**
* The main method; uses zero arguments in args array
* @param args command line arguments
*/
public static void main(String[] args) {
Tanks2D app = new Tanks2D();
app.start();
}

/** Object in charge of managing the 'T' key */
private static final BooleanStateKeyboardInputHandler VK_LEFT = new BooleanStateKeyboardInputHandler(new Key(KeyInput.KEY_T, "left"));
/** Object in charge of managing the 'Y' key */
private static final BooleanStateKeyboardInputHandler VK_RIGHT = new BooleanStateKeyboardInputHandler(new Key(KeyInput.KEY_Y, "right"));

private static class TanksControl extends AbstractControl {
/**
* Vehicle control (Tank).
*/
private static class TankControl extends AbstractControl {

/* (non-Javadoc)
* @see com.jme3.scene.control.AbstractControl#controlUpdate(float)
*/
@Override
protected void controlUpdate(float tpf) {
if (VK_LEFT.isActive()) {
Expand All @@ -85,16 +103,21 @@ protected void controlUpdate(float tpf) {
}
}

/* (non-Javadoc)
* @see com.jme3.scene.control.AbstractControl#controlRender(com.jme3.renderer.RenderManager, com.jme3.renderer.ViewPort)
*/
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {

// nothing
}
}

/* (non-Javadoc)
* @see com.jme3.app.SimpleApplication#simpleInitApp()
*/
@Override
public void simpleInitApp() {
J2OLoader.initialize(this);

J2OLoader.initialize(this);
Camera2DRenderer camera2DRenderer = new Camera2DRenderer(Camera2DRenderer.GLRendererType.GLX_25D, 5, 45);
stateManager.attach(camera2DRenderer);

Expand All @@ -112,19 +135,22 @@ public void simpleInitApp() {
prepareCharacters();
}

/**
* Prepare the character (2D model) and animations.
*/
@SuppressWarnings("unchecked")
private void prepareCharacters() {
Dyn4jAppState<PhysicsBody2D> dyn4jAppState = stateManager.getState(Dyn4jAppState.class);

Spatial tank = J2OLoader.load(new J2OKey<>("Models/TankNavy.j2o"));
Spatial tank = assetManager.loadAsset(new J2OKey<>("Models/TankNavy.j2o"));
tank.getControl(PhysicsBody2D.class).setMass(new Mass(new Vector2(), 10, 0));
tank.getControl(PhysicsBody2D.class).translate(-3, 0);
tank.addControl(new TanksControl());

tank.addControl(new TankControl());
dyn4jAppState.getPhysicsSpace().addPhysicsBody(tank, true);
rootNode.attachChild(tank);

Spatial tank2 = J2OLoader.load(new J2OKey<>("Models/TankNavy.j2o"));
Spatial tank2 = assetManager.loadAsset(new J2OKey<>("Models/TankNavy.j2o"));

tank2.getControl(PhysicsBody2D.class).setMass(new Mass(new Vector2(), 10, 0));
tank2.getControl(PhysicsBody2D.class).translate(3, 0);
Expand All @@ -133,6 +159,9 @@ private void prepareCharacters() {
rootNode.attachChild(tank2);
}

/**
* Prepare a simple terrain.
*/
@SuppressWarnings("unchecked")
private void prepareSimpleTerrain() {
Dyn4jAppState<PhysicsBody2D> dyn4jAppState = stateManager.getState(Dyn4jAppState.class);
Expand Down

0 comments on commit bc01cb1

Please sign in to comment.