Guest User

Untitled

a guest
Sep 5th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.09 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package com.ractoc.fs.invasion.appstates;
  6.  
  7. import com.jme3.app.Application;
  8. import com.jme3.app.state.AbstractAppState;
  9. import com.jme3.app.state.AppStateManager;
  10. import com.jme3.material.Material;
  11. import com.jme3.math.ColorRGBA;
  12. import com.jme3.scene.Geometry;
  13. import com.jme3.scene.shape.Quad;
  14. import com.jme3.texture.Image;
  15. import com.jme3.texture.Texture2D;
  16. import com.ractoc.fs.invasion.GameClient;
  17. import java.io.ByteArrayOutputStream;
  18. import java.io.IOException;
  19. import java.nio.ByteBuffer;
  20.  
  21. /**
  22.  *
  23.  * @author ractoc
  24.  */
  25. public class StarField extends AbstractAppState {
  26.  
  27.     private Geometry starField;
  28.     private int width, height, density, layers;
  29.     private GameClient gameClient;
  30.  
  31.     public StarField(int width, int height, int density, int layers) {
  32.         this.width = width;
  33.         this.height = height;
  34.         this.density = density;
  35.         this.layers = layers;
  36.     }
  37.  
  38.     @Override
  39.     public final void initialize(final AppStateManager stateManager,
  40.             final Application app) {
  41.         super.initialize(stateManager, app);
  42.         this.gameClient = (GameClient) app;
  43.         Quad starQ = new Quad(width, height);
  44.         starField = new Geometry("starField", starQ);
  45.  
  46.         Material mat = new Material(gameClient.getAssetManager(),
  47.                 "Common/MatDefs/Misc/Unshaded.j3md");
  48.         mat.setColor("Color", ColorRGBA.Blue);
  49.         Texture2D t = new Texture2D();
  50.         Image i = new Image(Image.Format.RGBA8, width, height, null);
  51.         t.setImage(i);
  52.         mat.setTexture("stars", t);
  53.         starField.setMaterial(mat);
  54.         gameClient.getRootNode().attachChild(starField);
  55.     }
  56.  
  57.     private ByteBuffer addStars() throws IOException {
  58.         ByteArrayOutputStream baos = new ByteArrayOutputStream();
  59.         for (int i = 0; i < layers; i++) {
  60.             for (int j = 0; j < density; j++) {
  61.                 baos.write(createStar());
  62.             }
  63.         }
  64.         return ByteBuffer.wrap(baos.toByteArray());
  65.     }
  66.    
  67.     private byte[] createStar() {
  68.         return null;
  69.     }
  70. }
Add Comment
Please, Sign In to add comment