Marvinssdf

Untitled

Jun 21st, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.43 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package testaudio;
  6.  
  7. import com.jme3.app.SimpleApplication;
  8. import com.jme3.asset.plugins.FileLocator;
  9. import com.jme3.audio.AudioNode;
  10. import com.jme3.input.controls.ActionListener;
  11. import com.jme3.input.controls.MouseButtonTrigger;
  12. import com.jme3.material.Material;
  13. import com.jme3.math.ColorRGBA;
  14. import com.jme3.math.Vector3f;
  15. import com.jme3.scene.Geometry;
  16. import com.jme3.scene.shape.Box;
  17.  
  18.  
  19. public class Testaudio extends SimpleApplication{
  20.  
  21.     private AudioNode soundpos1;
  22.     private AudioNode soundpos2;
  23.     private AudioNode soundpos3;
  24.     private AudioNode soundnopos;
  25.     private Geometry player;
  26.     public static Testaudio app;
  27.     int i = 0;
  28.     /**
  29.      * @param args the command line arguments
  30.      */
  31.     public static void main(String[] args) {
  32.         // TODO code application logic here
  33.         app = new Testaudio();
  34.         app.start();
  35.     }
  36.    
  37.     @Override
  38.   public void simpleInitApp() {
  39.     flyCam.setMoveSpeed(40);
  40.  
  41.     /** just a blue box floating in space */
  42.     Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
  43.     player = new Geometry("Player", box1);
  44.     Material mat1 = new Material(assetManager,
  45.             "Common/MatDefs/Misc/Unshaded.j3md");
  46.     mat1.setColor("Color", ColorRGBA.Blue);
  47.     player.setMaterial(mat1);
  48.     rootNode.attachChild(player);
  49.  
  50.     /** custom init methods, see below */
  51.     initKeys();
  52.     initAudio();
  53.   }
  54.  
  55.  
  56. private void initAudio() {
  57.     assetManager.registerLocator("C:/", FileLocator.class);
  58.     soundpos1 = new AudioNode(assetManager, "ASSETS/SOUNDS/BGM/esismono.wav");
  59.     soundpos1.setPositional(true);
  60.     soundpos1.setMaxDistance(50f);
  61.     soundpos1.setLocalTranslation(-200, 0, -200);
  62.     soundpos1.setLooping(true);
  63.     soundpos1.play();
  64.  
  65.     soundpos2 = new AudioNode(assetManager, "ASSETS/SOUNDS/BGM/gerudomono.wav");
  66.     soundpos2.setPositional(true);
  67.     soundpos2.setMaxDistance(50f);
  68.     soundpos2.setLocalTranslation(-200, 0, -200);
  69.     soundpos2.setLooping(true);
  70.     soundpos2.play();
  71.  
  72.     soundnopos = new AudioNode(assetManager, "ASSETS/SOUNDS/BGM/dafthbfs.wav");
  73.     soundnopos.setPositional(false);
  74.     soundnopos.setVolume(0.3f);
  75.     soundnopos.setLooping(true);
  76.     soundnopos.play();
  77. }
  78.  
  79.   private void initKeys() {
  80.     inputManager.addMapping("leftClick", new MouseButtonTrigger(0));
  81.     inputManager.addMapping("rightClick", new MouseButtonTrigger(1));
  82.     inputManager.addListener(actionListener, "leftClick");
  83.     inputManager.addListener(actionListener, "rightClick");
  84.   }
  85.  
  86.   private ActionListener actionListener = new ActionListener() {
  87.     @Override
  88.     public void onAction(String name, boolean keyPressed, float tpf) {
  89.       if (name.equals("leftClick") && !keyPressed) {
  90.           if (soundpos1 != null){
  91.               soundpos1.stop();
  92.           }
  93.       }
  94.       if (name.equals("rightClick") && !keyPressed) {
  95.           if (soundpos2 != null){
  96.               soundpos2.stop();
  97.           }
  98.       }
  99.     }
  100.   };
  101.  
  102.     @Override
  103.     public void simpleUpdate(float tpf) {
  104.         if (soundpos1.getStatus() == AudioNode.Status.Playing || soundpos2.getStatus() == AudioNode.Status.Playing){
  105.             if (soundpos1.getLocalTranslation() == new Vector3f(-200,0,-200)){
  106.                 soundpos1.setLocalTranslation(new Vector3f(-200,0,200));
  107.                 soundpos2.setLocalTranslation(new Vector3f(-200,0,200));
  108. //              soundMan.setSoundPosition(soundpos3, new Vector3f(-200,0,200));
  109.  
  110.             } else if (soundpos1.getLocalTranslation() == new Vector3f(-200,0,200)){
  111.                 soundpos1.setLocalTranslation(new Vector3f(200,0,200));
  112.                 soundpos2.setLocalTranslation(new Vector3f(200,0,200));
  113. //              soundMan.setSoundPosition(soundpos3, new Vector3f(200,0,200));
  114.  
  115.             } else if (soundpos1.getLocalTranslation() == new Vector3f(200,0,200)){
  116.                 soundpos1.setLocalTranslation(new Vector3f(-200,0,200));
  117.                 soundpos2.setLocalTranslation(new Vector3f(-200,0,200));
  118. //            soundMan.setSoundPosition(soundpos3, new Vector3f(-200,0,200));
  119.  
  120.             } else {
  121.                 soundpos1.setLocalTranslation(new Vector3f(-200,0,-200));
  122.                 soundpos2.setLocalTranslation(new Vector3f(-200,0,-200));
  123. //              soundMan.setSoundPosition(soundpos3, new Vector3f(-200,0,-200));
  124.             }          
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment