diff --git a/ShootingStars/assets/Textures/star.png b/ShootingStars/assets/Textures/star.png new file mode 100644 index 0000000..c84a2c8 Binary files /dev/null and b/ShootingStars/assets/Textures/star.png differ diff --git a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java index c122676..0bb1a6f 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java +++ b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java @@ -28,10 +28,13 @@ import com.jme3.input.controls.KeyTrigger; import com.jme3.renderer.Camera; import com.jme3.renderer.ViewPort; import com.jme3.scene.Node; +import java.util.logging.Level; +import java.util.logging.Logger; import org.wyrez.persij.PersiJContainer; import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.data.YTDownloader; import org.wyrez.shootingstars.factories.Materials; +import org.wyrez.shootingstars.factories.Particles; import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.gui.manager.HighscoreManager; import org.wyrez.shootingstars.gui.manager.ScoreComparator; @@ -55,16 +58,20 @@ public class ShootingStars extends SimpleApplication { public ShootingStars(OptionSettings optionSettings) { super(new StatsAppState(), new DebugKeysAppState()); this.optionSettings = optionSettings; + + Logger.getLogger("").setLevel(Level.SEVERE); + System.setProperty("jna.library.path", "lib/vlc"); } @Override public void simpleInitApp() { - System.setProperty("jna.library.path", "lib/vlc"); registerTypes(); initGUI(); initKeys(); Materials.initialize(assetManager); + Particles.initialize(assetManager); + cam.setFrustumFar(2500f); sManager = container.resolve(StateManager.class); sManager.setState(State.START); diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/StarDeathControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/StarDeathControl.java index b19b179..823e595 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/StarDeathControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/StarDeathControl.java @@ -16,9 +16,11 @@ */ 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.control.Control; +import org.wyrez.shootingstars.factories.Particles; import org.wyrez.shootingstars.helper.UserDataKeys; /** @@ -27,10 +29,13 @@ import org.wyrez.shootingstars.helper.UserDataKeys; */ 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) { - this.starNode = starNode; + public StarDeathControl() { } @Override @@ -41,14 +46,41 @@ public class StarDeathControl extends BaseControl { @Override protected void controlUpdate(float tpf) { - if (spatial.getUserData(UserDataKeys.HITTED)) { - //TODO DIE! - starNode.detachChild(spatial); + if (isDead) { + if (deathTimer <= 0f) { + 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) { - StarDeathControl control = new StarDeathControl(starNode); + StarDeathControl control = new StarDeathControl(); spatial.addControl(control); return control; } diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/StarPointControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/StarPointControl.java index 2d23c99..8c7d724 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/StarPointControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/StarPointControl.java @@ -38,12 +38,13 @@ public class StarPointControl extends BaseControl { private ColorRGBA color; private Material material; private float timer; + private boolean isHitted = false; public StarPointControl(Spatial player, float value) { this.player = player; this.points = (int) Math.round(MAX_POINTS * value); this.timer = HIT_TIMER; - this.color = ColorHelper.calcColor(value / MAX_POINTS); + this.color = ColorHelper.calcColor(points / MAX_POINTS); } @Override @@ -55,14 +56,16 @@ public class StarPointControl extends BaseControl { @Override 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)) + (int) Math.round(points)); + isHitted = true; } else if (timer <= 0f) { if (points > 1f) { points -= 2f * tpf; color = ColorHelper.calcColor(points / MAX_POINTS); } else if (points < 1f) { + spatial.setUserData(UserDataKeys.HITTED, true); //TODO test points = 1f; 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) { StarPointControl control = new StarPointControl(player, (float) points); spatial.addControl(control); diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/WeaponProjectileControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/WeaponProjectileControl.java index 013737e..67c2067 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/WeaponProjectileControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/WeaponProjectileControl.java @@ -16,8 +16,6 @@ */ package org.wyrez.shootingstars.controls; -import com.jme3.math.Quaternion; -import com.jme3.math.Vector3f; import com.jme3.scene.Node; import com.jme3.scene.Spatial; import com.jme3.scene.control.Control; @@ -42,6 +40,7 @@ public class WeaponProjectileControl extends BaseControl { @Override public void setSpatial(Spatial spatial) { super.setSpatial(spatial); + spatial.setCullHint(Spatial.CullHint.Always); } @Override @@ -51,7 +50,6 @@ public class WeaponProjectileControl extends BaseControl { spatial.setCullHint(Spatial.CullHint.Never); isVisible = true; } -// shoot(); } else { if (isVisible) { spatial.setCullHint(Spatial.CullHint.Always); @@ -65,22 +63,4 @@ public class WeaponProjectileControl extends BaseControl { spatial.addControl(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); -// } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/factories/Particles.java b/ShootingStars/src/org/wyrez/shootingstars/factories/Particles.java new file mode 100644 index 0000000..3dee966 --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/factories/Particles.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2013 Darth Affe 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 . + */ +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; + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/game/Player.java b/ShootingStars/src/org/wyrez/shootingstars/game/Player.java index 1fd6edc..a29e8f2 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/game/Player.java +++ b/ShootingStars/src/org/wyrez/shootingstars/game/Player.java @@ -65,6 +65,7 @@ public class Player extends Node { AudioDataManager audioDataManager, GameGUI gui) { this.setUserData(UserDataKeys.RUNNING, false); this.setUserData(UserDataKeys.SHOOTING, false); + this.setUserData(UserDataKeys.POINTS, 0); this.addControl(new PlayerMouseControl(inputManager, camera)); this.addControl(new PlayerMoveControl(audioDataManager)); this.addControl(new PlayerShootControl(inputManager, gui)); diff --git a/ShootingStars/src/org/wyrez/shootingstars/game/StarManager.java b/ShootingStars/src/org/wyrez/shootingstars/game/StarManager.java index 356beff..802084f 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/game/StarManager.java +++ b/ShootingStars/src/org/wyrez/shootingstars/game/StarManager.java @@ -23,7 +23,6 @@ import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.Spatial; -import java.util.Arrays; import java.util.Random; import org.wyrez.shootingstars.controls.StarDeathControl; 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.factories.Materials; import org.wyrez.shootingstars.helper.MathHelper; +import org.wyrez.shootingstars.helper.UserDataKeys; import org.wyrez.shootingstars.mesh.Star; import org.wyrez.shootingstars.states.GameState; @@ -86,11 +86,12 @@ public class StarManager extends Node { Material mat = Materials.STAR.create(); mat.setColor("Color", ColorRGBA.Yellow); star.setMaterial(mat); - + star.setUserData(UserDataKeys.SIZE, size); + star.addControl(new StarFaceControl(player)); - star.addControl(new StarDeathControl(this)); + star.addControl(new StarDeathControl()); star.addControl(new StarPointControl(player, value)); - + this.attachChild(star); } diff --git a/ShootingStars/src/org/wyrez/shootingstars/helper/UserDataKeys.java b/ShootingStars/src/org/wyrez/shootingstars/helper/UserDataKeys.java index f9942c5..561f92f 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/helper/UserDataKeys.java +++ b/ShootingStars/src/org/wyrez/shootingstars/helper/UserDataKeys.java @@ -26,4 +26,5 @@ public class UserDataKeys { public static final String SHOOTING = "isShooting"; public static final String RUNNING = "isRunning"; public static final String POINTS = "points"; + public static final String SIZE = "size"; } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java index 9c5ece0..b4206b9 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java @@ -28,6 +28,7 @@ import com.jme3.renderer.RenderManager; import com.jme3.renderer.ViewPort; import com.jme3.scene.Node; import org.wyrez.shootingstars.data.AudioDataManager; +import org.wyrez.shootingstars.factories.Particles; import org.wyrez.shootingstars.game.Cinema; import org.wyrez.shootingstars.game.GameSettings; 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.helper.ScreenHelper; import org.wyrez.shootingstars.helper.UserDataKeys; +import org.wyrez.shootingstars.states.util.OptionSettings; import tonegod.gui.core.Screen; import uk.co.caprica.vlcj.player.MediaPlayerFactory; import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer; @@ -69,8 +71,9 @@ public class GameState extends AbstractAppState implements GameListener, ActionL private boolean isRunning = false; public GameState(Node rootNode, Screen screen, StateManager stateManager, - AssetManager assetManager, ViewPort viewPort, - InputManager inputManager, Camera camera, AudioDataManager audioDataManager, GameSettings settings, ScreenHelper screenHelper) { + AssetManager assetManager, ViewPort viewPort, OptionSettings options, + InputManager inputManager, Camera camera, AudioDataManager audioDataManager, + GameSettings settings, ScreenHelper screenHelper) { this.rootNode = rootNode; 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"); this.settings = settings; + + Particles.setParticleDensity(options.getParticleDensity()); } public void loadGround() {