Exemple #1
0
 public static void resizedRefresh() {
   GL11.glMatrixMode(GL11.GL_PROJECTION);
   GL11.glLoadIdentity(); // Resets any previous projection matrices
   GL11.glOrtho(0, Display.getWidth(), 0, Display.getHeight(), 1000, -1000);
   GL11.glMatrixMode(GL11.GL_MODELVIEW);
   GL11.glLoadIdentity();
 }
 private static void setUpCamera() {
   cam =
       new EulerCamera(
           (float) Display.getWidth() / (float) Display.getHeight(), -2.19f, 1.36f, 11.45f);
   cam.setFieldOfView(70);
   cam.applyPerspectiveMatrix();
 }
 private void initGL() {
   try {
     Display.setDisplayMode(new DisplayMode(GS.FRAMEWIDTH, GS.FRAMEHEIGHT));
     Display.setFullscreen(true);
     Display.create();
     Display.setVSyncEnabled(true);
   } catch (LWJGLException e) {
     e.printStackTrace();
     Display.destroy();
     System.exit(1);
   }
   GL11.glEnable(GL11.GL_TEXTURE_2D);
   // GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   GL11.glClearDepth(1.0f);
   // GL11.glEnable(GL11.GL_DEPTH_TEST);
   // GL11.glDepthFunc(GL11.GL_ADD); //Wenn nicht auskommentiert führt es zu Exception
   GL11.glMatrixMode(GL11.GL_PROJECTION);
   GL11.glViewport(0, 0, GS.FRAMEWIDTH, GS.FRAMEHEIGHT);
   GL11.glOrtho(0, GS.FRAMEWIDTH, GS.FRAMEHEIGHT, 0, 0, 128);
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   // GL11.glBlendEquation( BLENDING_EQUATIONS[blendingEquationIndex]);
   GL11.glShadeModel(GL11.GL_FLAT);
   GL11.glMatrixMode(GL11.GL_MODELVIEW);
   GL11.glEnable(GL11.GL_ALPHA_TEST);
   GL11.glAlphaFunc(GL11.GL_GREATER, 0);
   GL11.glCullFace(GL11.GL_BACK);
   glEnable(GL_CULL_FACE);
   glCullFace(GL_BACK);
   GL11.glLoadIdentity();
 }
  public static void main(String[] args) throws InterruptedException {
    try {
      Display.setTitle("Simple Square");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    // draw the square
    glBegin(GL_LINE_LOOP);
    glVertex3f(-0.5f, -0.5f, 0f);
    glVertex3f(-0.5f, 0.5f, 0f);
    glVertex3f(0.5f, 0.5f, 0f);
    glVertex3f(0.5f, -0.5f, 0f);
    glEnd();

    // flush any commands that are still hanging about.
    glFlush();
    // update window.
    Display.update();

    while (!Display.isCloseRequested()) {
      Thread.sleep(100);
    }
    Display.destroy();
  }
  public void update(int delta) {
    // rotate quad
    rotation += 0.15f * delta;

    if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) x -= 0.35f * delta;
    if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) x += 0.35f * delta;

    if (Keyboard.isKeyDown(Keyboard.KEY_UP)) y -= 0.35f * delta;
    if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) y += 0.35f * delta;

    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {
        if (Keyboard.getEventKey() == Keyboard.KEY_F) {
          setDisplayMode(800, 600, !Display.isFullscreen());
        } else if (Keyboard.getEventKey() == Keyboard.KEY_V) {
          vsync = !vsync;
          Display.setVSyncEnabled(vsync);
        }
      }
    }

    // keep quad on the screen
    if (x < 0) x = 0;
    if (x > 800) x = 800;
    if (y < 0) y = 0;
    if (y > 600) y = 600;

    updateFPS(); // update FPS Counter
  }
