added star-particles, disabled logger, fixed prohectile spawn

This commit is contained in:
Raybz@Raybz 2013-06-27 11:29:14 +02:00
parent dffae3aa09
commit 416ebca4b2
10 changed files with 146 additions and 38 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -28,10 +28,13 @@ import com.jme3.input.controls.KeyTrigger;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.wyrez.persij.PersiJContainer; import org.wyrez.persij.PersiJContainer;
import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.data.AudioDataManager;
import org.wyrez.shootingstars.data.YTDownloader; import org.wyrez.shootingstars.data.YTDownloader;
import org.wyrez.shootingstars.factories.Materials; import org.wyrez.shootingstars.factories.Materials;
import org.wyrez.shootingstars.factories.Particles;
import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.game.GameSettings;
import org.wyrez.shootingstars.gui.manager.HighscoreManager; import org.wyrez.shootingstars.gui.manager.HighscoreManager;
import org.wyrez.shootingstars.gui.manager.ScoreComparator; import org.wyrez.shootingstars.gui.manager.ScoreComparator;
@ -55,16 +58,20 @@ public class ShootingStars extends SimpleApplication {
public ShootingStars(OptionSettings optionSettings) { public ShootingStars(OptionSettings optionSettings) {
super(new StatsAppState(), new DebugKeysAppState()); super(new StatsAppState(), new DebugKeysAppState());
this.optionSettings = optionSettings; this.optionSettings = optionSettings;
Logger.getLogger("").setLevel(Level.SEVERE);
System.setProperty("jna.library.path", "lib/vlc");
} }
@Override @Override
public void simpleInitApp() { public void simpleInitApp() {
System.setProperty("jna.library.path", "lib/vlc");
registerTypes(); registerTypes();
initGUI(); initGUI();
initKeys(); initKeys();
Materials.initialize(assetManager); Materials.initialize(assetManager);
Particles.initialize(assetManager);
cam.setFrustumFar(2500f); cam.setFrustumFar(2500f);
sManager = container.resolve(StateManager.class); sManager = container.resolve(StateManager.class);
sManager.setState(State.START); sManager.setState(State.START);

View File

@ -16,9 +16,11 @@
*/ */
package org.wyrez.shootingstars.controls; package org.wyrez.shootingstars.controls;
import com.jme3.scene.Node; import com.jme3.effect.ParticleEmitter;
import com.jme3.math.ColorRGBA;
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.factories.Particles;
import org.wyrez.shootingstars.helper.UserDataKeys; import org.wyrez.shootingstars.helper.UserDataKeys;
/** /**
@ -27,10 +29,13 @@ import org.wyrez.shootingstars.helper.UserDataKeys;
*/ */
public class StarDeathControl extends BaseControl { public class StarDeathControl extends BaseControl {
private Node starNode; private static final float FX_TIME = 3f;
/**/
private ParticleEmitter effect;
private boolean isDead;
private float deathTimer = FX_TIME;
public StarDeathControl(Node starNode) { public StarDeathControl() {
this.starNode = starNode;
} }
@Override @Override
@ -41,14 +46,41 @@ public class StarDeathControl extends BaseControl {
@Override @Override
protected void controlUpdate(float tpf) { protected void controlUpdate(float tpf) {
if (spatial.getUserData(UserDataKeys.HITTED)) { if (isDead) {
//TODO DIE! if (deathTimer <= 0f) {
starNode.detachChild(spatial); spatial.removeFromParent();
effect.killAllParticles();
effect.removeFromParent();
} else {
deathTimer -= tpf;
}
} else {
if (spatial.getUserData(UserDataKeys.HITTED)) {
effect = Particles.SPARKLE.create();
StarPointControl points = spatial.getControl(StarPointControl.class);
if (points != null) {
effect.setStartColor(points.getColor());
effect.setEndColor(new ColorRGBA(points.getColor().r,
points.getColor().g, points.getColor().b, 0f));
}
effect.setStartSize((Float) spatial.getUserData(UserDataKeys.SIZE));
effect.setEndSize(0f);
effect.setHighLife(FX_TIME);
effect.setLowLife(0f);
effect.setLocalTranslation(spatial.getLocalTranslation());
effect.setParticlesPerSec(0f);
spatial.getParent().attachChild(effect);
spatial.setCullHint(Spatial.CullHint.Always);
effect.emitAllParticles();
isDead = true;
}
} }
} }
public Control cloneForSpatial(Spatial spatial) { public Control cloneForSpatial(Spatial spatial) {
StarDeathControl control = new StarDeathControl(starNode); StarDeathControl control = new StarDeathControl();
spatial.addControl(control); spatial.addControl(control);
return control; return control;
} }

View File

@ -38,12 +38,13 @@ public class StarPointControl extends BaseControl {
private ColorRGBA color; private ColorRGBA color;
private Material material; private Material material;
private float timer; private float timer;
private boolean isHitted = false;
public StarPointControl(Spatial player, float value) { public StarPointControl(Spatial player, float value) {
this.player = player; this.player = player;
this.points = (int) Math.round(MAX_POINTS * value); this.points = (int) Math.round(MAX_POINTS * value);
this.timer = HIT_TIMER; this.timer = HIT_TIMER;
this.color = ColorHelper.calcColor(value / MAX_POINTS); this.color = ColorHelper.calcColor(points / MAX_POINTS);
} }
@Override @Override
@ -55,14 +56,16 @@ public class StarPointControl extends BaseControl {
@Override @Override
protected void controlUpdate(float tpf) { protected void controlUpdate(float tpf) {
if (spatial.getUserData(UserDataKeys.HITTED)) { if ((Boolean)spatial.getUserData(UserDataKeys.HITTED) && !isHitted) {
player.setUserData(UserDataKeys.POINTS, (Integer) (player.getUserData(UserDataKeys.POINTS)) player.setUserData(UserDataKeys.POINTS, (Integer) (player.getUserData(UserDataKeys.POINTS))
+ (int) Math.round(points)); + (int) Math.round(points));
isHitted = true;
} else if (timer <= 0f) { } else if (timer <= 0f) {
if (points > 1f) { if (points > 1f) {
points -= 2f * tpf; points -= 2f * tpf;
color = ColorHelper.calcColor(points / MAX_POINTS); color = ColorHelper.calcColor(points / MAX_POINTS);
} else if (points < 1f) { } else if (points < 1f) {
spatial.setUserData(UserDataKeys.HITTED, true); //TODO test
points = 1f; points = 1f;
color = ColorHelper.calcColor(points / MAX_POINTS); color = ColorHelper.calcColor(points / MAX_POINTS);
} }
@ -72,6 +75,10 @@ public class StarPointControl extends BaseControl {
} }
} }
public ColorRGBA getColor() {
return color;
}
public Control cloneForSpatial(Spatial spatial) { public Control cloneForSpatial(Spatial spatial) {
StarPointControl control = new StarPointControl(player, (float) points); StarPointControl control = new StarPointControl(player, (float) points);
spatial.addControl(control); spatial.addControl(control);

View File

@ -16,8 +16,6 @@
*/ */
package org.wyrez.shootingstars.controls; package org.wyrez.shootingstars.controls;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control; import com.jme3.scene.control.Control;
@ -42,6 +40,7 @@ public class WeaponProjectileControl extends BaseControl {
@Override @Override
public void setSpatial(Spatial spatial) { public void setSpatial(Spatial spatial) {
super.setSpatial(spatial); super.setSpatial(spatial);
spatial.setCullHint(Spatial.CullHint.Always);
} }
@Override @Override
@ -51,7 +50,6 @@ public class WeaponProjectileControl extends BaseControl {
spatial.setCullHint(Spatial.CullHint.Never); spatial.setCullHint(Spatial.CullHint.Never);
isVisible = true; isVisible = true;
} }
// shoot();
} else { } else {
if (isVisible) { if (isVisible) {
spatial.setCullHint(Spatial.CullHint.Always); spatial.setCullHint(Spatial.CullHint.Always);
@ -65,22 +63,4 @@ public class WeaponProjectileControl extends BaseControl {
spatial.addControl(control); spatial.addControl(control);
return control; return control;
} }
/*
* Fires a projectile
*/
// private void shoot() {
// spatial.setLocalTranslation(player.getLocalTranslation().add(0, 0, -4));
//
// Vector3f vectorDifference = new Vector3f(player.getLocalTranslation().subtract(player.getWorldTranslation()));
// spatial.setLocalTranslation(vectorDifference.addLocal(player.getLocalTranslation()));
//
// Quaternion worldDiff = new Quaternion(player.getLocalRotation().subtract(player.getWorldRotation()));
// spatial.setLocalRotation(worldDiff.addLocal(player.getLocalRotation()));
//
// spatial.move(player.getLocalRotation().getRotationColumn(2).mult(3.5f));
// spatial.move(player.getLocalRotation().getRotationColumn(1).mult(0.1f));
// spatial.move(player.getLocalRotation().getRotationColumn(0).mult(0.1f));
//// spatial.rotate(0f, FastMath.PI, 0);
// }
} }

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.factories;
import com.jme3.asset.AssetManager;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
/**
*
* @author Darth Affe
*/
public enum Particles {
SPARKLE(500, "Textures/star.png", ColorRGBA.White, new Vector3f(0f, 100f, 0f), 1f);
private static AssetManager assetManager;
private static int particleDensity;
/**/
private int particleCount;
private String texture;
private ColorRGBA color;
private Vector3f initialVelocity;
private float velocityVariation;
Particles(int particleCount, String texture, ColorRGBA color,
Vector3f initialVelocity, float velocityVariation) {
this.particleCount = particleCount;
this.texture = texture;
this.color = color;
this.initialVelocity = initialVelocity;
this.velocityVariation = velocityVariation;
}
public ParticleEmitter create() {
int particles = particleCount;
for (int i = 0; i < 3 - particleDensity; i++) {
particles *= 0.5;
}
ParticleEmitter particleEmitter = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, particles);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
mat.setTexture("Texture", assetManager.loadTexture(texture));
particleEmitter.setMaterial(mat);
particleEmitter.setRotateSpeed(4);
particleEmitter.getParticleInfluencer().setInitialVelocity(initialVelocity);
particleEmitter.setStartColor(color);
particleEmitter.getParticleInfluencer().setVelocityVariation(velocityVariation);
return particleEmitter;
}
public static void initialize(AssetManager assetManager) {
Particles.assetManager = assetManager;
}
public static void setParticleDensity(int particleDensity) {
Particles.particleDensity = particleDensity;
}
}

View File

@ -65,6 +65,7 @@ public class Player extends Node {
AudioDataManager audioDataManager, GameGUI gui) { AudioDataManager audioDataManager, GameGUI gui) {
this.setUserData(UserDataKeys.RUNNING, false); this.setUserData(UserDataKeys.RUNNING, false);
this.setUserData(UserDataKeys.SHOOTING, false); this.setUserData(UserDataKeys.SHOOTING, false);
this.setUserData(UserDataKeys.POINTS, 0);
this.addControl(new PlayerMouseControl(inputManager, camera)); this.addControl(new PlayerMouseControl(inputManager, camera));
this.addControl(new PlayerMoveControl(audioDataManager)); this.addControl(new PlayerMoveControl(audioDataManager));
this.addControl(new PlayerShootControl(inputManager, gui)); this.addControl(new PlayerShootControl(inputManager, gui));

View File

@ -23,7 +23,6 @@ import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import java.util.Arrays;
import java.util.Random; import java.util.Random;
import org.wyrez.shootingstars.controls.StarDeathControl; import org.wyrez.shootingstars.controls.StarDeathControl;
import org.wyrez.shootingstars.controls.StarFaceControl; import org.wyrez.shootingstars.controls.StarFaceControl;
@ -31,6 +30,7 @@ import org.wyrez.shootingstars.controls.StarPointControl;
import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.data.AudioDataManager;
import org.wyrez.shootingstars.factories.Materials; import org.wyrez.shootingstars.factories.Materials;
import org.wyrez.shootingstars.helper.MathHelper; import org.wyrez.shootingstars.helper.MathHelper;
import org.wyrez.shootingstars.helper.UserDataKeys;
import org.wyrez.shootingstars.mesh.Star; import org.wyrez.shootingstars.mesh.Star;
import org.wyrez.shootingstars.states.GameState; import org.wyrez.shootingstars.states.GameState;
@ -86,11 +86,12 @@ public class StarManager extends Node {
Material mat = Materials.STAR.create(); Material mat = Materials.STAR.create();
mat.setColor("Color", ColorRGBA.Yellow); mat.setColor("Color", ColorRGBA.Yellow);
star.setMaterial(mat); star.setMaterial(mat);
star.setUserData(UserDataKeys.SIZE, size);
star.addControl(new StarFaceControl(player)); star.addControl(new StarFaceControl(player));
star.addControl(new StarDeathControl(this)); star.addControl(new StarDeathControl());
star.addControl(new StarPointControl(player, value)); star.addControl(new StarPointControl(player, value));
this.attachChild(star); this.attachChild(star);
} }

View File

@ -26,4 +26,5 @@ public class UserDataKeys {
public static final String SHOOTING = "isShooting"; public static final String SHOOTING = "isShooting";
public static final String RUNNING = "isRunning"; public static final String RUNNING = "isRunning";
public static final String POINTS = "points"; public static final String POINTS = "points";
public static final String SIZE = "size";
} }

View File

@ -28,6 +28,7 @@ import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.data.AudioDataManager;
import org.wyrez.shootingstars.factories.Particles;
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;
@ -37,6 +38,7 @@ 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;
import org.wyrez.shootingstars.helper.UserDataKeys; import org.wyrez.shootingstars.helper.UserDataKeys;
import org.wyrez.shootingstars.states.util.OptionSettings;
import tonegod.gui.core.Screen; import tonegod.gui.core.Screen;
import uk.co.caprica.vlcj.player.MediaPlayerFactory; import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer; import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
@ -69,8 +71,9 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
private boolean isRunning = false; private boolean isRunning = false;
public GameState(Node rootNode, Screen screen, StateManager stateManager, public GameState(Node rootNode, Screen screen, StateManager stateManager,
AssetManager assetManager, ViewPort viewPort, AssetManager assetManager, ViewPort viewPort, OptionSettings options,
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);
@ -86,6 +89,8 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet"); mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
this.settings = settings; this.settings = settings;
Particles.setParticleDensity(options.getParticleDensity());
} }
public void loadGround() { public void loadGround() {