Exemplo 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");
  }
Exemplo n.º 2
0
  public void handleInput() {

    // handle movement keys

    if (!editorMode) {

      if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
        player.move(Player.LEFT);
      } else if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
        player.move(Player.RIGHT);
      } else if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
        player.move(Player.DOWN);
      } else if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
        player.move(Player.UP);
      }

    } else {

      if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
        editorTag.getPosition().add(new Coord(-1f, 0f));
      } else if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
        editorTag.getPosition().add(new Coord(1f, 0f));
      } else if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
        editorTag.getPosition().add(new Coord(0f, -1f));
      } else if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
        editorTag.getPosition().add(new Coord(0f, 1f));
      }
    }

    // handle other keys

    while (Keyboard.next()) {

      char k = Keyboard.getEventCharacter();

      // the ` key toggles the console

      if (k == '`') {
        if (console.isEnabled()) {
          console.disable();
        } else {
          console.enable();
        }
      } else if (console.isEnabled()) {

        if (Keyboard.getEventKeyState()) {
          console.nextChar(k);
        }
      }

      // editor specific commands

      if (editorMode && !console.isEnabled()) {

        if (k == ' ') {
          map.setTile(editorTag.getPosition(), currentEditorTile);
        } else if (k == 'n') {
          currentEditorTile = (currentEditorTile + 1) % map.getNumTypes();
        }
      }
    }
  }