diff --git a/ShootingStars/lib/AudioProcessing-1.0.jar b/ShootingStars/lib/AudioProcessing-1.0.jar index 098b24e..9f32196 100644 Binary files a/ShootingStars/lib/AudioProcessing-1.0.jar and b/ShootingStars/lib/AudioProcessing-1.0.jar differ diff --git a/ShootingStars/nbproject/project.properties b/ShootingStars/nbproject/project.properties index 0ac05a6..1cac98e 100644 --- a/ShootingStars/nbproject/project.properties +++ b/ShootingStars/nbproject/project.properties @@ -54,7 +54,8 @@ javac.classpath=\ ${file.reference.mp3spi1.9.5.jar}:\ ${file.reference.tritonus_aos-0.3.6.jar}:\ ${file.reference.tritonus_share-0.3.6.jar}:\ - ${file.reference.AudioProcessing-1.0.jar} + ${file.reference.AudioProcessing-1.0.jar}:\ + ${libs.jme3-libraries-effects.classpath} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java index c718ce0..adfdc4a 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java +++ b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java @@ -21,10 +21,13 @@ import com.jme3.app.DebugKeysAppState; import com.jme3.app.SimpleApplication; import com.jme3.app.StatsAppState; import com.jme3.app.state.AppStateManager; -import com.jme3.math.Vector3f; +import com.jme3.asset.AssetManager; +import com.jme3.input.InputManager; import com.jme3.renderer.Camera; +import com.jme3.renderer.ViewPort; import com.jme3.scene.Node; import org.wyrez.persij.PersiJContainer; +import org.wyrez.shootingstars.audiodata.AudioDataManager; import org.wyrez.shootingstars.factories.Materials; import org.wyrez.shootingstars.states.State; import org.wyrez.shootingstars.states.StateManager; @@ -53,7 +56,7 @@ public class ShootingStars extends SimpleApplication { Materials.initialize(assetManager); cam.setFrustumFar(2500f); //TODO debug - cam.setLocation(new Vector3f(0f, 2500f, 0f)); + //cam.setLocation(new Vector3f(0f, 2500f, 0f)); sManager = container.resolve(StateManager.class); sManager.setState(State.START); @@ -70,8 +73,12 @@ public class ShootingStars extends SimpleApplication { container.registerSingleton(Node.class, rootNode); container.registerSingleton(Camera.class, cam); container.registerSingleton(AppStateManager.class, stateManager); + container.registerSingleton(InputManager.class, inputManager); + container.registerSingleton(AssetManager.class, assetManager); + container.registerSingleton(ViewPort.class, viewPort); container.registerType(StateManager.class, true); container.registerType(Screen.class, true); + container.registerType(AudioDataManager.class, true); } public static void main(String[] args) { diff --git a/ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioDataManager.java b/ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioDataManager.java new file mode 100644 index 0000000..433d7c9 --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/audiodata/AudioDataManager.java @@ -0,0 +1,106 @@ +/* + * 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.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;