Esempio n. 1
0
  private void draw() {

    // Clear the screen and depth buffer
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();

    // set up GameContext.getCamera()
    GL11.glPushMatrix();

    GL11.glScalef(scale, scale, scale);
    GL11.glTranslatef(
        -GameContext.getCamera().getPosition().getx(),
        -GameContext.getCamera().getPosition().gety(),
        0);
    GL11.glTranslatef(4f, 3f, 0);

    map.draw();

    if (editorMode) {
      Quad q = new Quad(editorTag.getPosition(), map.getLookupTile(currentEditorTile).getTexture());
      GameContext.getPipe().addDrawable(q);
    }

    for (Entity ae : entities) {
      ae.draw();
    }

    GameContext.getPipe().renderContent();

    GL11.glPopMatrix();

    // overlay console text

    GL11.glPushMatrix();
    GL11.glScalef(2f, 2f, 2f);

    if (console.isEnabled()) {
      gtest.drawing.util.drawString(new Coord(0, 0), "> " + console.getText());
    }

    if (GameContext.isDebugMode()) {
      gtest.drawing.util.drawString(
          new Coord(0, 285), "tiles drawn " + GameContext.getFromLog("tilesLastDrawn"));
      gtest.drawing.util.drawString(
          new Coord(0, 275), "textures bound " + GameContext.getFromLog("textureBinds"));
      gtest.drawing.util.drawString(new Coord(0, 265), "FPS " + GameContext.getFromLog("fps"));
    }

    GL11.glPopMatrix();

    Display.update();

    // clean up

    GameContext.getPipe().clear();
    GameContext.addToLog("tilesLastDrawn", "0");
    GameContext.addToLog("textureBinds", "0");
  }
Esempio n. 2
0
  public void start() {

    // set up the console handler

    console.setHandler(new ConsoleHandler());

    // load the map

    map = MapLoader.loadMap("map_basic.txt");

    // grab some entities

    StaticEntity chip = new StaticEntity();
    chip.setPosition(new Coord(9, 5));
    chip.addTexture(GameContext.getTextureLoader().getTexture("gtest/resources/chipA.png"));
    chip.addTexture(GameContext.getTextureLoader().getTexture("gtest/resources/chipB.png"));
    entities.add(chip);

    // create the player
    player = new Player(new Coord(0, 12));
    player.setMapContext(map);
    entities.add(player);

    // set up camera
    GameContext.getCamera().setFollowing(player);

    // set up openGL

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // game loop

    while (!Display.isCloseRequested()) {

      Date d = new Date();
      long startTime = d.getTime();

      draw();
      update();
      handleInput();

      d = new Date();
      long endTime = d.getTime();

      try {
        Thread.sleep(50 - (endTime - startTime));
      } catch (Exception e) {
      }

      if ((endTime - startTime) != 0) {
        GameContext.addToLog("fps", "" + 1000 / (endTime - startTime));
      }
    }

    Display.destroy();
  }