Package edu.ups.gamedev.terrain.tile

Source Code of edu.ups.gamedev.terrain.tile.TileGame

package edu.ups.gamedev.terrain.tile;

import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;

import javax.imageio.ImageIO;

import com.jme.app.SimpleGame;
import com.jme.light.PointLight;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.system.DisplaySystem;
import com.jmex.terrain.util.ImageBasedHeightMap;

import edu.ups.gamedev.terrain.Level;
import edu.ups.gamedev.terrain.MaterialTerrainPage;

public class TileGame extends SimpleGame {
  public static void main( String[] args ) {
     TileGame tg = new TileGame();
     tg.setDialogBehaviour( TileGame.ALWAYS_SHOW_PROPS_DIALOG );
     tg.start();
  }
 
  public static DisplaySystem d;
  public static void setDisplay( DisplaySystem displaySystem ) {
    d = displaySystem;
  }
  public static DisplaySystem getDisplay() {
    return d;
  }


  @Override
  protected void simpleInitGame() {
    TileGame.setDisplay( this.display );
    try {
      File[] files = new File[3];
      files[0] = new File( "/Users/scanfield/Desktop/map/tile3.png" );
      files[1] = new File( "/Users/scanfield/Desktop/map/tile4.png" );
      files[2] = new File( "/Users/scanfield/Desktop/map/tile1.png" );
      File heightMapFile = new File( "/Users/scanfield/Desktop/map/heightmap.png" );
      TileMap tileMap = new TileMap( new File( "/Users/scanfield/Desktop/map/tilemap.png" ), new ImageBasedHeightMap( ImageIO.read( heightMapFile )), files );
     
      System.out.println( TileTexture.TILE_WIDTH + "x" + TileTexture.TILE_HEIGHT );
     
      Node[][] nodes = new Node[10][10];
      for( int n = 0; n < 10; n++ ) {
        for( int j = 0; j < 10; j++ ) {
          nodes[n][j] = new Node();
        }
      }
     
      for( int x = 0; x < tileMap.getTilesWide(); x++ ) {
        for( int y = 0; y < tileMap.getTilesHigh(); y++ ) {
          Tile t  = tileMap.getTileAtPoint( x, y  );
        //  t.setLocalTranslation( new Vector3f( (float)x*1.85f, (float)y*1.85f , 0.0f));
          nodes[ x / 13 ][ y / 13 ].attachChild( t );
        }
      }
     
      for( int n = 0; n < 10; n++ ) {
        for( int j = 0; j < 10; j++ ) {
          nodes[n][j].updateModelBound();
          nodes[n][j].updateWorldBound();
          rootNode.attachChildnodes[n][j] );
        }
      }
      System.out.println( "Done loading tiles...");
     
      int x = 4; int y= 0;
      for( String k : tileMap.keys ) {
        String row1 = k.substring( 0, 3);
        String row2 = k.substring( 3, 6);
        String row3 = k.substring( 6, 9);
        System.out.print("ht.put(\"" + row1 + "\" +" +
            "\"" + row2 + "\" +" +
            "\"" + row3 + "\"," +
            "new Vector2f( " + x + " * TileTexture.TILE_WIDTH, " + y +  " * TileTexture.TILE_HEIGHT));\n");
            x++;
            if( x > 7 ) {
              x = 4;
              y++;
              if( y > 3 ) {
                y = 0;
              }
            }
      }
     

     
      cam.setFrustumPerspective(45.0f, (float) display.getWidth()
          / (float) display.getHeight(), 1, 3000);
      cam.update();

      wireState.setEnabled(true);
     
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
TOP

Related Classes of edu.ups.gamedev.terrain.tile.TileGame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.