Exemple #6
0
  // ***************************************************************************
  // initDisplay
  // ***************************************************************************
  private static void initDisplay(boolean fullscreen) {
    DisplayMode chosenMode = null;

    try {
      DisplayMode[] modes = Display.getAvailableDisplayModes();

      for (int i = 0; i < modes.length; i++) {
        if ((modes[i].getWidth() == targetWidth) && (modes[i].getHeight() == targetHeight)) {
          chosenMode = modes[i];
          break;
        }
      }
    } catch (LWJGLException e) {
      Sys.alert("Error", "Unable to determine display modes.");
      System.exit(0);
    }

    // at this point if we have no mode there was no appropriate, let the user know
    // and give up
    if (chosenMode == null) {
      Sys.alert("Error", "Unable to find appropriate display mode.");
      System.exit(0);
    }

    try {
      Display.setDisplayMode(chosenMode);
      Display.setFullscreen(fullscreen);
      Display.setTitle("OpenCraft");
      Display.create();

    } catch (LWJGLException e) {
      Sys.alert("Error", "Unable to create display.");
      System.exit(0);
    }
  }
 @Override
 public void run() {
   long lastTime = System.nanoTime();
   start();
   long now = System.nanoTime();
   long timer = System.currentTimeMillis();
   double delta = 0;
   int frames = 0;
   int updates = 0;
   System.out.println("Initialized in " + ((now - lastTime) / 1000000000.0) + " seconds");
   while (!Display.isCloseRequested()) {
     now = System.nanoTime();
     delta += (now - lastTime) / NANOSECS;
     lastTime = now;
     while (delta >= 1) {
       update(updates);
       updates++;
       delta--;
     }
     render();
     frames++;
     if (System.currentTimeMillis() - timer > 1000) {
       timer += 1000;
       Display.setTitle("SplitMan | FPS: " + frames + " | UPS: " + updates);
       frames = 0;
       updates = 0;
     }
     Display.update();
     Display.sync(120);
   }
   stop();
 }
Exemple #8
0
  public void start() {
    // ウィンドウの生成
    try {
      Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
      // Display.setTitle("SimField");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    }

    initGL();

    // メインループ
    while (!Display.isCloseRequested()) {
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
      /**
       * for(Life l : lifeSet.getArray()){ l.renderLife(); } for(Life lr: lifeRedSet.getArray()){
       * lr.renderLife(); } for(Life lb: lifeBlueSet.getArray()){ lb.renderLife(); }
       */
      for (Life l : life) {
        l.renderLife();
      }
      for (Life lr : lifeRed) {
        lr.renderLife();
      }
      for (Life lb : lifeBlue) {
        lb.renderLife();
      }
      status.updateFPS();
      Display.update(); // オンスクリーンに反映
      Display.sync(60); // FPSを60に固定
    }
  }
  public void display(long deltaTime) {
    Display.sync(60);
    elapsedTime += deltaTime;

    if (Display.wasResized()) resize();

    float[] offsets = computePositionOffsets(0, 0, deltaTime);
    float xOffset = offsets[0];
    float yOffset = offsets[1];
    adjustVertexData(xOffset, yOffset);

    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(program);

    glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, 0);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    glDisableVertexAttribArray(0);
    glUseProgram(0);

    Display.update(); // calls (among other things) swapBuffers()
  }
  public void run() {
    if (listener == null)
      throw new IllegalStateException(
          "SystemListener is not set on context!" + "Must set with JmeContext.setSystemListner().");

    logger.log(Level.INFO, "Using LWJGL {0}", Sys.getVersion());
    if (!initInThread()) {
      logger.log(Level.SEVERE, "Display initialization failed. Cannot continue.");
      return;
    }
    while (true) {
      if (renderable.get()) {
        if (Display.isCloseRequested()) listener.requestClose(false);

        if (wasActive != Display.isActive()) {
          if (!wasActive) {
            listener.gainFocus();
            timer.reset();
            wasActive = true;
          } else {
            listener.loseFocus();
            wasActive = false;
          }
        }
      }

      runLoop();

      if (needClose.get()) break;
    }
    deinitInThread();
  }
Exemple #11
0
public abstract class GElement {

  public int id;
  protected float xPos, yPos;
  protected float width, height;
  protected float xScale = Display.getWidth();
  protected float yScale = Display.getHeight();

  public boolean visible = true;
  public boolean enabled = true;

  public abstract void render();

  public void update(boolean leftClicked, boolean leftReleased) {}

