spawned Stars (not tested), refactored some stuff
This commit is contained in:
parent
0d2ec02510
commit
b8fa020781
@ -23,6 +23,7 @@ import com.jme3.scene.Spatial;
|
|||||||
import com.jme3.scene.control.Control;
|
import com.jme3.scene.control.Control;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.wyrez.shootingstars.data.AudioDataManager;
|
import org.wyrez.shootingstars.data.AudioDataManager;
|
||||||
|
import org.wyrez.shootingstars.helper.ColorHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -53,7 +54,7 @@ public class GroundGlowControl extends BaseControl {
|
|||||||
if (audioDataManager.isFlash() && glowTimer <= 0f) {
|
if (audioDataManager.isFlash() && glowTimer <= 0f) {
|
||||||
if (random.nextBoolean()) {
|
if (random.nextBoolean()) {
|
||||||
glowTimer = GLOW_DURATION;
|
glowTimer = GLOW_DURATION;
|
||||||
color = calcColor(audioDataManager.getFlashData());
|
color = ColorHelper.calcColor(audioDataManager.getFlashData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,28 +71,6 @@ public class GroundGlowControl extends BaseControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ColorRGBA calcColor(float value) {
|
|
||||||
int r, g, b;
|
|
||||||
if (value < 0.25f) {
|
|
||||||
r = 0;
|
|
||||||
g = Math.round(255 * value / 0.25f);
|
|
||||||
b = 255;
|
|
||||||
} else if (value < 0.5f) {
|
|
||||||
r = 0;
|
|
||||||
g = 255;
|
|
||||||
b = Math.round(255 * ((0.25f - (value - 0.25f)) / 0.25f));
|
|
||||||
} else if (value < 0.75f) {
|
|
||||||
g = 255;
|
|
||||||
r = Math.round(255 * (value - 0.5f) / 0.25f);
|
|
||||||
b = 0;
|
|
||||||
} else {
|
|
||||||
g = Math.round(255 * ((0.25f - (value - 0.75f)) / 0.25f));
|
|
||||||
r = 255;
|
|
||||||
b = 0;
|
|
||||||
}
|
|
||||||
return new ColorRGBA((float) r / 255f, (float) g / 255f, (float) b / 255f, 1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Control cloneForSpatial(Spatial spatial) {
|
public Control cloneForSpatial(Spatial spatial) {
|
||||||
GroundGlowControl control = new GroundGlowControl(audioDataManager);
|
GroundGlowControl control = new GroundGlowControl(audioDataManager);
|
||||||
control.setSpatial(spatial);
|
control.setSpatial(spatial);
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.wyrez.shootingstars.controls;
|
package org.wyrez.shootingstars.controls;
|
||||||
|
|
||||||
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.renderer.Camera;
|
import com.jme3.renderer.Camera;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.control.Control;
|
import com.jme3.scene.control.Control;
|
||||||
@ -26,21 +27,21 @@ import org.wyrez.shootingstars.helper.UserDataKeys;
|
|||||||
* @author Darth Affe
|
* @author Darth Affe
|
||||||
*/
|
*/
|
||||||
public class PlayerCamControl extends BaseControl {
|
public class PlayerCamControl extends BaseControl {
|
||||||
|
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
|
|
||||||
public PlayerCamControl(Camera camera) {
|
public PlayerCamControl(Camera camera) {
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float tpf) {
|
public void update(float tpf) {
|
||||||
if (spatial.getUserData(UserDataKeys.RUNNING)) {
|
if (spatial.getUserData(UserDataKeys.RUNNING)) {
|
||||||
camera.setLocation(spatial.getLocalTranslation().add(10f,10f,10f));
|
camera.setLocation(spatial.getLocalTranslation());
|
||||||
camera.setRotation(spatial.getLocalRotation());
|
camera.setRotation(spatial.getLocalRotation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Control cloneForSpatial(Spatial spatial) {
|
public Control cloneForSpatial(Spatial spatial) {
|
||||||
PlayerCamControl control = new PlayerCamControl(camera);
|
PlayerCamControl control = new PlayerCamControl(camera);
|
||||||
control.setSpatial(spatial);
|
control.setSpatial(spatial);
|
||||||
|
|||||||
@ -17,8 +17,10 @@
|
|||||||
package org.wyrez.shootingstars.controls;
|
package org.wyrez.shootingstars.controls;
|
||||||
|
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.control.Control;
|
import com.jme3.scene.control.Control;
|
||||||
|
import org.wyrez.shootingstars.helper.ColorHelper;
|
||||||
import org.wyrez.shootingstars.helper.UserDataKeys;
|
import org.wyrez.shootingstars.helper.UserDataKeys;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,35 +29,43 @@ import org.wyrez.shootingstars.helper.UserDataKeys;
|
|||||||
*/
|
*/
|
||||||
public class StarPointControl extends BaseControl {
|
public class StarPointControl extends BaseControl {
|
||||||
|
|
||||||
private int points = 100; //Todo Change StartPoint at Spawn
|
private static final float MAX_POINTS = 100f;
|
||||||
|
private static final float HIT_TIMER = 10f;
|
||||||
|
/**/
|
||||||
|
private float points;
|
||||||
private Spatial player;
|
private Spatial player;
|
||||||
private ColorRGBA starColor;
|
private ColorRGBA color;
|
||||||
|
private float timer;
|
||||||
public StarPointControl(Spatial player) {
|
|
||||||
|
public StarPointControl(Spatial player, float value) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.points = (int) Math.round(MAX_POINTS * value);
|
||||||
|
this.timer = HIT_TIMER;
|
||||||
|
this.color = ColorHelper.calcColor(value / MAX_POINTS);
|
||||||
|
((Geometry) spatial).getMaterial().setColor("Color", color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void controlUpdate(float tpf) {
|
protected void controlUpdate(float tpf) {
|
||||||
if (spatial.getUserData(UserDataKeys.HITTED)) {
|
if (spatial.getUserData(UserDataKeys.HITTED)) {
|
||||||
int pointsToAdd = Integer.parseInt(player.getUserData(UserDataKeys.POINTS).toString()) + points;
|
player.setUserData(UserDataKeys.POINTS, (Integer) (player.getUserData(UserDataKeys.POINTS))
|
||||||
player.setUserData(UserDataKeys.POINTS, pointsToAdd);
|
+ (int) Math.round(points));
|
||||||
} else {
|
} else if (timer <= 0f) {
|
||||||
points -= tpf / 2;
|
if (points > 1f) {
|
||||||
if(points < 75) {
|
points -= 2f * tpf;
|
||||||
starColor = new ColorRGBA(0.5f, 0.5f, 0.5f, 1f);
|
color = ColorHelper.calcColor(points / MAX_POINTS);
|
||||||
//Todo Set color to spatial
|
} else if (points < 1f) {
|
||||||
|
points = 1f;
|
||||||
|
color = ColorHelper.calcColor(points / MAX_POINTS);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
timer -= tpf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Control cloneForSpatial(Spatial spatial) {
|
public Control cloneForSpatial(Spatial spatial) {
|
||||||
StarPointControl control = new StarPointControl(player);
|
StarPointControl control = new StarPointControl(player, (float) points);
|
||||||
spatial.addControl(control);
|
spatial.addControl(control);
|
||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPoints() {
|
|
||||||
return this.points;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,11 +45,13 @@ public class AudioDataManager {
|
|||||||
// private float[] movementData;
|
// private float[] movementData;
|
||||||
private float[] flashData;
|
private float[] flashData;
|
||||||
private float[] groundMoveData;
|
private float[] groundMoveData;
|
||||||
|
private float[] spawnData;
|
||||||
private float peakAverageFlash;
|
private float peakAverageFlash;
|
||||||
private float indexFactor;
|
private float indexFactor;
|
||||||
private float bpm;
|
private float bpm;
|
||||||
private float currentTime;
|
private float currentTime;
|
||||||
private float lastTimeSync;
|
private float lastTimeSync;
|
||||||
|
private int lastSpawnDataPollIndex;
|
||||||
|
|
||||||
public void AudioDataManager() {
|
public void AudioDataManager() {
|
||||||
}
|
}
|
||||||
@ -118,7 +120,18 @@ public class AudioDataManager {
|
|||||||
|
|
||||||
public void analyseMidBand() {
|
public void analyseMidBand() {
|
||||||
audioProcessorMidBand.calculate();
|
audioProcessorMidBand.calculate();
|
||||||
audioProcessorMidBand.cutFastPeaks(MIN_PEAK_DIFF);
|
|
||||||
|
spawnData = audioProcessorMidBand.getPeaks();
|
||||||
|
float minValue = audioProcessorMidBand.getPeakAverage() * 0.5f;
|
||||||
|
float maxValue = audioProcessorHighBand.getPeakAverage() * 2f;
|
||||||
|
for (int i = 0; i < spawnData.length; i++) {
|
||||||
|
if (spawnData[i] > maxValue) {
|
||||||
|
spawnData[i] = maxValue;
|
||||||
|
} else if (spawnData[i] < minValue) {
|
||||||
|
spawnData[i] = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SampleHelper.normalize(spawnData, 0f, 1f);
|
||||||
|
|
||||||
audioProcessorMidBand.clean();
|
audioProcessorMidBand.clean();
|
||||||
audioProcessorMidBand = null;
|
audioProcessorMidBand = null;
|
||||||
@ -192,24 +205,32 @@ public class AudioDataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float getGroundMoveData() {
|
public float getGroundMoveData() {
|
||||||
return groundMoveData[calcIndex(flashData.length)];
|
return groundMoveData[calcIndex(groundMoveData.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getMovementData() {
|
public float getMovementData() {
|
||||||
return 0.25f;
|
return 0.25f;
|
||||||
// System.out.println(currentTime + " * " + indexFactor + " = " + calcIndex() + " --> " + movementData[calcIndex()]);
|
|
||||||
// return movementData[calcIndex()];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getSpeedData() {
|
public float getSpeedData() {
|
||||||
return speedData[calcIndex(flashData.length)];
|
return speedData[calcIndex(speedData.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getMidData() {
|
public float[] getSpawnData() {
|
||||||
return 0f; //TODO implement
|
int index = calcIndex(spawnData.length);
|
||||||
}
|
float[] data;
|
||||||
|
if (index == lastSpawnDataPollIndex) {
|
||||||
public float getHighData() {
|
data = null;
|
||||||
return 0f; //TODO implement
|
} else if (index - 1 != lastSpawnDataPollIndex) {
|
||||||
|
data = new float[index - lastSpawnDataPollIndex];
|
||||||
|
for (int i = 0; i < data.length; i++) {
|
||||||
|
data[i] = spawnData[lastSpawnDataPollIndex + 1 + i];
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
} else {
|
||||||
|
data = new float[]{spawnData[index]};
|
||||||
|
}
|
||||||
|
lastSpawnDataPollIndex = index;
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,8 @@ public enum Materials {
|
|||||||
UNSHADED("Common/MatDefs/Misc/Unshaded.j3md", null, null, null),
|
UNSHADED("Common/MatDefs/Misc/Unshaded.j3md", null, null, null),
|
||||||
HEX("Common/MatDefs/Light/Lighting.j3md", "Textures/Hex.png", null, null),
|
HEX("Common/MatDefs/Light/Lighting.j3md", "Textures/Hex.png", null, null),
|
||||||
WEAPON("Common/MatDefs/Light/Lighting.j3md", null, ColorRGBA.White, ColorRGBA.Cyan),
|
WEAPON("Common/MatDefs/Light/Lighting.j3md", null, ColorRGBA.White, ColorRGBA.Cyan),
|
||||||
GLOW("Common/MatDefs/Light/Lighting.j3md", null, ColorRGBA.White, ColorRGBA.Black);
|
GLOW("Common/MatDefs/Light/Lighting.j3md", null, ColorRGBA.White, ColorRGBA.Black),
|
||||||
|
STAR("Common/MatDefs/Misc/Unshaded.j3md", null, null, null);
|
||||||
private static AssetManager assetManager;
|
private static AssetManager assetManager;
|
||||||
private String material;
|
private String material;
|
||||||
private String texture;
|
private String texture;
|
||||||
|
|||||||
@ -41,14 +41,15 @@ public class GlowingHexPrism extends Node {
|
|||||||
|
|
||||||
Material prismMat = Materials.HEX.create();
|
Material prismMat = Materials.HEX.create();
|
||||||
prismMat.setColor("Diffuse", ColorRGBA.Black);
|
prismMat.setColor("Diffuse", ColorRGBA.Black);
|
||||||
prism = new Geometry("Prism " + position, new HexPrism(position, size, height));
|
prism = new Geometry("Prism " + position, new HexPrism(size, height));
|
||||||
prism.setMaterial(prismMat);
|
prism.setMaterial(prismMat);
|
||||||
|
prism.setLocalTranslation(position);
|
||||||
this.attachChild(prism);
|
this.attachChild(prism);
|
||||||
|
|
||||||
Material glowMat = Materials.GLOW.create();
|
Material glowMat = Materials.GLOW.create();
|
||||||
glow = new Geometry("Prism " + position, new HexPrism(position.add(
|
glow = new Geometry("Prism " + position, new HexPrism(size * glowPercentage, height * 0.001f));
|
||||||
0f, height, 0f), size * glowPercentage, height * 0.001f));
|
|
||||||
glow.setMaterial(glowMat);
|
glow.setMaterial(glowMat);
|
||||||
|
glow.setLocalTranslation(position.add(0f, height, 0f));
|
||||||
this.attachChild(glow);
|
this.attachChild(glow);
|
||||||
|
|
||||||
glow.addControl(new GroundGlowControl(adm));
|
glow.addControl(new GroundGlowControl(adm));
|
||||||
|
|||||||
@ -33,15 +33,15 @@ import org.wyrez.shootingstars.mesh.HexPrism;
|
|||||||
* @author Darth Affe
|
* @author Darth Affe
|
||||||
*/
|
*/
|
||||||
public class Ground extends Node {
|
public class Ground extends Node {
|
||||||
|
|
||||||
public Ground(AudioDataManager adm) {
|
public Ground(AudioDataManager adm) {
|
||||||
this(adm, 1000f);
|
this(adm, 1000f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ground(AudioDataManager adm, float radius) {
|
public Ground(AudioDataManager adm, float radius) {
|
||||||
this(adm, radius, 0.1f);
|
this(adm, radius, 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ground(AudioDataManager adm, float radius, float factor) {
|
public Ground(AudioDataManager adm, float radius, float factor) {
|
||||||
super("Ground");
|
super("Ground");
|
||||||
generateHexGrid(adm, radius, factor);
|
generateHexGrid(adm, radius, factor);
|
||||||
@ -52,11 +52,11 @@ public class Ground extends Node {
|
|||||||
private void generateHexGrid(AudioDataManager adm, float borderWidth, float factor) {
|
private void generateHexGrid(AudioDataManager adm, float borderWidth, float factor) {
|
||||||
float size = borderWidth * factor;
|
float size = borderWidth * factor;
|
||||||
int maxIterations = (int) (borderWidth / size) - 2;
|
int maxIterations = (int) (borderWidth / size) - 2;
|
||||||
|
|
||||||
Node prism = new GlowingHexPrism(new Vector3f(0f, -140f, 0f), size, 150f, 0.8f, adm);
|
Node prism = new GlowingHexPrism(new Vector3f(0f, -140f, 0f), size, 150f, 0.8f, adm);
|
||||||
prism.addControl(new GroundMoveControl(adm));
|
prism.addControl(new GroundMoveControl(adm));
|
||||||
this.attachChild(prism);
|
this.attachChild(prism);
|
||||||
|
|
||||||
float xcc = 0f;
|
float xcc = 0f;
|
||||||
float ycc = 0f;
|
float ycc = 0f;
|
||||||
float centerDistance = size * FastMath.sqrt(3f);
|
float centerDistance = size * FastMath.sqrt(3f);
|
||||||
@ -65,13 +65,14 @@ public class Ground extends Node {
|
|||||||
float yc = ycc - (float) iteration * centerDistance;
|
float yc = ycc - (float) iteration * centerDistance;
|
||||||
float dx = (FastMath.sqrt(3f) * centerDistance / 2f);
|
float dx = (FastMath.sqrt(3f) * centerDistance / 2f);
|
||||||
float dy = centerDistance / 2f;
|
float dy = centerDistance / 2f;
|
||||||
|
|
||||||
for (int directions = 0; directions < 6; directions++) {
|
for (int directions = 0; directions < 6; directions++) {
|
||||||
for (int steps = 0; steps < iteration; steps++) {
|
for (int steps = 0; steps < iteration; steps++) {
|
||||||
if ((iteration == maxIterations - 1)) {
|
if ((iteration == maxIterations - 1)) {
|
||||||
Geometry hex = new Geometry("Prism_" + xc + " - " + yc,
|
Geometry hex = new Geometry("Prism_" + xc + " - " + yc,
|
||||||
new HexPrism(new Vector3f(xc, 0f, yc), size, 160f));
|
new HexPrism(size, 160f));
|
||||||
hex.setMaterial(Materials.HEX.create());
|
hex.setMaterial(Materials.HEX.create());
|
||||||
|
hex.setLocalTranslation(new Vector3f(xc, 0f, yc));
|
||||||
hex.addControl(new GroundBorderGlowControl(adm));
|
hex.addControl(new GroundBorderGlowControl(adm));
|
||||||
this.attachChild(hex);
|
this.attachChild(hex);
|
||||||
} else {
|
} else {
|
||||||
@ -90,7 +91,7 @@ public class Ground extends Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLight() {
|
private void addLight() {
|
||||||
AmbientLight ambient = new AmbientLight();
|
AmbientLight ambient = new AmbientLight();
|
||||||
ambient.setColor(ColorRGBA.White);
|
ambient.setColor(ColorRGBA.White);
|
||||||
|
|||||||
@ -8,20 +8,19 @@ import tonegod.gui.core.Screen;
|
|||||||
*/
|
*/
|
||||||
public class ScreenHelper {
|
public class ScreenHelper {
|
||||||
|
|
||||||
private static final float X = 1280;
|
private static final float WIDTH = 1280;
|
||||||
private static final float Y = 720;
|
private static final float HEIGHT = 720;
|
||||||
private Screen screen;
|
private Screen screen;
|
||||||
|
|
||||||
|
|
||||||
public ScreenHelper(Screen screen) {
|
public ScreenHelper(Screen screen) {
|
||||||
this.screen = screen;
|
this.screen = screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float calcX(float value) {
|
public float calcX(float value) {
|
||||||
return screen.getWidth() * ((100/X) * value) / 100;
|
return screen.getWidth() * ((100f / WIDTH) * value) / 100f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float calcY(float value) {
|
public float calcY(float value) {
|
||||||
return screen.getHeight() * ((100/Y) * value) / 100;
|
return screen.getHeight() * ((100f / HEIGHT) * value) / 100f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,7 @@ public class HexPrism extends Mesh {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//TODO remove bottom for better performance
|
//TODO remove bottom for better performance
|
||||||
|
|
||||||
private static final short[] GEOMETRY_INDICES_DATA = {
|
private static final short[] GEOMETRY_INDICES_DATA = {
|
||||||
0, 1, 2,/**/ 2, 3, 0,/**/ 0, 3, 4,/**/ 4, 5, 0,/**/ 0, 5, 6,/**/ 6, 1, 0, // bottom
|
0, 1, 2,/**/ 2, 3, 0,/**/ 0, 3, 4,/**/ 4, 5, 0,/**/ 0, 5, 6,/**/ 6, 1, 0, // bottom
|
||||||
//0, 1, 6,/**/ 6, 5, 0,/**/ 0, 5, 4,/**/ 4, 3, 0,/**/ 0, 3, 2,/**/ 2, 1, 0, // reverse bottom
|
//0, 1, 6,/**/ 6, 5, 0,/**/ 0, 5, 4,/**/ 4, 3, 0,/**/ 0, 3, 2,/**/ 2, 1, 0, // reverse bottom
|
||||||
@ -62,17 +63,12 @@ public class HexPrism extends Mesh {
|
|||||||
0.5f, 0.5f, 0, 0.5f, 0.25f, 0, 0.75f, 0, 1, 0.5f, 0.75f, 1, 0.25f, 1,//bottom
|
0.5f, 0.5f, 0, 0.5f, 0.25f, 0, 0.75f, 0, 1, 0.5f, 0.75f, 1, 0.25f, 1,//bottom
|
||||||
0.5f, 0.5f, 0, 0.5f, 0.25f, 0, 0.75f, 0, 1, 0.5f, 0.75f, 1, 0.25f, 1 //top
|
0.5f, 0.5f, 0, 0.5f, 0.25f, 0, 0.75f, 0, 1, 0.5f, 0.75f, 1, 0.25f, 1 //top
|
||||||
};
|
};
|
||||||
private Vector3f center;
|
|
||||||
private float radius;
|
private float radius;
|
||||||
private float height;
|
private float height;
|
||||||
|
|
||||||
public HexPrism(float radius, float height) {
|
public HexPrism(float radius, float height) {
|
||||||
this(Vector3f.ZERO, radius, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HexPrism(Vector3f center, float radius, float height) {
|
|
||||||
super();
|
super();
|
||||||
updateGeometry(center, radius, height);
|
updateGeometry(radius, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,11 +80,10 @@ public class HexPrism extends Mesh {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HexPrism clone() {
|
public HexPrism clone() {
|
||||||
return new HexPrism(center.clone(), radius, height);
|
return new HexPrism(radius, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void updateGeometry(Vector3f center, float radius, float height) {
|
protected final void updateGeometry(float radius, float height) {
|
||||||
this.center = center;
|
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
updateGeometryIndices();
|
updateGeometryIndices();
|
||||||
@ -124,13 +119,13 @@ public class HexPrism extends Mesh {
|
|||||||
protected Vector3f[] computeVertices() {
|
protected Vector3f[] computeVertices() {
|
||||||
Vector3f[] vertices = new Vector3f[14];
|
Vector3f[] vertices = new Vector3f[14];
|
||||||
//bottom
|
//bottom
|
||||||
vertices[0] = center;
|
vertices[0] = new Vector3f(Vector3f.ZERO);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
vertices[i + 1] = new Vector3f(vertices[0].x + radius * FastMath.cos(i * FastMath.PI / 3),
|
vertices[i + 1] = new Vector3f(vertices[0].x + radius * FastMath.cos(i * FastMath.PI / 3),
|
||||||
vertices[0].y, (vertices[0].z + radius * FastMath.sin(i * FastMath.PI / 3)));
|
vertices[0].y, (vertices[0].z + radius * FastMath.sin(i * FastMath.PI / 3)));
|
||||||
}
|
}
|
||||||
//top
|
//top
|
||||||
vertices[7] = center.add(0f, height, 0f);
|
vertices[7] = Vector3f.ZERO.add(0f, height, 0f);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
vertices[i + 8] = new Vector3f(vertices[7].x + radius * FastMath.cos(i * FastMath.PI / 3),
|
vertices[i + 8] = new Vector3f(vertices[7].x + radius * FastMath.cos(i * FastMath.PI / 3),
|
||||||
vertices[7].y, (vertices[7].z + radius * FastMath.sin(i * FastMath.PI / 3)));
|
vertices[7].y, (vertices[7].z + radius * FastMath.sin(i * FastMath.PI / 3)));
|
||||||
|
|||||||
@ -38,18 +38,13 @@ public class Star extends Mesh {
|
|||||||
0.5f, 0.5f, /**/ 0.5f, 0f,/**/ 0.75f, 0.25f,/**/ 1f, 0f,/**/ 0.75f, 0.5f,/**/ 1f, 1f,/**/ 0.75f, 0.75f,
|
0.5f, 0.5f, /**/ 0.5f, 0f,/**/ 0.75f, 0.25f,/**/ 1f, 0f,/**/ 0.75f, 0.5f,/**/ 1f, 1f,/**/ 0.75f, 0.75f,
|
||||||
1f, 0.5f,/**/ 0.25f, 0.75f,/**/ 0f, 1f,/**/ 0f, 0.5f,/**/ 0f, 0f,/**/ 0.25f, 0.25f,/**/ 0f, 0f
|
1f, 0.5f,/**/ 0.25f, 0.75f,/**/ 0f, 1f,/**/ 0f, 0.5f,/**/ 0f, 0f,/**/ 0.25f, 0.25f,/**/ 0f, 0f
|
||||||
};
|
};
|
||||||
private Vector3f center;
|
|
||||||
private float radius;
|
private float radius;
|
||||||
private float height;
|
private float height;
|
||||||
private float factor;
|
private float factor;
|
||||||
|
|
||||||
public Star(float radius, float height, float factor) {
|
public Star(float radius, float height, float factor) {
|
||||||
this(Vector3f.ZERO, radius, height, factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Star(Vector3f center, float radius, float height, float factor) {
|
|
||||||
super();
|
super();
|
||||||
updateGeometry(center, radius, height, factor);
|
updateGeometry(radius, height, factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,11 +56,10 @@ public class Star extends Mesh {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Star clone() {
|
public Star clone() {
|
||||||
return new Star(center.clone(), radius, height, factor);
|
return new Star(radius, height, factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void updateGeometry(Vector3f center, float radius, float height, float factor) {
|
protected final void updateGeometry(float radius, float height, float factor) {
|
||||||
this.center = center;
|
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.factor = factor;
|
this.factor = factor;
|
||||||
@ -94,17 +88,17 @@ public class Star extends Mesh {
|
|||||||
|
|
||||||
protected Vector3f[] computeVertices() {
|
protected Vector3f[] computeVertices() {
|
||||||
Vector3f[] vertices = new Vector3f[14];
|
Vector3f[] vertices = new Vector3f[14];
|
||||||
vertices[0] = new Vector3f(new Vector3f(center.x, center.y - (height / 2f), center.z));
|
vertices[0] = new Vector3f(new Vector3f(0f, -(height / 2f), 0f));
|
||||||
vertices[13] = new Vector3f(new Vector3f(center.x, center.y + (height / 2f), center.z));;
|
vertices[13] = new Vector3f(new Vector3f(0f, (height / 2f), 0f));
|
||||||
//outer
|
//outer
|
||||||
for (int i = 0; i < 12; i += 2) {
|
for (int i = 0; i < 12; i += 2) {
|
||||||
vertices[i + 1] = new Vector3f(center.x + radius * FastMath.cos(i * FastMath.PI / 6),
|
vertices[i + 1] = new Vector3f(radius * FastMath.cos(i * FastMath.PI / 6),
|
||||||
center.y, (center.z + radius * FastMath.sin(i * FastMath.PI / 6)));
|
0f, (radius * FastMath.sin(i * FastMath.PI / 6)));
|
||||||
}
|
}
|
||||||
//inner
|
//inner
|
||||||
for (int i = 1; i < 12; i += 2) {
|
for (int i = 1; i < 12; i += 2) {
|
||||||
vertices[i + 1] = new Vector3f(center.x + (radius * factor) * FastMath.cos(i * FastMath.PI / 6),
|
vertices[i + 1] = new Vector3f((radius * factor) * FastMath.cos(i * FastMath.PI / 6),
|
||||||
center.y, (center.z + (radius * factor) * FastMath.sin(i * FastMath.PI / 6)));
|
0f, ((radius * factor) * FastMath.sin(i * FastMath.PI / 6)));
|
||||||
}
|
}
|
||||||
return vertices;
|
return vertices;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,27 +21,18 @@ import com.jme3.app.state.AppStateManager;
|
|||||||
import com.jme3.asset.AssetManager;
|
import com.jme3.asset.AssetManager;
|
||||||
import com.jme3.input.InputManager;
|
import com.jme3.input.InputManager;
|
||||||
import com.jme3.input.controls.ActionListener;
|
import com.jme3.input.controls.ActionListener;
|
||||||
import com.jme3.math.Vector3f;
|
|
||||||
import com.jme3.post.FilterPostProcessor;
|
import com.jme3.post.FilterPostProcessor;
|
||||||
import com.jme3.post.filters.BloomFilter;
|
import com.jme3.post.filters.BloomFilter;
|
||||||
import com.jme3.renderer.Camera;
|
import com.jme3.renderer.Camera;
|
||||||
import com.jme3.renderer.RenderManager;
|
import com.jme3.renderer.RenderManager;
|
||||||
import com.jme3.renderer.ViewPort;
|
import com.jme3.renderer.ViewPort;
|
||||||
import com.jme3.scene.Geometry;
|
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.Spatial;
|
|
||||||
import com.jme3.scene.shape.Box;
|
|
||||||
import org.wyrez.shootingstars.data.AudioDataManager;
|
import org.wyrez.shootingstars.data.AudioDataManager;
|
||||||
import org.wyrez.shootingstars.controls.PlayerCamControl;
|
|
||||||
import org.wyrez.shootingstars.controls.PlayerMouseControl;
|
|
||||||
import org.wyrez.shootingstars.controls.PlayerMoveControl;
|
|
||||||
import org.wyrez.shootingstars.controls.PlayerShootControl;
|
|
||||||
import org.wyrez.shootingstars.controls.WeaponProjectileControl;
|
|
||||||
import org.wyrez.shootingstars.factories.Materials;
|
|
||||||
import org.wyrez.shootingstars.game.Cinema;
|
import org.wyrez.shootingstars.game.Cinema;
|
||||||
import org.wyrez.shootingstars.game.GameSettings;
|
import org.wyrez.shootingstars.game.GameSettings;
|
||||||
import org.wyrez.shootingstars.game.Ground;
|
import org.wyrez.shootingstars.game.Ground;
|
||||||
import org.wyrez.shootingstars.game.Player;
|
import org.wyrez.shootingstars.game.Player;
|
||||||
|
import org.wyrez.shootingstars.game.StarManager;
|
||||||
import org.wyrez.shootingstars.gui.GameGUI;
|
import org.wyrez.shootingstars.gui.GameGUI;
|
||||||
import org.wyrez.shootingstars.gui.listener.GameListener;
|
import org.wyrez.shootingstars.gui.listener.GameListener;
|
||||||
import org.wyrez.shootingstars.helper.ScreenHelper;
|
import org.wyrez.shootingstars.helper.ScreenHelper;
|
||||||
@ -56,6 +47,10 @@ import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
|
|||||||
*/
|
*/
|
||||||
public class GameState extends AbstractAppState implements GameListener, ActionListener {
|
public class GameState extends AbstractAppState implements GameListener, ActionListener {
|
||||||
|
|
||||||
|
public static final float FIELD_RADIUS = 1000f;
|
||||||
|
public static final float FIELD_HEIGHT = 550f;
|
||||||
|
public static final float FIELD_LOWER_POS = 200f;
|
||||||
|
/**/
|
||||||
private StateManager stateManager;
|
private StateManager stateManager;
|
||||||
private AssetManager assetManager;
|
private AssetManager assetManager;
|
||||||
private InputManager inputManager;
|
private InputManager inputManager;
|
||||||
@ -63,6 +58,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
|||||||
private Camera camera;
|
private Camera camera;
|
||||||
private GameSettings settings;
|
private GameSettings settings;
|
||||||
private AudioDataManager audioDataManager;
|
private AudioDataManager audioDataManager;
|
||||||
|
private StarManager starManager;
|
||||||
private final MediaPlayerFactory mediaPlayerFactory;
|
private final MediaPlayerFactory mediaPlayerFactory;
|
||||||
private DirectMediaPlayer mediaPlayer;
|
private DirectMediaPlayer mediaPlayer;
|
||||||
private Node rootNode;
|
private Node rootNode;
|
||||||
@ -77,7 +73,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
|||||||
InputManager inputManager, Camera camera, AudioDataManager audioDataManager, GameSettings settings, ScreenHelper screenHelper) {
|
InputManager inputManager, Camera camera, AudioDataManager audioDataManager, GameSettings settings, ScreenHelper screenHelper) {
|
||||||
|
|
||||||
this.rootNode = rootNode;
|
this.rootNode = rootNode;
|
||||||
this.gui = new GameGUI(screen, this, assetManager,screenHelper);
|
this.gui = new GameGUI(screen, this, assetManager, screenHelper);
|
||||||
this.stateManager = stateManager;
|
this.stateManager = stateManager;
|
||||||
inputManager.addListener(this, new String[]{"ESC"});
|
inputManager.addListener(this, new String[]{"ESC"});
|
||||||
|
|
||||||
@ -86,6 +82,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
|||||||
this.audioDataManager = audioDataManager;
|
this.audioDataManager = audioDataManager;
|
||||||
this.assetManager = assetManager;
|
this.assetManager = assetManager;
|
||||||
this.viewPort = viewPort;
|
this.viewPort = viewPort;
|
||||||
|
this.starManager = new StarManager(audioDataManager, player);
|
||||||
|
|
||||||
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
|
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
|
||||||
|
|
||||||
@ -93,7 +90,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadGround() {
|
public void loadGround() {
|
||||||
ground = new Ground(audioDataManager);
|
ground = new Ground(audioDataManager, FIELD_RADIUS);
|
||||||
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
|
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
|
||||||
fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
|
fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
|
||||||
viewPort.addProcessor(fpp);
|
viewPort.addProcessor(fpp);
|
||||||
@ -107,14 +104,14 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadCinema() {
|
public void loadCinema() {
|
||||||
cinema = new Cinema(settings);
|
cinema = new Cinema(settings, FIELD_RADIUS);
|
||||||
cinema.move(0f, 160f, 0f);
|
cinema.move(0f, 160f, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadPlayer() {
|
public void loadPlayer() {
|
||||||
player = new Player(rootNode, stateManager, assetManager, viewPort, gui,
|
player = new Player(rootNode, stateManager, assetManager, viewPort, gui,
|
||||||
inputManager, camera, audioDataManager);
|
inputManager, camera, audioDataManager);
|
||||||
|
|
||||||
gui.setPlayer(player);
|
gui.setPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +132,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
|||||||
rootNode.attachChild(cinema);
|
rootNode.attachChild(cinema);
|
||||||
rootNode.attachChild(ground);
|
rootNode.attachChild(ground);
|
||||||
rootNode.attachChild(player);
|
rootNode.attachChild(player);
|
||||||
|
rootNode.attachChild(starManager);
|
||||||
gui.setWait();
|
gui.setWait();
|
||||||
gui.attach();
|
gui.attach();
|
||||||
}
|
}
|
||||||
@ -142,6 +140,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
|||||||
@Override
|
@Override
|
||||||
public void stateDetached(AppStateManager stateManager) {
|
public void stateDetached(AppStateManager stateManager) {
|
||||||
gui.detach();
|
gui.detach();
|
||||||
|
rootNode.detachChild(starManager);
|
||||||
rootNode.detachChild(player);
|
rootNode.detachChild(player);
|
||||||
rootNode.detachChild(ground);
|
rootNode.detachChild(ground);
|
||||||
rootNode.detachChild(cinema);
|
rootNode.detachChild(cinema);
|
||||||
@ -159,6 +158,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
|||||||
public void update(float tpf) {
|
public void update(float tpf) {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
audioDataManager.update(tpf);
|
audioDataManager.update(tpf);
|
||||||
|
starManager.update(tpf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +168,11 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
|
|||||||
setRunning(false);
|
setRunning(false);
|
||||||
mediaPlayer.release();
|
mediaPlayer.release();
|
||||||
mediaPlayerFactory.release();
|
mediaPlayerFactory.release();
|
||||||
|
mediaPlayer = null;
|
||||||
|
player = null;
|
||||||
|
ground = null;
|
||||||
|
cinema = null;
|
||||||
|
starManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectMediaPlayer getMediaPlayer() {
|
public DirectMediaPlayer getMediaPlayer() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user