From 44836f69c62bc2b9c7b2d6cd7c7a98dbbdb71c65 Mon Sep 17 00:00:00 2001 From: "Raybz@Raybz" Date: Fri, 7 Jun 2013 14:53:57 +0200 Subject: [PATCH] added the real Audio-Replay (not working with videos), improved controls --- ShootingStars/lib/AudioProcessing-1.0.jar | Bin 32448 -> 32457 bytes ShootingStars/nbproject/project.properties | 3 +- .../wyrez/shootingstars/ShootingStars.java | 11 +- .../audiodata/AudioDataManager.java | 106 +++++++++++++++++ .../shootingstars/audiodata/AudioPlayer.java | 65 ++++++++++ .../controls/GroundGlowControl.java | 73 ++++++++++++ .../controls/PlayerCamControl.java | 49 ++++++++ .../controls/PlayerMouseControl.java | 21 ++-- .../controls/PlayerMoveControl.java | 49 +++++++- .../controls/PlayerShootControl.java | 10 +- .../shootingstars/helper/MathHelper.java | 8 +- .../shootingstars/helper/UserDataKeys.java | 1 + .../wyrez/shootingstars/states/GameState.java | 111 +++++++++++++++--- .../shootingstars/states/LoadingState.java | 45 ++++++- .../states/util/LoadingProgress.java | 13 +- 15 files changed, 517 insertions(+), 48 deletions(-) create mode 100644 ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioDataManager.java create mode 100644 ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioPlayer.java create mode 100644 ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java create mode 100644 ShootingStars/src/org/wyrez/shootingstars/controls/PlayerCamControl.java diff --git a/ShootingStars/lib/AudioProcessing-1.0.jar b/ShootingStars/lib/AudioProcessing-1.0.jar index 098b24ee7043435f4ee425da218b503fc8932b61..9f32196989feac0dca72b74d1ef7a69187277e86 100644 GIT binary patch delta 4852 zcmZXYcUV))w!oT7a5uhWvy;7P|t zO^hcmZ!ig-`GS3yva1LU$@K=u0rjS=VBR$<0)lU-CMf^-Fv=CgukSV)N)zzW8e6vmvGJ{Ff8AK&A@AE9-#~Ml#@7=uKUWno4{4rW z3~KiC_HJ%ptkeBTQ@HSZZsqGB#lxVs=$xVq8vC9esSe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uo-J`$BUs3m!9Vw%me2iuS_sX z7-w!1reA)%i<`CW^f41n3>t5L8QQUS?(uk}E~lIYY_Fr0T3-1tY6n8a3X`c98(O8Fhj1Utt&aDWJ@9AqnDyD^s*keV z1y>)28Tm&pk|6$pY>$#u_2awe6x+RK%~gug=LXcSl^lo|_Mef-hCZiL!)`Y`L3~3z z3%zA9T;6efUUE}Qy_ON%YKwjG23v@KlGBUOW%hZET67<5d5&tGaXy1)I<}(GMAjnQ zcB4wsU`MmefGDb-k~2#MjJ;mEn0EnkhP}B5bH=;)7j# z+&H~V*CB@E)Ba9ApfRS7B_-Hy5p>tHzb~?e%-Xp2=4-B@heNU2Hiyk>q@T6$c_!bA zfhcr7Jxrj-@JkwKGS%3mtez2!~Kr!NrnY=48N z+#ZhR*Du~9EwXeEA5;9h;-&$St6Laj@i;g(BvLG~kx2@-kpM>Xt+Tq^m0U!#mYCYe^o zUDF=wmj)>zHNX%Sihs8k+LTZG45uG}+wJ;EuK~F4cKc)-K)9O-8EW06$eo2PH+eEM z^Sc0Ox(kwrUhXR7i3ayOWCrojCd0#jLYjvmnH_sPBm>Ixlzs9vA}2t-wEm~pVC!{{ z99Hbb1qo9EN^bK4YhFy3$R}ZdIOZP!gFsXiAkfYKt`w9J@cQ;ipa_8UW+11UcymDt zl}{7_Aj6x9tl&=+uKOp-1%Tu&OjdY(xFD+Ne<^f;rO!VtdI<{#ebgY(0|pT2`v0?- zFaf}(f&JePeD43p3k3TQISV>IRtIkT@sO{InI9L#!x{MI%n2m=F 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.audiodata; + +import org.wyrez.audio.AudioProcessor; +import org.wyrez.audio.decoder.DecoderFactory; +import org.wyrez.audio.util.Band; +import org.wyrez.audio.util.SampleBuffer; +import org.wyrez.audio.util.SampleHelper; + +/** + * + * @author Darth Affe + */ +public class AudioDataManager { + + private static final int MIN_PEAK_DIFF = 13; //~198.8bpm + private static final Band LOW_BAND = new Band(1f, 140); + private static final Band MID_BAND = new Band(400f, 1200f); + private static final Band HIGH_BAND = new Band(4000f, 8000f); + /**/ + private AudioProcessor audioProcessorLowBand; + private AudioProcessor audioProcessorMidBand; + private AudioProcessor audioProcessorHighBand; + private AudioPlayer player; + private float bpm; + private float currentTime; + private float lastTimeSync; + + public void AudioDataManager() { + } + + public boolean initialize(String file, AudioPlayer player) { + try { + this.player = player; + SampleBuffer samples = SampleHelper.createSampleBuffer(DecoderFactory.create(file)); + this.audioProcessorLowBand = new AudioProcessor(samples, LOW_BAND); + this.audioProcessorMidBand = new AudioProcessor(samples, MID_BAND); + this.audioProcessorHighBand = new AudioProcessor(samples, HIGH_BAND); + return true; + } catch (Exception ex) { + return false; + } + } + + public void update(float tpf) { + if (lastTimeSync != player.getElapsedTime()) { + currentTime = player.getElapsedTime(); + lastTimeSync = currentTime; + } else { + currentTime += tpf; + } + } + + public void analyseLowBand() { + audioProcessorLowBand.calculate(); + audioProcessorLowBand.cutFastPeaks(MIN_PEAK_DIFF); + bpm = audioProcessorLowBand.getBpm(); + while (bpm > 200f) { + bpm /= 2f; + } + } + + public void analyseMidBand() { + audioProcessorMidBand.calculate(); + audioProcessorMidBand.cutFastPeaks(MIN_PEAK_DIFF); + } + + public void analyseHighBand() { + audioProcessorHighBand.calculate(); + } + + public float getBPM() { + return bpm; + } + + public boolean isLowPeak() { + int index = (int) (currentTime * (audioProcessorLowBand.getSamplingRate() / audioProcessorLowBand.getBufferSize())); + if (index > audioProcessorLowBand.getPeaks().length) { + index = audioProcessorLowBand.getPeaks().length - 1; + } + return audioProcessorLowBand.getPeaks()[index] > audioProcessorLowBand.getPeakAverage()*0.5f; + } + + public float getMidData() { + return 0f; //TODO implement + } + + public float getHighData() { + return 0f; //TODO implement + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioPlayer.java b/ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioPlayer.java new file mode 100644 index 0000000..aafe5a0 --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioPlayer.java @@ -0,0 +1,65 @@ +/* + * 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.audiodata; + +import org.wyrez.audio.AudioDevice; +import org.wyrez.audio.decoder.Decoder; + +/** + * + * @author Darth Affe + */ +public abstract class AudioPlayer extends Thread { + + private static final int BUFFER_SIZE = 128; + /**/ + private Decoder decoder; + private AudioDevice device; + private float elapsedTime; + private boolean cleanup = false; + + public AudioPlayer(Decoder decoder) throws Exception { + this.decoder = decoder; + device = new AudioDevice(decoder.getSamplingRate(), decoder.getChannelCount(), + BUFFER_SIZE * decoder.getChannelCount()); + } + + @Override + public void run() { + elapsedTime = 0; + float[] samples = new float[BUFFER_SIZE * decoder.getChannelCount()]; + long startTime = System.nanoTime(); + while (decoder.readSamplesStereo(samples) > 0) { + if (cleanup) { + break; + } + device.writeSamples(samples); + elapsedTime = (System.nanoTime() - startTime) / 1000000000.0f; + } + finished(cleanup); + } + + public float getElapsedTime() { + return elapsedTime; + } + + public void cleanup() { + this.cleanup = true; + } + + public abstract void finished(boolean cleanup); +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java new file mode 100644 index 0000000..92b1ddf --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/GroundGlowControl.java @@ -0,0 +1,73 @@ +/* + * 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.controls; + +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.scene.Geometry; +import com.jme3.scene.Spatial; +import com.jme3.scene.control.Control; +import org.wyrez.shootingstars.audiodata.AudioDataManager; + +/** + * + * @author Darth Affe + */ +public class GroundGlowControl extends BaseControl { + + private static final float GLOW_DURATION = 0.33f; + /**/ + private AudioDataManager audioDataManager; + private Material material; + private float glowTimer = 0; + + public GroundGlowControl(AudioDataManager audioDataManager) { + this.audioDataManager = audioDataManager; + } + + @Override + public void setSpatial(Spatial spatial) { + super.setSpatial(spatial); + this.material = ((Geometry) spatial).getMaterial(); + this.material.setColor("GlowColor", ColorRGBA.Black); + } + + @Override + public void update(float tpf) { + if (audioDataManager.isLowPeak()) { + glowTimer = GLOW_DURATION; + } + + if (glowTimer > 0f) { + float glowFactor = (glowTimer / GLOW_DURATION); + if (glowFactor > 0.5f) { + glowFactor = 1f; + } else { + glowFactor += 0.5f; + } + material.setColor("GlowColor", new ColorRGBA(1f * glowFactor, + 1f * glowFactor, 1f * glowFactor, 1f)); + glowTimer -= tpf; + } + } + + public Control cloneForSpatial(Spatial spatial) { + GroundGlowControl control = new GroundGlowControl(audioDataManager); + control.setSpatial(spatial); + return control; + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerCamControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerCamControl.java new file mode 100644 index 0000000..2a64f5d --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerCamControl.java @@ -0,0 +1,49 @@ +/* + * 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.controls; + +import com.jme3.renderer.Camera; +import com.jme3.scene.Spatial; +import com.jme3.scene.control.Control; +import org.wyrez.shootingstars.helper.UserDataKeys; + +/** + * + * @author Darth Affe + */ +public class PlayerCamControl extends BaseControl { + + private Camera camera; + + public PlayerCamControl(Camera camera) { + this.camera = camera; + } + + @Override + public void update(float tpf) { + if (spatial.getUserData(UserDataKeys.RUNNING)) { + camera.setLocation(spatial.getLocalTranslation()); + camera.setRotation(spatial.getLocalRotation()); + } + } + + public Control cloneForSpatial(Spatial spatial) { + PlayerCamControl control = new PlayerCamControl(camera); + control.setSpatial(spatial); + return control; + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMouseControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMouseControl.java index 0d1e51c..d2fc7e2 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMouseControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMouseControl.java @@ -28,6 +28,7 @@ import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; import com.jme3.scene.Spatial; import com.jme3.scene.control.Control; +import org.wyrez.shootingstars.helper.UserDataKeys; /** * @@ -41,7 +42,7 @@ public class PlayerMouseControl extends BaseControl implements AnalogListener { private static final String MAPPING_PLAYER_DOWN = "PLAYER_Down"; private static final float PITCH_LIMIT = 1.4f; /**/ - private float speed; + private float speed = 2f; private InputManager inputManager; private Camera cam; private Vector3f initialUpVec; @@ -73,14 +74,16 @@ public class PlayerMouseControl extends BaseControl implements AnalogListener { } public void onAnalog(String name, float value, float tpf) { - if (name.equals(MAPPING_PLAYER_LEFT)) { - rotateCamera(value, initialUpVec); - } else if (name.equals(MAPPING_PLAYER_RIGHT)) { - rotateCamera(-value, initialUpVec); - } else if (name.equals(MAPPING_PLAYER_UP)) { - rotateCamera(-value, spatial.getLocalRotation().getRotationColumn(0)); - } else if (name.equals(MAPPING_PLAYER_DOWN)) { - rotateCamera(value, spatial.getLocalRotation().getRotationColumn(0)); + if (spatial.getUserData(UserDataKeys.RUNNING)) { + if (name.equals(MAPPING_PLAYER_LEFT)) { + rotateCamera(value, initialUpVec); + } else if (name.equals(MAPPING_PLAYER_RIGHT)) { + rotateCamera(-value, initialUpVec); + } else if (name.equals(MAPPING_PLAYER_UP)) { + rotateCamera(-value, spatial.getLocalRotation().getRotationColumn(0)); + } else if (name.equals(MAPPING_PLAYER_DOWN)) { + rotateCamera(value, spatial.getLocalRotation().getRotationColumn(0)); + } } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMoveControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMoveControl.java index c4e1147..7012b21 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMoveControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerMoveControl.java @@ -19,7 +19,9 @@ package org.wyrez.shootingstars.controls; import com.jme3.math.FastMath; import com.jme3.scene.Spatial; import com.jme3.scene.control.Control; +import org.wyrez.shootingstars.audiodata.AudioDataManager; import org.wyrez.shootingstars.helper.MathHelper; +import org.wyrez.shootingstars.helper.UserDataKeys; /** * @@ -27,22 +29,57 @@ import org.wyrez.shootingstars.helper.MathHelper; */ public class PlayerMoveControl extends BaseControl { + private static final float BPM_TO_SPEED_FACTOR = 1f / 8f; + //private static final float DASH_MULTIPLIER = 4f; + //private static final float DASH_DURATION = 0.25f; + /**/ + private AudioDataManager audioDataManager; + private float radius = 666f; private float angle = 0f; + private float speed; + //TODO dashing isn't as nice at it should be -.- is it needed? +// private float dashTimer = 0f; - public PlayerMoveControl() { + public PlayerMoveControl(AudioDataManager audioDataManager) { + this.audioDataManager = audioDataManager; + this.speed = audioDataManager.getBPM() * BPM_TO_SPEED_FACTOR; } + public void setRadius(float radius) { + this.radius = radius; + } + + public float getRadius() { + return radius; + } + long lastDash = 0; + @Override protected void controlUpdate(float tpf) { - if (angle > FastMath.TWO_PI) { - angle -= FastMath.TWO_PI; + if (spatial.getUserData(UserDataKeys.RUNNING)) { + if (angle > FastMath.TWO_PI) { + angle -= FastMath.TWO_PI; + } + +// if (audioDataManager.isLowPeak() && dashTimer <= 0f) { +// dashTimer = DASH_DURATION; +// System.out.println((System.nanoTime() - lastDash) / 1000000000.0); +// lastDash = System.nanoTime(); +// } + + spatial.setLocalTranslation(MathHelper.calcPointOnCircle(angle, radius, 250f)); //TODO set y-Position +// if (dashTimer > 0f) { +// angle += MathHelper.degreeToRadian(speed * (DASH_MULTIPLIER +// * (dashTimer / DASH_DURATION)) * tpf); +// dashTimer -= tpf; +// } else { + angle += MathHelper.degreeToRadian(speed * tpf); +// } } - spatial.setLocalTranslation(MathHelper.calcPointOnCircle(angle, 0f)); //TODO set y-Position - //angle += speed //TODO implement } public Control cloneForSpatial(Spatial spatial) { - final PlayerMoveControl control = new PlayerMoveControl(); + PlayerMoveControl control = new PlayerMoveControl(audioDataManager); control.setSpatial(spatial); return control; } diff --git a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerShootControl.java b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerShootControl.java index 57174d2..96162ba 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerShootControl.java +++ b/ShootingStars/src/org/wyrez/shootingstars/controls/PlayerShootControl.java @@ -46,10 +46,12 @@ public class PlayerShootControl extends BaseControl implements ActionListener { @Override protected void controlUpdate(float tpf) { - if (isShooting) { - timeToOverheat -= tpf; - if (timeToOverheat <= 0) { - setShooting(false); + if (spatial.getUserData(UserDataKeys.RUNNING)) { + if (isShooting) { + timeToOverheat -= tpf; + if (timeToOverheat <= 0) { + setShooting(false); + } } } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/helper/MathHelper.java b/ShootingStars/src/org/wyrez/shootingstars/helper/MathHelper.java index fd45cd8..2d998a5 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/helper/MathHelper.java +++ b/ShootingStars/src/org/wyrez/shootingstars/helper/MathHelper.java @@ -26,12 +26,12 @@ import com.jme3.math.Vector3f; */ public class MathHelper { - public static Vector3f calcPointOnCircle(float radian, float y) { - return new Vector3f(FastMath.cos(radian), y, FastMath.sin(radian)); + public static Vector3f calcPointOnCircle(float radian, float radius, float y) { + return new Vector3f(FastMath.cos(radian) * radius, y, FastMath.sin(radian) * radius); } - public static Vector2f calcPointOnCircle(float radian) { - return new Vector2f(FastMath.cos(radian), FastMath.sin(radian)); + public static Vector2f calcPointOnCircle(float radian, float radius) { + return new Vector2f(FastMath.cos(radian) * radius, FastMath.sin(radian) * radius); } public static float radianToDegree(float radian) { diff --git a/ShootingStars/src/org/wyrez/shootingstars/helper/UserDataKeys.java b/ShootingStars/src/org/wyrez/shootingstars/helper/UserDataKeys.java index 43b46b0..e781c2e 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/helper/UserDataKeys.java +++ b/ShootingStars/src/org/wyrez/shootingstars/helper/UserDataKeys.java @@ -24,4 +24,5 @@ public class UserDataKeys { public static final String HITTED = "isHitted"; public static final String SHOOTING = "isShooting"; + public static final String RUNNING = "isRunning"; } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java index 1419f3d..5a96946 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java @@ -16,15 +16,34 @@ */ package org.wyrez.shootingstars.states; -import com.jme3.app.FlyCamAppState; import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; +import com.jme3.asset.AssetManager; +import com.jme3.input.InputManager; +import com.jme3.math.Vector3f; +import com.jme3.post.FilterPostProcessor; +import com.jme3.post.filters.BloomFilter; +import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; +import com.jme3.renderer.ViewPort; +import com.jme3.scene.Geometry; import com.jme3.scene.Node; +import com.jme3.scene.Spatial; +import com.jme3.scene.shape.Box; +import org.wyrez.audio.decoder.DecoderFactory; +import org.wyrez.shootingstars.audiodata.AudioDataManager; +import org.wyrez.shootingstars.audiodata.AudioPlayer; +import org.wyrez.shootingstars.controls.GroundGlowControl; +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.factories.Materials; import org.wyrez.shootingstars.game.Cinema; import org.wyrez.shootingstars.game.Ground; import org.wyrez.shootingstars.gui.GameGUI; import org.wyrez.shootingstars.gui.listener.GameListener; +import org.wyrez.shootingstars.helper.UserDataKeys; import tonegod.gui.core.Screen; /** @@ -32,63 +51,123 @@ import tonegod.gui.core.Screen; * @author Darth Affe */ public class GameState extends AbstractAppState implements GameListener { - + private StateManager stateManager; + private AssetManager assetManager; + private InputManager inputManager; + private ViewPort viewPort; + private Camera camera; + private AudioDataManager audioDataManager; + private AudioPlayer audioPlayer; private Node rootNode; private GameGUI gui; private Cinema cinema; private Ground ground; - - public GameState(Node rootNode, Screen screen, StateManager stateManager) { + private Spatial player; + private boolean isRunning = false; + + public GameState(Node rootNode, Screen screen, StateManager stateManager, + AssetManager assetManager, ViewPort viewPort, + InputManager inputManager, Camera camera, AudioDataManager audioDataManager) { this.rootNode = rootNode; this.gui = new GameGUI(screen, this); this.stateManager = stateManager; + this.inputManager = inputManager; + this.camera = camera; + this.audioDataManager = audioDataManager; + this.assetManager = assetManager; + this.viewPort = viewPort; } - + public void loadGround() { - this.ground = new Ground(); + ground = new Ground(); + + for (Spatial s : ground.getChildren()) { + s.addControl(new GroundGlowControl(audioDataManager)); + } + + FilterPostProcessor fpp = new FilterPostProcessor(assetManager); + fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects)); + viewPort.addProcessor(fpp); } - + + public boolean initAudioPlayer() { + try { + this.audioPlayer = new AudioPlayer(DecoderFactory.create("Lost One no Goukoku.mp3")) {//TODO path + @Override + public void finished(boolean cleanup) { + System.out.println(">>> FINISHED!"); + } + }; + return true; + } catch (Exception ex) { + return false; + } + } + public void loadCinema() { - this.cinema = new Cinema("Broken.mp4"); //TODO settings? + cinema = new Cinema("Broken.mp4"); //TODO settings? cinema.move(0f, 160f, 0f); } - + + public void loadPlayer() { + player = new Geometry("player", new Box(Vector3f.ZERO, 1f, 1f, 1f)); //TODO start location? + player.setMaterial(Materials.UNSHADED.create()); + player.setUserData(UserDataKeys.RUNNING, false); + player.addControl(new PlayerMouseControl(inputManager, camera)); + player.addControl(new PlayerMoveControl(audioDataManager)); + player.addControl(new PlayerShootControl(inputManager)); + player.addControl(new PlayerCamControl(camera)); + } + public void start() { gui.setStart(); + inputManager.setCursorVisible(false); + player.setUserData(UserDataKeys.RUNNING, true); cinema.play(); + audioPlayer.start(); + isRunning = true; } - + @Override public void stateAttached(AppStateManager stateManager) { - stateManager.attach(new FlyCamAppState()); //TODO debug +// stateManager.attach(new FlyCamAppState()); //TODO debug rootNode.attachChild(cinema); rootNode.attachChild(ground); + rootNode.attachChild(player); gui.setWait(); gui.attach(); } - + @Override public void stateDetached(AppStateManager stateManager) { - stateManager.detach(new FlyCamAppState()); //TODO debug +// stateManager.detach(new FlyCamAppState()); //TODO debug gui.detach(); + rootNode.detachChild(player); rootNode.detachChild(ground); rootNode.detachChild(cinema); cinema.cleanup(); + inputManager.setCursorVisible(true); } - + @Override public void render(RenderManager rm) { cinema.render(); } - + @Override public void update(float tpf) { + audioDataManager.update(tpf); } - + @Override public void cleanup() { super.cleanup(); cinema.cleanup(); + audioPlayer.cleanup(); + } + + public AudioPlayer getAudioPlayer() { + return audioPlayer; } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java index 001af2f..62674a2 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java @@ -18,6 +18,7 @@ package org.wyrez.shootingstars.states; import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; +import org.wyrez.shootingstars.audiodata.AudioDataManager; import org.wyrez.shootingstars.gui.LoadingGui; import org.wyrez.shootingstars.states.util.LoadingProgress; import tonegod.gui.core.Screen; @@ -30,11 +31,14 @@ public class LoadingState extends AbstractAppState { private StateManager stateManager; private LoadingGui gui; + private AudioDataManager audioDataManager; private LoadingProgress currentProgress; - public LoadingState(Screen screen, StateManager stateManager) { + public LoadingState(Screen screen, StateManager stateManager, + AudioDataManager audioDataManager) { this.stateManager = stateManager; this.gui = new LoadingGui(screen); + this.audioDataManager = audioDataManager; } @Override @@ -52,10 +56,22 @@ public class LoadingState extends AbstractAppState { public void update(float tpf) { switch (currentProgress) { case START: + currentProgress = LoadingProgress.INIT_AUDIO_PLAYER; + break; + case INIT_AUDIO_PLAYER: + initAudioPlayer(); + currentProgress = LoadingProgress.INIT_AUDIO_ANALYSIS; + break; + case INIT_AUDIO_ANALYSIS: + initAudioAnalysis(); currentProgress = LoadingProgress.ANALYSE_LOW_BAND; break; case ANALYSE_LOW_BAND: analyseLowBand(); + currentProgress = LoadingProgress.ANALYSE_MID_BAND; + break; + case ANALYSE_MID_BAND: + analyseMidBand(); currentProgress = LoadingProgress.ANALYSE_HIGH_BAND; break; case ANALYSE_HIGH_BAND: @@ -68,6 +84,10 @@ public class LoadingState extends AbstractAppState { break; case GENERATING_SCENE: generateScene(); + currentProgress = LoadingProgress.LOADING_PLAYER; + break; + case LOADING_PLAYER: + loadPlayer(); currentProgress = LoadingProgress.DONE; break; case DONE: @@ -77,12 +97,26 @@ public class LoadingState extends AbstractAppState { gui.updateProgress(currentProgress); } + private void initAudioAnalysis() { + GameState gs = stateManager.getState(State.GAME); + audioDataManager.initialize("Lost One no Goukoku.mp3", gs.getAudioPlayer()); //TODO path + } + private void analyseLowBand() { - //TODO fill + audioDataManager.analyseLowBand(); + } + + private void analyseMidBand() { + audioDataManager.analyseMidBand(); } private void analyseHighBand() { - //TODO fill + audioDataManager.analyseHighBand(); + } + + private void initAudioPlayer() { + GameState gs = stateManager.getState(State.GAME); + gs.initAudioPlayer(); } private void loadingCinema() { @@ -95,6 +129,11 @@ public class LoadingState extends AbstractAppState { gs.loadGround(); } + private void loadPlayer() { + GameState gs = stateManager.getState(State.GAME); + gs.loadPlayer(); + } + public void done() { stateManager.setState(State.GAME); } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java b/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java index 951cd7c..34597f3 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java @@ -22,9 +22,16 @@ package org.wyrez.shootingstars.states.util; */ public enum LoadingProgress { - START("Loading...", 0), ANALYSE_LOW_BAND("Analyse Low-Band...", 0), - ANALYSE_HIGH_BAND("Analyse High-Band...", 1), LOADING_CINEMA("Loading Cinema", 2), - GENERATING_SCENE("Generating Scene...", 3), DONE("Done!", 3); + START("Loading...", 0), + INIT_AUDIO_PLAYER("Loading Audio-Player...", 1), + INIT_AUDIO_ANALYSIS("Creating Samples...", 2), + ANALYSE_LOW_BAND("Analyse Low-Band...", 3), + ANALYSE_MID_BAND("Analyse Mid-Band...", 4), + ANALYSE_HIGH_BAND("Analyse High-Band...", 5), + LOADING_CINEMA("Loading Cinema", 6), + GENERATING_SCENE("Generating Scene...", 7), + LOADING_PLAYER("Loading Player...", 8), + DONE("Done!", 8); private String text; private float value;