  public boolean isHovered() {
    if (!enabled) return false;
    int x = Mouse.getX();
    int y = Display.getHeight() - Mouse.getY();

    boolean flagX = x >= xPos && x < xPos + width;
    boolean flagY = y >= yPos && y < yPos + height;

    if (flagX && flagY && enabled && visible) return true;
    return false;
  }
}
Exemple #12
0
  /**
   * The menu sequence that allows the user to select options.
   *
   * <p>
   *
   * <ul>
   *   <li>QuickStart (random character created for the player)
   *   <li>Create new character
   *   <li>Load a character
   *   <li>
   *   <li>Settings, including keybindings
   *   <li>Quit
   * </ul>
   */
  private void menuSelectionSequence() {

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    Input.poll();
    mouseEvents = Input.getMouseEvents();

    for (GLUIComponent b : menuSelectionButtons) {

      b.processMouseEvents(mouseEvents);
      b.update(0);
      b.renderGL();
    }

    try {
      menuTheme
          .getFont()
          .glDrawText(
              "\\c#FFFFFFUniQuest",
              (Main.SCREEN_WIDTH - menuTheme.getFont().getStringWidth("UniQuest")) / 2 + 2,
              50);
    } catch (InvalidEscapeSequenceException e) {
      e.printStackTrace();
    }

    Display.update();

    if (Display.isCloseRequested()) {
      Game.GAME_STATE = Game.GAME_STATE_QUIT;
      menu = false;
    }
  }
Exemple #13
0
  private void mainLoop() {
    long startTime = 0L;
    long endTime = 0L;
    long deltaTime = 0L;
    while (!Display.isCloseRequested()) {
      startTime = System.currentTimeMillis();
      // Run the physics simulation
      if (useOpenCL) {
        clPhysics.doPhysics(particleCount, deltaTime);
        // Render
        Renderer.render(clPhysics.getCurrentPosBuffer(), particleCount);
      } else {
        normalPhysics.doPhysics(particles, boxWidth, boxHeight, deltaTime);
        // Render
        Renderer.render(particles);
      }

      // Update the display
      Display.update();

      endTime = System.currentTimeMillis();
      deltaTime = endTime - startTime;
      System.out.println(deltaTime);
    }
  }
  public static void init() {

    WorldShapes.init();
    ImageLibrary.init();

    worldOne = new World();

    // Setting up arbitrary testing entities
    for (int i = -10; i < 10; i++) {
      for (int j = -10; j < 10; j++) {
        Entity e = new Entity(i * 10, j * 10, 5, ImageLibrary.randomImage());
        e.getParticle()
            .setVelocityVector(
                new Complex(Calculation.rand(-0.1f, 0.1f), Calculation.rand(-0.1f, 0.1f)));
        e.getParticle().setAngularVelocity(Calculation.rand(-1, 1));
        e.getParticle().setAngularVelocity(Calculation.rand(-100, 100));
        worldOne.Entity_HashMap.put(Calculation.rand(0, 1000) + "", e);
      }
    }

    worldOne.Entity_HashMap.put("player", new Entity(12, 12, 12, ImageLibrary.get("smile")));
    mainCamera =
        new POV(
            worldOne.Entity_HashMap.get("player").getParticle().getPositionVector(),
            Display.getWidth(),
            Display.getHeight(),
            0,
            5,
            worldOne);
  }
Exemple #15
0
  private void init(boolean absolutePixels, boolean testModes) {
    // find out what the current bits per pixel of the desktop is
    int currentBpp = Display.getDisplayMode().getBitsPerPixel();

    try {
      DisplayMode mode;
      if (testModes) mode = findDisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT, currentBpp);
      else mode = new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT);

      Display.setDisplayMode(mode);
      Display.setFullscreen(false);
      Display.setTitle("src");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    double aspectRatio = (double) WINDOW_WIDTH / WINDOW_HEIGHT;

    if (absolutePixels) {
      glOrtho(0.0d, WINDOW_WIDTH, 0.0d, WINDOW_HEIGHT, 1.0d, -1.0d);
    } else {
      glOrtho(aspectRatio, -aspectRatio, -1.0d, 1.0d, 1.0d, -1.0d);
    }

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
  }
