Ejemplo n.º 1
0
  public void createPolygons() {
    Graphics2D g = screen.getGraphics();
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, screen.getWidth(), screen.getHeight());
    g.setColor(Color.WHITE);
    g.drawString("Loading...", 5, screen.getHeight() - 5);
    screen.update();

    float ambientLightIntensity = .2f;
    List lights = new LinkedList();
    lights.add(new PointLight3D(-100, 100, 100, .3f, -1));
    lights.add(new PointLight3D(100, 100, 0, .3f, -1));

    MapLoader loader = new MapLoader(new BSPTreeBuilderWithPortals());
    loader.setObjectLights(lights, ambientLightIntensity);

    try {
      bspTree = loader.loadMap(mapFile);
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    collisionDetection = new CollisionDetectionWithSliding(bspTree);
    gameObjectManager = new GridGameObjectManager(bspTree.calcBounds(), collisionDetection);
    gameObjectManager.addPlayer(new Player());

    ((BSPRenderer) polygonRenderer).setGameObjectManager(gameObjectManager);

    createGameObjects(loader.getObjectsInMap());
    Transform3D start = loader.getPlayerStartLocation();
    gameObjectManager.getPlayer().getTransform().setTo(start);
  }