From 416ebca4b2bfbfa7a606628d54fabeb9a3ad719e Mon Sep 17 00:00:00 2001 From: "Raybz@Raybz" Date: Thu, 27 Jun 2013 11:29:14 +0200 Subject: [PATCH] added star-particles, disabled logger, fixed prohectile spawn --- ShootingStars/assets/Textures/star.png | Bin 0 -> 2863 bytes .../wyrez/shootingstars/ShootingStars.java | 9 ++- .../controls/StarDeathControl.java | 48 ++++++++++-- .../controls/StarPointControl.java | 11 ++- .../controls/WeaponProjectileControl.java | 22 +----- .../shootingstars/factories/Particles.java | 74 ++++++++++++++++++ .../org/wyrez/shootingstars/game/Player.java | 1 + .../wyrez/shootingstars/game/StarManager.java | 9 ++- .../shootingstars/helper/UserDataKeys.java | 1 + .../wyrez/shootingstars/states/GameState.java | 9 ++- 10 files changed, 146 insertions(+), 38 deletions(-) create mode 100644 ShootingStars/assets/Textures/star.png create mode 100644 ShootingStars/src/org/wyrez/shootingstars/factories/Particles.java diff --git a/ShootingStars/assets/Textures/star.png b/ShootingStars/assets/Textures/star.png new file mode 100644 index 0000000000000000000000000000000000000000..c84a2c8bbb588e9568c0b388615673e6236f97e8 GIT binary patch literal 2863 zcmY*b4Oo)b7k?3a1$i-u`2m=Mjo4QSn5~)?AZcb=ZtJmJDk`%UmLIL8GDAT^T?5yL zf6XDtC*GAK-B0{*IYAG6P?(dhaz7kH6M9J^lGD(@GA01t~0L z-Qmdxx*zA4)ws|^E%#uEeYFL@y)tOW0%NHT|PTym6~GAO7k(DTBCC(a+5_m zCm_YT@yR2b>T?%WWs_*}Q%!Rm&_wr4hRG-nj|Pw#4PW&MZIej#4xG9Yed&%w`)(fLyF|yL$6+ z{85|DXUq#VNM&)6*}8Ee7kNv&1V}fnzXCzSTFw#6=cgE{+bq(^ub&o>DX`1>Pp}kt z)}7gnlTY`QAawN>B0GtbiR|B55PCxwQEWJ|BJ)yHG~aBH)l>Oqc7<+HH>NqC@Ksj9 z^%|@;6r^!M=f*R$4LX>}Wt&q+NL*xL$M(&)3f9QQLphJncDA1z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?$7Gs#QBRj4 zZtynKJionQxBT{{vsIwwo!Z;+KIoaj9ezLxtuDdZpd$K@*bxpQklc*!t*i-?l?#5D zDxRE9E7`H@yh>&1@)3(#EM9(FZ(hVKIWwWUB0C44;g_06-<@Oi1dW$q^#X4Rkw6R+ zWQvx-gV&knO}Rxwu=|~P5#os_2lOa`lAr6J1G3B2*IygF$~1p|=Oe5fH+Xo%KbzUG z!*746y=nc3cF2@YgSlmo1EFm#W-G-9$^T7QB(S~!Y@I~~?M@D8L&e~mo<_mZ2I{49` z)x%j4Tb;GUo5eNp8g$CMI(TDFTU932AJVxGIRd79M+uc-QaVX!3{$X^WTRPUG)A+! zZ98#2OCP1*YijcPDFpES^_F(80-;fcP(XSNIX>@*E24j&(foYtMqP^CPaXmZ(_Dv0 z&%mmSScf`&vz9EsYWot`Gr8|^o=4l7!@JHucpDxk3X}xw_-x(LfoGx=6cqZ8L+z9A Vk7w*nF@mct6uKfpSS1kU{2y(or``Yn literal 0 HcmV?d00001 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() {