Exemple #16
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();
  }
 public void render(ShaderHandler sh, DisplaySetup d, DataUtils util) {
   for (int i = 0; i < size(); i++) {
     pellet.changePos(get(i).getPos().x - currentpos.x, get(i).getPos().y - currentpos.y);
     pellet.changeTexture(get(i).getTexid());
     if (get(i).getAnimationWait() > 3) {
       if (get(i).getTexid() < 11) {
         get(i).changeTexid(1);
       } else {
         get(i).setTexid(0);
       }
       get(i).resetWait();
     } else {
       get(i).animationWait();
     }
     currentpos = new Vector2f(get(i).getPos().x, get(i).getPos().y);
     pellet.render(sh, util, 0);
     if (get(i)
         .contains(
             player.getPos(),
             (float) player.getWidth() / Display.getWidth(),
             (float) player.getHeight() / Display.getHeight(),
             d)) {
       parent.score(get(i).getScore());
       remove(i);
     }
   }
 }
Exemple #18
0
  /*
   * Called when the application is alt-tabbed to or from
   */
  private void appActivate(boolean active) {
    if (inAppActivate) {
      return;
    }
    inAppActivate = true;
    isFocused = active;
    if (active) {
      if (Display.isFullscreen()) {
        restoreDisplayMode();
      }
      if (parent == null) {
        setForegroundWindow(getHwnd());
      }
      setFocus(getHwnd());
      redoMakeContextCurrent = true;
      if (Display.isFullscreen()) updateClipping();

      if (keyboard != null) keyboard.fireLostKeyEvents();
    } else if (Display.isFullscreen()) {
      showWindow(getHwnd(), SW_SHOWMINNOACTIVE);
      resetDisplayMode();
    } else updateClipping();
    updateCursor();
    inAppActivate = false;
  }
Exemple #19
0
  private void initialise() {
    DisplayMode mode = new DisplayMode(WIDTH, HEIGHT);
    Display.setTitle(TITLE);

    input = new InputHandler();
    display = new CodeDisplay(input);

    try {
      Display.setDisplayMode(mode);
      Display.setResizable(false);
      Display.create();

      if (!GLContext.getCapabilities().OpenGL33)
        System.err.printf("You must have at least OpenGL 3.3 to run this program\n");
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(-1);
    }

    // Set clear color

    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL); // Less than or equal
    glClearDepth(1.0);

    establishProjectionMatrix();

    // glEnable(GL_LIGHTING);
    // glEnable(GL_LIGHT0);
  }
Exemple #20
0
  private void run() {

    int frames = 0;
    double nsPerFrame = 1000000000.0 / 60.0;
    double unProcessed = 0;
    long lastFrameTime = System.nanoTime();
    long currentFrameTime = System.currentTimeMillis();

    while (running) {
      long now = System.nanoTime();
      unProcessed += (now - lastFrameTime) / nsPerFrame;
      lastFrameTime = now;

      if (Display.isCloseRequested()) running = false;

      while (unProcessed > 1) {
        unProcessed -= 1;
        tick();
        display.render();
      }

      frames++;

      if (System.currentTimeMillis() - currentFrameTime > 1000) {
        currentFrameTime += 1000;
        // Print.line(frames + " fps");
        Display.setTitle(frames + " fps");
        frames = 0;
      }
      Display.sync(60);
      Display.update();
    }

    Display.destroy();
  }
  /**
   * Create the native window peer from the given mode and fullscreen flag. A native context must
   * exist, and it will be attached to the window.
   */
  private static void createWindow() throws LWJGLException {
    if (window_created) {
      return;
    }
    Canvas tmp_parent = isFullscreen() ? null : parent;
    if (tmp_parent != null
        && !tmp_parent
            .isDisplayable()) // Only a best effort check, since the parent can turn undisplayable
                              // hereafter
    throw new LWJGLException("Parent.isDisplayable() must be true");
    if (tmp_parent != null) {
      tmp_parent.addComponentListener(component_listener);
    }
    DisplayMode mode = getEffectiveMode();
    display_impl.createWindow(drawable, mode, tmp_parent, getWindowX(), getWindowY());
    window_created = true;

    width = Display.getDisplayMode().getWidth();
    height = Display.getDisplayMode().getHeight();

    setTitle(title);
    initControls();

    // set cached window icon if exists
    if (cached_icons != null) {
      setIcon(cached_icons);
    } else {
      setIcon(new ByteBuffer[] {LWJGLUtil.LWJGLIcon32x32, LWJGLUtil.LWJGLIcon16x16});
    }
  }
 /* (non-Javadoc)
  * @see chu.engine.Game#loop()
  */
 @Override
 public void loop() {
   while (!Display.isCloseRequested()) {
     final long time = System.nanoTime();
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     glClearDepth(1.0f);
     getInput();
     final ArrayList<Message> messages = new ArrayList<>();
     if (client != null) {
       synchronized (client.messagesLock) {
         messages.addAll(client.messages);
         for (Message m : messages) client.messages.remove(m);
       }
     }
     SoundStore.get().poll(0);
     glPushMatrix();
     // Global resolution scale
     //			Renderer.scale(scaleX, scaleY);
     currentStage.beginStep(messages);
     currentStage.onStep();
     currentStage.processAddStack();
     currentStage.processRemoveStack();
     currentStage.render();
     //				FEResources.getBitmapFont("stat_numbers").render(
     //						(int)(1.0f/getDeltaSeconds())+"", 440f, 0f, 0f);
     currentStage.endStep();
     glPopMatrix();
     Display.update();
     timeDelta = System.nanoTime() - time;
   }
   AL.destroy();
   Display.destroy();
   if (client != null && client.isOpen()) client.quit();
 }
Exemple #23
0
  public Enemy(
      Vector2f pos,
      int texid,
      Controller parent,
      EnemyPath ep,
      Sprite player,
      ArrayList<EnemyBullet> playerbullets,
      String texloc,
      int lowesttexid,
      int highesttexid,
      int width,
      int pattern) {
    this.width = width / Display.getWidth();
    this.playerbullets = playerbullets;
    this.parent = parent;
    this.pattern = pattern;
    this.lti = lowesttexid;
    this.hti = highesttexid;
    this.pos =
        new Vector2f(((pos.x / Display.getWidth())), ((pos.y) / (Display.getHeight() / 2.0f)));
    this.playersprite = player;
    this.ep = ep;
    this.texid = texid;
    this.player = new Rectangle2D.Float();
    this.myrect = new Rectangle2D.Float();

    ImageReturn images = new ImageReturn();
    GridParser gp = new GridParser();
    TextureHolder texture;

    try {
      texture = gp.parseGrid(images.getImage("explosion.png"), 30);
      this.explosion =
          new Sprite(
              images.getImage("explosion.png"),
              parent,
              70,
              70,
              texture,
              0,
              new Vector2f(0.0f, 0.0f));
      texture = gp.parseGrid(images.getImage("bullets2.png"), 20);
      this.bullet =
          new Sprite(
              images.getImage("bullets2.png"),
              parent,
              40,
              40,
              texture,
              0,
              new Vector2f(0.0f, 0.0f));
      texture = gp.parseGrid(images.getImage(texloc), 50);
      me = new Sprite(images.getImage(texloc), parent, 100, 100, texture, 0, this.pos);
    } catch (IOException e) {
      System.err.println("err at enemy");
      System.exit(1);
      e.printStackTrace();
    }
  }
Exemple #24
0
  /** Enters the Main-Loop */
  private void beginLoop() {
    this.isRunning = true;

    this.timing.init();
    while (this.isRunning) {
      int delta = this.timing.getDelta();

      this.handleDisplayResize();
      if (Display.isCloseRequested()) this.isRunning = false;

      // Mouse updates
      this.profiler.start("Mouse updates");
      this.mouseX = Mouse.getX();
      this.mouseY = this.height - Mouse.getY();

      if (!this.isGamePaused) {
        this.input.mousePos(this.mouseX, this.mouseY);
        if (Mouse.isButtonDown(0) && !this.lastButtonState)
          this.input.mouseClick(this.mouseX, this.mouseY);
        this.lastButtonState = Mouse.isButtonDown(0);
      }

      // Scrolling
      if (!this.isGamePaused) {
        int scroll = Mouse.getDWheel();
        if (scroll > 0) this.camera.zoom(-1);
        else if (scroll < 0) this.camera.zoom(1);
      }

      // Keyboard updates
      this.profiler.endStart("Keyboard updates");
      this.keyboardListener.update();

      // Audio
      this.profiler.endStart("Audio updates");
      this.soundEngine.update(delta);

      // Rendering
      this.profiler.endStart("Render game");
      this.camera.update(delta);
      this.renderer.render(this.camera, this.logic.getGameState(), delta);
      this.profiler.endStart("Render GUI");
      this.guiRenderer.render(this.width, this.height, this.mouseX, this.mouseY);
      this.profiler.end();

      Display.update();
      Display.sync(60);

      int error = glGetError();
      if (error != GL_NO_ERROR)
        System.out.println("GLError " + error + ": " + GLU.gluErrorString(error));

      this.timing.updateFPS();
    }

    this.soundEngine.dispose();
    Settings.saveSettings(this.settings);
    if (Display.isCreated()) Display.destroy();
  }
 private void loop() {
   while (!Display.isCloseRequested()) {
     run();
     updateFPS();
     Display.update();
     Display.sync(60);
   }
 }
Exemple #26
0
 public void run() {
   while (!Display.isCloseRequested()) {
     GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
     gui.update();
     Display.update();
     TestUtils.reduceInputLag();
   }
 }
Exemple #27
0
 /**
  * Paints a character against the map for rendering
  *
  * @param g - Graphics component that'll draw the map to the display
  * @param cam - Camera of where to center the map at
  * @param c - Character to draw on the map
  */
 public void paintCharacter(Graphics g, Camera cam, MapCharacter c) {
   // TODO add culling so characters outside of camera bounds are not drawn
   Image sprite = c.sprite;
   int w = c.sprite.getWidth() / 2;
   int h = c.sprite.getHeight();
   g.drawImage(
       c.sprite, (c.x - cam.x) + Display.getWidth() / 2, (c.y - cam.y) + Display.getHeight() / 2);
 }
Exemple #28
0
 public static void isSlotHover(int x, int y, int i, int j, int k) {
   if (Mideas.mouseX() >= Display.getWidth() / 2 + x
       && Mideas.mouseX() <= Display.getWidth() / 2 + x + 42
       && Mideas.mouseY() >= Display.getHeight() / 2 + y + i
       && Mideas.mouseY() <= Display.getHeight() / 2 + y + j) {
     slot_hover[k] = true;
   }
 }
Exemple #29
0
 public static void main(String[] args) throws Exception {
   Display.setTitle("TWL Examples");
   Display.setDisplayMode(new DisplayMode(800, 600));
   Display.setVSyncEnabled(true);
   Display.create();
   TwlTest twlTest = new TwlTest();
   twlTest.run();
 }
Exemple #30
0
  public Game(boolean host) {
    try {
      if (host) {
        System.out.println("Hosting...");
        server = new ServerSocket(port, 4, InetAddress.getByName(serverIP));
        System.out.println("Ready!\nAwaiting client...");
        client = server.accept();
        System.out.println("Client connected!\nBuffering...");
        out = new ObjectOutputStream(client.getOutputStream());
        in = new ObjectInputStream(client.getInputStream());
        System.out.println("Buffered!\nPinging for 256 bytes...");
        long start = System.currentTimeMillis();
        byte[] ping = new byte[256];
        in.read(ping);
        System.out.println("Latency: " + (System.currentTimeMillis() - start));
        out.writeLong(start);
        out.flush();
        System.out.println("Starting threads...");
        new ThreadSend(world, out);
        new ThreadReceive(world, in);
        System.out.println("Started!\nCreating game world...");
      } else {
        System.out.println("Connecting...");
        socket = new Socket(connectIP, port);
        System.out.println("Connected!\nBuffering...");
        in = new ObjectInputStream(socket.getInputStream());
        out = new ObjectOutputStream(socket.getOutputStream());
        byte[] ping = new byte[256];
        new Random().nextBytes(ping);
        System.out.println("Buffered\nPinging for 256 bytes...");
        out.write(ping);
        out.flush();
        long latency = in.readLong();
        System.out.println("Latency: " + (System.currentTimeMillis() - latency));
        System.out.println("Starting threads...");
        new ThreadReceive(world, in);
        new ThreadSend(world, out);
        System.out.println("Started!\nCreating game world...");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    try {
      Display.setDisplayMode(new DisplayMode(width, height));
      Display.create();
    } catch (Exception e) {
      e.printStackTrace();
    }

    world.init();

    while (!Display.isCloseRequested()) {
      if (ended) break;
      world.update();
    }

    Display.destroy();
  }