Advertisement
mifth

ShootBulletRun.java

Sep 29th, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1.  
  2. import com.jme3.app.SimpleApplication;
  3. import com.jme3.font.BitmapText;
  4. import com.jme3.material.Material;
  5. import com.jme3.math.*;
  6. import com.jme3.scene.Geometry;
  7. import com.jme3.scene.Spatial;
  8. import com.jme3.scene.shape.Box;
  9. import com.jme3.system.AppSettings;
  10.  
  11.  
  12. public class ShootBulletRun extends SimpleApplication {
  13.  
  14.  
  15.    
  16.     public static void main(String[] args) {
  17.         ShootBulletRun app = new ShootBulletRun();
  18.        
  19.         //set vSinc on to get stable 60 fps
  20.         AppSettings aps = new AppSettings(true);
  21.         aps.setVSync(true);
  22.         app.setSettings(aps);
  23.         app.start();
  24.     }
  25.  
  26. ShootBullet shb;
  27. //ShootBulletControl sbc;
  28. Spatial charShoot;
  29. Material mat_box;
  30. Box box_char = new Box(Vector3f.ZERO, 1, 1, 1);
  31. float timer;
  32.  
  33.  
  34.  public void shootObj() {
  35.    
  36.         // Create a blue box Geometry
  37.        
  38.         charShoot = new Geometry("Box", box_char);
  39.         charShoot.scale(1,1,2);
  40.        
  41.         mat_box = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  42.         mat_box.setColor("Color", ColorRGBA.Blue);
  43.         charShoot.setMaterial(mat_box);
  44.        
  45.         rootNode.attachChild(charShoot);    
  46.  
  47.     }    
  48.  
  49.     @Override
  50.     public void simpleInitApp() {
  51.  
  52.       shootObj();
  53.       starting();
  54.       shb = new ShootBullet(this);
  55.      
  56.      
  57.      
  58.  
  59.              
  60.     }
  61.    
  62.  
  63.     @Override
  64. public void simpleUpdate(float tpf)
  65. {
  66.    
  67.     timer += tpf*4f;
  68.     if (timer>0.2f){
  69.       Geometry gm = shb.bullet.clone(false);
  70.       gm.addControl(new ShootBulletControl(gm, charShoot, this));
  71. //      gm.getControl(0).setEnabled(true);
  72.       timer = 0;
  73.     }
  74.      
  75.     charShoot.rotate(0,2f*tpf,0);  
  76.      
  77.    
  78.    
  79.     System.out.println(timer);
  80.        
  81.  }
  82.  
  83.     public void starting () {
  84.          guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
  85.         BitmapText ch = new BitmapText(guiFont, false);
  86.         ch.setSize(guiFont.getCharSet().getRenderedSize());
  87.         ch.setText("Shooting Cube!"); // crosshairs
  88.         ch.setColor(new ColorRGBA(1f,0.8f,0.1f,1f));
  89.         ch.setLocalTranslation(settings.getWidth()*0.3f,settings.getHeight()*0.1f,0);
  90.         guiNode.attachChild(ch);
  91.        
  92.         viewPort.setBackgroundColor(ColorRGBA.Gray);
  93.         flyCam.setMoveSpeed(30);
  94.         cam.setLocation(new Vector3f(0f,3f,30f));
  95.        
  96.     }
  97.  
  98.    
  99. }
  100.  
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement