Beispiel #1
0
 public void isEscapePressed() {
   while (Keyboard.next()) {
     if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
       shutdown = true;
     }
   }
 }
 private void keyboardHandler() {
   while (Keyboard.next()) {
     if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {
       openConsole();
     }
   }
 }
  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
  }
  @Override
  protected void update() {
    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {
        switch (Keyboard.getEventKey()) {
          case Keyboard.KEY_S:
            useFakeHallway = !useFakeHallway;
            if (useFakeHallway) {
              System.out.printf("Fake Hallway.\n");
            } else {
              System.out.printf("Real Hallway.\n");
            }
            break;

          case Keyboard.KEY_P:
            useSmoothInterpolation = !useSmoothInterpolation;
            if (useSmoothInterpolation) {
              System.out.printf("Perspective correct interpolation.\n");
            } else {
              System.out.printf("Just linear interpolation.\n");
            }
            break;

          case Keyboard.KEY_ESCAPE:
            leaveMainLoop();
            break;
        }
      }
    }
  }
Beispiel #5
0
  /** Game loop update */
  public void update() {
    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {
        if (Keyboard.getEventKey() == Keyboard.KEY_Q) {
          // play as a one off sound effect
          oggEffect.playAsSoundEffect(1.0f, 1.0f, false);
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_W) {
          // replace the music thats curretly playing with
          // the ogg
          oggStream.playAsMusic(1.0f, 1.0f, true);
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_E) {
          // replace the music thats curretly playing with
          // the mod
          modStream.playAsMusic(1.0f, 1.0f, true);
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_R) {
          // play as a one off sound effect
          aifEffect.playAsSoundEffect(1.0f, 1.0f, false);
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_T) {
          // play as a one off sound effect
          wavEffect.playAsSoundEffect(1.0f, 1.0f, false);
        }
      }
    }

    // polling is required to allow streaming to get a chance to
    // queue buffers.
    SoundStore.get().poll(0);
  }
  public static void gameOver() {

    gameStatus = 9;
    while (Keyboard.next()) {}

    changedGameStatus = true;
  }
Beispiel #7
0
  /** Called each tick so GUIs can handle their input. */
  @Override
  public void handleInput() throws IOException {
    if (Mouse.isCreated()) {
      while (Mouse.next()) {
        if (!MinecraftForge.EVENT_BUS.post(
            new net.minecraftforge.client.event.GuiScreenEvent.MouseInputEvent.Pre(this))) {
          this.handleMouseInput();
          if (this.equals(this.mc.currentScreen)) {
            MinecraftForge.EVENT_BUS.post(
                new net.minecraftforge.client.event.GuiScreenEvent.MouseInputEvent.Post(this));
          }
        }
      }
    }

    if (Keyboard.isCreated()) {
      while (Keyboard.next()) {
        if (!MinecraftForge.EVENT_BUS.post(
            new net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent.Pre(this))) {
          this.handleKeyboardInput();
          if (this.equals(this.mc.currentScreen)) {
            MinecraftForge.EVENT_BUS.post(
                new net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent.Post(this));
          }
        }
      }
    }
  }
Beispiel #8
0
  private void handleKeyboardInputs() {

    // Kedboard.poll() checks for keyboard input, buffered
    Keyboard.poll();

    while (Keyboard.next()) {
      // only consider KeyDown Events
      if (!Keyboard.getEventKeyState()) {
        continue;
      }
      switch (Keyboard.getEventKey()) {
        case Keyboard.KEY_ESCAPE:
          running = false;
          break;
        case Keyboard.KEY_S:
          gameView.drawSightRange = !gameView.drawSightRange;
          break;
        case Keyboard.KEY_M:
          gameView.drawMessages = !gameView.drawMessages;
          break;
        case Keyboard.KEY_PERIOD:
          ticksPerSecond *= 1.3;
          resetReferenceValues();
          break;
        case Keyboard.KEY_COMMA:
          ticksPerSecond /= 1.3;
          resetReferenceValues();
          break;
        case Keyboard.KEY_P:
          paused = !paused;
          break;
      }
    }
  }
Beispiel #9
0
 private void doKeys() {
   while (Keyboard.next()) {
     char eventChar = Keyboard.getEventCharacter();
     int eventKey = Keyboard.getEventKey();
     long eventTick = Keyboard.getEventNanoseconds();
     boolean eventState = Keyboard.getEventKeyState();
     // System.out.println("doKeys("+eventKey+")");
     if (eventKey == Keyboard.KEY_LSHIFT) {
       if (eventState) {
         mModifiers |= KeyEvent.VK_SHIFT;
       } else {
         mModifiers &= ~KeyEvent.VK_SHIFT;
       }
     } else if (eventKey == Keyboard.KEY_RSHIFT) {
       if (eventState) {
         mModifiers |= KeyEvent.VK_SHIFT;
       } else {
         mModifiers &= ~KeyEvent.VK_SHIFT;
       }
     } else if (eventKey == Keyboard.KEY_LCONTROL) {
       if (eventState) {
         mModifiers |= KeyEvent.VK_CONTROL;
       } else {
         mModifiers &= ~KeyEvent.VK_CONTROL;
       }
     } else if (eventKey == Keyboard.KEY_RCONTROL) {
       if (eventState) {
         mModifiers |= KeyEvent.VK_CONTROL;
       } else {
         mModifiers &= ~KeyEvent.VK_CONTROL;
       }
     } else if (eventKey == Keyboard.KEY_LMENU) {
       if (eventState) {
         mModifiers |= KeyEvent.VK_ALT;
       } else {
         mModifiers &= ~KeyEvent.VK_ALT;
       }
     } else if (eventKey == Keyboard.KEY_RMENU) {
       if (eventState) {
         mModifiers |= KeyEvent.VK_ALT;
       } else {
         mModifiers &= ~KeyEvent.VK_ALT;
       }
     }
     if (KEY_LWJGL_TO_AWT.containsKey(eventKey)) {
       eventKey = KEY_LWJGL_TO_AWT.get(eventKey);
     }
     KeyEvent e =
         new KeyEvent(
             this,
             eventState ? KeyEvent.KEY_PRESSED : KeyEvent.KEY_RELEASED,
             eventTick,
             mModifiers,
             eventKey,
             eventChar);
     fireKeyEvent(e);
   }
 }
Beispiel #10
0
  public void func_564_d() {
    while (Mouse.next()) {
      this.func_566_e();
    }

    while (Keyboard.next()) {
      this.func_569_f();
    }
  }
  /**
   * *************************************************************************************************************************************************************************************************
   * Checks if key is pressed or mouse is moved etc.
   * ************************************************************************************************************************************************************************************************
   */
  private void checkInput() {

    if (Keyboard.next() && Keyboard.getEventKeyState()) {
      if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) closeRequested = true;
    }

    if (Display.isCloseRequested()) {
      closeRequested = true;
    }
  }
Beispiel #12
0
  public static void loop() {

    while (CSGame.state == States.ThreeDeeTest) {
      // Clear the screen of its filthy contents
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      // Push the screen inwards at the amount of speed
      glTranslatef(0, 0, speed);

      // Begin drawing points
      glBegin(GL_POINTS);
      // Iterate of every point

      for (Point p : points) {
        // Draw the point at its coordinates
        glColor3f(0.0f, 1f, 0f);
        glVertex3f(p.x, p.y, p.z);
      }
      // Stop drawing points
      glEnd();

      // If we're pressing the "up" key increase our speed
      if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
        speed += 0.01f;
      }
      // If we're pressing the "down" key decrease our speed
      if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
        speed -= 0.01f;
      }
      // Iterate over keyboard input events
      while (Keyboard.next()) {
        // If we're pressing the "space-bar" key reset our speed to zero
        if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
          speed = 0f;
        }
        // If we're pressing the "c" key reset our speed to zero and reset our position
        if (Keyboard.isKeyDown(Keyboard.KEY_C)) {
          speed = 0;
          glLoadIdentity();
        }
      }

      if (Display.isCloseRequested()) {
        CSGame.state = States.Closing;
        break;
      }

      Debug.debugLoop();
      // Update the display
      Display.update();
      // Wait until the frame-rate is 60fps
      Display.sync(60);
    }
  }
 /*     */ protected synchronized boolean getNextDeviceEvent(Event event) throws IOException {
   /*  86 */ if (!org.lwjgl.input.Keyboard.isCreated()) /*  87 */ return false;
   /*  88 */ if (!org.lwjgl.input.Keyboard.next()) /*  89 */ return false;
   /*  90 */ int lwjgl_key = org.lwjgl.input.Keyboard.getEventKey();
   /*  91 */ if (lwjgl_key == 0) /*  92 */ return false;
   /*  93 */ Component.Identifier.Key key_id = KeyMap.map(lwjgl_key);
   /*  94 */ if (key_id == null) /*  95 */ return false;
   /*  96 */ Component key = getComponent(key_id);
   /*  97 */ if (key == null) /*  98 */ return false;
   /*  99 */ float value = org.lwjgl.input.Keyboard.getEventKeyState() ? 1.0F : 0.0F;
   /* 100 */ event.set(key, value, org.lwjgl.input.Keyboard.getEventNanoseconds());
   /* 101 */ return true;
   /*     */ }
  public void pollKeyboard() {
    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {

        switch (Keyboard.getEventKey()) {
            // Quit the game
          case Keyboard.KEY_ESCAPE:
            System.exit(0);
            break;
        }
      }
    }
  }
 private static void checkInput() {
   timer.update();
   camera.processMouse(1, 80, -80);
   camera.processKeyboard(16, 1, 1, 1);
   if (Mouse.isButtonDown(0)) Mouse.setGrabbed(true);
   else if (Mouse.isButtonDown(1)) Mouse.setGrabbed(false);
   while (Keyboard.next()) {
     if (Keyboard.isKeyDown(Keyboard.KEY_P)) {
       currentShaderProgram = perPixelShaderProgram;
     } else if (Keyboard.isKeyDown(Keyboard.KEY_V)) {
       currentShaderProgram = perVertexShaderProgram;
     }
   }
 }
  private void checkInput() {
    if (Mouse.isButtonDown(0)) {
      leftHold(Mouse.getX(), Mouse.getY());
    }
    while (Mouse.next()) {
      if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) {
        leftClick(Mouse.getX(), Mouse.getY());
      }

      if (Mouse.getEventButtonState() && Mouse.getEventButton() == 1) {
        rightClick();
      }
    }
    while (Keyboard.next()) {
      if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
        System.exit(0);
      }

      if (Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
        if (drawVector) {
          drawVector = false;
        } else {
          drawVector = true;
        }
      }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
      if (vecSlider.y < 85) {
        vecSlider.y++;
      }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
      if (vecSlider.x > -90) {
        vecSlider.x--;
      }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
      if (vecSlider.y > -85) {
        vecSlider.y--;
      }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
      if (vecSlider.x < 85) {
        vecSlider.x++;
      }
    }
  }
 private void refreshKeyboard() {
   while (Keyboard.next()) {
     int key = Keyboard.getEventKey();
     boolean keyState = Keyboard.getEventKeyState();
     String keyname = Keyboard.getKeyName(key);
     if (keyState) {
       char c = Keyboard.getEventCharacter();
       for (InputListener listener : listeners) {
         if (listener.onKeyDown(key, keyname, c)) break;
       }
     } else {
       for (InputListener listener : listeners) {
         if (listener.onKeyUp(key, keyname)) break;
       }
     }
   }
 }
  public void pollInput(Player player) {
    if (org.lwjgl.input.Keyboard.isCreated()) {
      while (org.lwjgl.input.Keyboard.next()) {
        Keyboard key = Keyboard.get(org.lwjgl.input.Keyboard.getEventKey());
        if (key != null) {
          onKeyPressed(
              player,
              key,
              org.lwjgl.input.Keyboard.getEventKeyState(),
              org.lwjgl.input.Keyboard.getEventCharacter());
        }
      }
    }

    // Handle mouse
    if (org.lwjgl.input.Mouse.isCreated()) {
      int x, y;
      while (org.lwjgl.input.Mouse.next()) {

        // Calculate dx/dy since last event polling
        x = org.lwjgl.input.Mouse.getEventX();
        y = org.lwjgl.input.Mouse.getEventY();

        Mouse button = Mouse.get(org.lwjgl.input.Mouse.getEventButton());
        if (button != null) {
          onMouseClicked(player, button, org.lwjgl.input.Mouse.getEventButtonState(), x, y);
          continue;
        }

        // Handle scrolls
        int scroll = org.lwjgl.input.Mouse.getEventDWheel();
        if (scroll < 0) {
          onMouseClicked(player, Mouse.MOUSE_SCROLLUP, true, x, y);
        } else if (scroll > 0) {
          onMouseClicked(player, Mouse.MOUSE_SCROLLDOWN, true, x, y);
        }

        onMouseMove(
            player,
            org.lwjgl.input.Mouse.getEventDX(),
            org.lwjgl.input.Mouse.getEventDY(),
            org.lwjgl.input.Mouse.getEventX(),
            org.lwjgl.input.Mouse.getEventY());
      }
    }
  }
Beispiel #19
0
 @Override
 protected void input() {
   while (Keyboard.next()) {
     if (Keyboard.getEventKeyState()) {
       if (Keyboard.getEventKey() == Keyboard.KEY_F1) {
         font = (font + 1) % fonts.length;
       } else if (Keyboard.getEventKey() == Keyboard.KEY_BACK && text.length() > 1) {
         text.deleteCharAt(text.length() - 2);
       } else if (Keyboard.getEventKey() == Keyboard.KEY_RETURN) {
         text.insert(text.length() - 1, '\n');
       } else if (activeFont()
           .getAvailableChars()
           .contains(Character.toLowerCase(Keyboard.getEventCharacter()))) {
         text.insert(text.length() - 1, Keyboard.getEventCharacter());
       }
     }
   }
 }
Beispiel #20
0
 public static void update() {
   pressed.clear();
   released.clear();
   while (Keyboard.next()) {
     Integer key = Keyboard.getEventKey();
     if (Keyboard.getEventKeyState()) {
       down.add(key);
       pressed.add(key);
       time.put(key, 0);
     } else {
       down.remove(key);
       released.add(key);
     }
   }
   for (Integer i : down) {
     time.put(i, time.get(i) + 1);
   }
 }
  @Override
  public void draw() {
    GL11.glClearColor(0.8f, 0.8f, 0.8f, 0.0f);

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

    GL11.glLoadIdentity();
    GLU.gluLookAt(5.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    GL11.glRotatef(rot, 0.0f, 1.0f, 0.0f);
    GL11.glRotatef(rot2, 1.0f, 0.0f, 0.0f);
    drawer.draw();

    Keyboard.poll();

    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {
        if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
          return;
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_RIGHT) {
          rot -= 15.0f;
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_LEFT) {
          rot += 15.0f;
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_UP) {
          rot2 -= 15.0f;
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_DOWN) {
          rot2 += 15.0f;
        }

        if (Keyboard.getEventKey() == Keyboard.KEY_T) {
          if (renderMode == GL11.GL_POLYGON) {
            renderMode = GL11.GL_LINE_LOOP;
          } else {
            renderMode = GL11.GL_POLYGON;
          }
        }
      }
    }
  }
Beispiel #22
0
  @Override
  protected void update() {
    while (Mouse.next()) {
      int eventButton = Mouse.getEventButton();

      if (eventButton != -1) {
        boolean pressed = Mouse.getEventButtonState();
        MousePole.forwardMouseButton(viewPole, eventButton, pressed, Mouse.getX(), Mouse.getY());
        MousePole.forwardMouseButton(objtPole, eventButton, pressed, Mouse.getX(), Mouse.getY());
      } else {
        // Mouse moving or mouse scrolling
        int dWheel = Mouse.getDWheel();

        if (dWheel != 0) {
          MousePole.forwardMouseWheel(viewPole, dWheel, dWheel, Mouse.getX(), Mouse.getY());
          MousePole.forwardMouseWheel(objtPole, dWheel, dWheel, Mouse.getX(), Mouse.getY());
        }

        if (Mouse.isButtonDown(0) || Mouse.isButtonDown(1) || Mouse.isButtonDown(2)) {
          MousePole.forwardMouseMotion(viewPole, Mouse.getX(), Mouse.getY());
          MousePole.forwardMouseMotion(objtPole, Mouse.getX(), Mouse.getY());
        }
      }
    }

    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {
        switch (Keyboard.getEventKey()) {
          case Keyboard.KEY_SPACE:
            drawColoredCyl = !drawColoredCyl;
            break;

          case Keyboard.KEY_ESCAPE:
            leaveMainLoop();
            break;
        }
      }
    }
  }
Beispiel #23
0
  @Override
  public void update(Engine engine, double time, double dt) {
    Window window = engine.getGlobal(Window.class);
    window.closing = Display.isCloseRequested();
    if (Display.wasResized()) {
      window.width = Display.getWidth();
      window.height = Display.getHeight();
    }

    KeyboardComponent keyboard = engine.getGlobal(KeyboardComponent.class);
    Keyboard.poll();
    for (int i = 0; i < keyboard.down.length; i++) {
      keyboard.pressed[i] = false;
      keyboard.released[i] = false;
      keyboard.down[i] = Keyboard.isKeyDown(i);
    }
    while (Keyboard.next()) {
      int key = Keyboard.getEventKey();
      keyboard.pressed[key] = Keyboard.getEventKeyState();
      keyboard.released[key] = !keyboard.pressed[key];
    }

    MouseComponent mouse = engine.getGlobal(MouseComponent.class);
    Mouse.poll();
    for (int i = 0; i < Mouse.getButtonCount(); i++) {
      mouse.pressed[i] = false;
      mouse.pressed[i] = false;
      mouse.down[i] = Mouse.isButtonDown(i);
      mouse.dx = 0;
      mouse.dy = 0;
    }
    while (Mouse.next()) {
      int btn = Mouse.getEventButton();
      if (btn != -1) {
        mouse.pressed[btn] = Mouse.getEventButtonState();
        mouse.released[btn] = !mouse.pressed[btn];
      } else {
        mouse.dx += Mouse.getEventDX();
        mouse.dy += Mouse.getEventDY();
      }
      mouse.x = Mouse.getEventX();
      mouse.y = Mouse.getEventY();
    }
    mouse.nx = ((float) mouse.x / (float) window.width) * 2.0f - 1.0f;
    mouse.ny = ((float) mouse.y / (float) window.height) * 2.0f - 1.0f;

    Vec3[] mp = MouseUtils.mouseToWorld(window, engine.getGlobal(Camera.class), mouse);

    mouse.near = mp[0];
    mouse.far = mp[1];

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    for (Map m : objects.values()) {
      m.clear();
    }

    // calculate the world matrix of each renderable,
    // and add them to their respective "shader buckets"
    for (RenderNode node : engine.getNodeList(RenderNode.class)) {
      ID<Entity> id = node.getEntity().getId();
      worlds.put(id, StateUtils.getMatrix(node.state));

      Program program = resourceManager.getProgram(node.renderable.shader);
      Map<ID<Entity>, RenderNode> renderables = objects.get(program);
      if (renderables == null) {
        renderables = new HashMap<>();
        objects.put(program, renderables);
      }
      renderables.put(id, node);
    }

    for (ViewportNode vpnode : engine.getNodeList(ViewportNode.class)) {
      Camera camera = vpnode.camera;
      glViewport(
          (int) (window.width * vpnode.viewport.x),
          (int) (window.height * vpnode.viewport.y),
          (int) (window.width * vpnode.viewport.width),
          (int) (window.height * vpnode.viewport.height));

      // for each shader, draw each object that uses that shader
      for (Map.Entry<Program, Map<ID<Entity>, RenderNode>> e : objects.entrySet()) {
        Program program = e.getKey();
        program.use();
        program.setView(camera.viewMatrix);
        program.setProjection(camera.projection);
        program.setSun(engine.getGlobal(Sun.class).location);
        program.setEye(camera.eye);
        for (Map.Entry<ID<Entity>, RenderNode> e2 : e.getValue().entrySet()) {
          RenderNode node = e2.getValue();
          program.setWorld(worlds.get(e2.getKey()));
          program.setColour(node.renderable.colour);
          program.setOpacity(node.renderable.opacity);
          Mesh mesh = resourceManager.getMesh(node.mesh);
          mesh.draw();
        }
      }

      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      glDisable(GL_CULL_FACE);

      Program program = resourceManager.getProgram("passthrough");
      program.use();
      program.setView(camera.viewMatrix);
      program.setProjection(camera.projection);
      for (BBoxNode node : engine.getNodeList(BBoxNode.class)) {
        program.setWorld(node.bbox.getMatrix());

        Vec3 e = node.bbox.getExtents();

        glBegin(GL_QUADS);
        {
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), e.getY(), -e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), e.getY(), -e.getZ());

          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), -e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), -e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), -e.getY(), -e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), -e.getY(), -e.getZ());

          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), -e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), -e.getY(), -e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), e.getY(), -e.getZ());

          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), -e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), -e.getY(), -e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), e.getY(), -e.getZ());
        }
        glEnd();
      }
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      glEnable(GL_CULL_FACE);
    }

    Display.update();
  }
Beispiel #24
0
  /**
   * Poll the state of the input
   *
   * @param width The width of the game view
   * @param height The height of the game view
   */
  public void poll(int width, int height) {
    if (paused) {
      clearControlPressedRecord();
      clearKeyPressedRecord();
      clearMousePressedRecord();

      while (Keyboard.next()) {}
      while (Mouse.next()) {}
      return;
    }

    if (!Display.isActive()) {
      clearControlPressedRecord();
      clearKeyPressedRecord();
      clearMousePressedRecord();
    }

    // add any listeners requested since last time
    for (int i = 0; i < keyListenersToAdd.size(); i++) {
      addKeyListenerImpl((KeyListener) keyListenersToAdd.get(i));
    }
    keyListenersToAdd.clear();
    for (int i = 0; i < mouseListenersToAdd.size(); i++) {
      addMouseListenerImpl((MouseListener) mouseListenersToAdd.get(i));
    }
    mouseListenersToAdd.clear();

    if (doubleClickTimeout != 0) {
      if (System.currentTimeMillis() > doubleClickTimeout) {
        doubleClickTimeout = 0;
      }
    }

    this.height = height;

    Iterator allStarts = allListeners.iterator();
    while (allStarts.hasNext()) {
      ControlledInputReciever listener = (ControlledInputReciever) allStarts.next();
      listener.inputStarted();
    }

    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {
        int eventKey = resolveEventKey(Keyboard.getEventKey(), Keyboard.getEventCharacter());

        keys[eventKey] = Keyboard.getEventCharacter();
        pressed[eventKey] = true;
        nextRepeat[eventKey] = System.currentTimeMillis() + keyRepeatInitial;

        consumed = false;
        for (int i = 0; i < keyListeners.size(); i++) {
          KeyListener listener = (KeyListener) keyListeners.get(i);

          if (listener.isAcceptingInput()) {
            listener.keyPressed(eventKey, Keyboard.getEventCharacter());
            if (consumed) {
              break;
            }
          }
        }
      } else {
        int eventKey = resolveEventKey(Keyboard.getEventKey(), Keyboard.getEventCharacter());
        nextRepeat[eventKey] = 0;

        consumed = false;
        for (int i = 0; i < keyListeners.size(); i++) {
          KeyListener listener = (KeyListener) keyListeners.get(i);
          if (listener.isAcceptingInput()) {
            listener.keyReleased(eventKey, keys[eventKey]);
            if (consumed) {
              break;
            }
          }
        }
      }
    }

    while (Mouse.next()) {
      if (Mouse.getEventButton() >= 0 && Mouse.getEventButton() < mousePressed.length) {
        if (Mouse.getEventButtonState()) {
          consumed = false;
          mousePressed[Mouse.getEventButton()] = true;

          pressedX = (int) (xoffset + (Mouse.getEventX() * scaleX));
          pressedY = (int) (yoffset + ((height - Mouse.getEventY()) * scaleY));

          for (int i = 0; i < mouseListeners.size(); i++) {
            MouseListener listener = (MouseListener) mouseListeners.get(i);
            if (listener.isAcceptingInput()) {
              listener.mousePressed(Mouse.getEventButton(), pressedX, pressedY);
              if (consumed) {
                break;
              }
            }
          }
        } else {
          consumed = false;
          mousePressed[Mouse.getEventButton()] = false;

          int releasedX = (int) (xoffset + (Mouse.getEventX() * scaleX));
          int releasedY = (int) (yoffset + ((height - Mouse.getEventY()) * scaleY));
          if ((pressedX != -1)
              && (pressedY != -1)
              && (Math.abs(pressedX - releasedX) < mouseClickTolerance)
              && (Math.abs(pressedY - releasedY) < mouseClickTolerance)) {
            considerDoubleClick(Mouse.getEventButton(), releasedX, releasedY);
            pressedX = pressedY = -1;
          }

          for (int i = 0; i < mouseListeners.size(); i++) {
            MouseListener listener = (MouseListener) mouseListeners.get(i);
            if (listener.isAcceptingInput()) {
              listener.mouseReleased(Mouse.getEventButton(), releasedX, releasedY);
              if (consumed) {
                break;
              }
            }
          }
        }
      } else {
        if (Mouse.isGrabbed() && displayActive) {
          if ((Mouse.getEventDX() != 0) || (Mouse.getEventDY() != 0)) {
            consumed = false;
            for (int i = 0; i < mouseListeners.size(); i++) {
              MouseListener listener = (MouseListener) mouseListeners.get(i);
              if (listener.isAcceptingInput()) {
                if (anyMouseDown()) {
                  listener.mouseDragged(0, 0, Mouse.getEventDX(), -Mouse.getEventDY());
                } else {
                  listener.mouseMoved(0, 0, Mouse.getEventDX(), -Mouse.getEventDY());
                }

                if (consumed) {
                  break;
                }
              }
            }
          }
        }

        int dwheel = Mouse.getEventDWheel();
        wheel += dwheel;
        if (dwheel != 0) {
          consumed = false;
          for (int i = 0; i < mouseListeners.size(); i++) {
            MouseListener listener = (MouseListener) mouseListeners.get(i);
            if (listener.isAcceptingInput()) {
              listener.mouseWheelMoved(dwheel);
              if (consumed) {
                break;
              }
            }
          }
        }
      }
    }

    if (!displayActive || Mouse.isGrabbed()) {
      lastMouseX = getMouseX();
      lastMouseY = getMouseY();
    } else {
      if ((lastMouseX != getMouseX()) || (lastMouseY != getMouseY())) {
        consumed = false;
        for (int i = 0; i < mouseListeners.size(); i++) {
          MouseListener listener = (MouseListener) mouseListeners.get(i);
          if (listener.isAcceptingInput()) {
            if (anyMouseDown()) {
              listener.mouseDragged(lastMouseX, lastMouseY, getMouseX(), getMouseY());
            } else {
              listener.mouseMoved(lastMouseX, lastMouseY, getMouseX(), getMouseY());
            }
            if (consumed) {
              break;
            }
          }
        }
        lastMouseX = getMouseX();
        lastMouseY = getMouseY();
      }
    }

    if (controllersInited) {
      for (int i = 0; i < getControllerCount(); i++) {
        int count = ((Controller) controllers.get(i)).getButtonCount() + 3;
        count = Math.min(count, 24);
        for (int c = 0; c <= count; c++) {
          try {
            if (controls[i][c] && !isControlDwn(c, i)) {
              controls[i][c] = false;
              fireControlRelease(c, i);
            } else if (!controls[i][c] && isControlDwn(c, i)) {
              controllerPressed[i][c] = true;
              controls[i][c] = true;
              fireControlPress(c, i);
            }
          } catch (ArrayIndexOutOfBoundsException e) {
            break;
          }
        }
      }
    }

    if (keyRepeat) {
      for (int i = 0; i < 1024; i++) {
        if (pressed[i] && (nextRepeat[i] != 0)) {
          if (System.currentTimeMillis() > nextRepeat[i]) {
            nextRepeat[i] = System.currentTimeMillis() + keyRepeatInterval;
            consumed = false;
            for (int j = 0; j < keyListeners.size(); j++) {
              KeyListener listener = (KeyListener) keyListeners.get(j);

              if (listener.isAcceptingInput()) {
                listener.keyPressed(i, keys[i]);
                if (consumed) {
                  break;
                }
              }
            }
          }
        }
      }
    }

    Iterator all = allListeners.iterator();
    while (all.hasNext()) {
      ControlledInputReciever listener = (ControlledInputReciever) all.next();
      listener.inputEnded();
    }

    if (Display.isCreated()) {
      displayActive = Display.isActive();
    }
  }
  public void getInput() {
    if (gameStatus != -1) {
      float b = (float) (15f / Main.fps);
      switch (controlMode) {
        case 3:
          if (Keyboard.isKeyDown(Keyboard.KEY_DOWN) && !player.isBot) {
            if (player.y <= 100 * Main.ratio - player.amplitude * 2 - player.sy)
              player.playerYShift += b;
          }
        case 1:
          if (Keyboard.isKeyDown(Keyboard.KEY_LEFT) && !player.isBot) {
            if (player.freak >= player.minFreak) player.freak -= freakChanger;
          }
          if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT) && !player.isBot) {
            if (player.freak <= player.maxFreak) player.freak += freakChanger;
          }
          if (player2 != null) {
            if (Keyboard.isKeyDown(Keyboard.KEY_A) && !player2.isBot) {
              if (player2.freak >= player.minFreak) player2.freak -= freakChanger;
            }
            if (Keyboard.isKeyDown(Keyboard.KEY_D) && !player2.isBot) {
              if (player2.freak <= player.maxFreak) player2.freak += freakChanger;
            }
          }
          break;
        case 2:
          if (Keyboard.isKeyDown(Keyboard.KEY_SPACE) && !player.isBot) {
            if (player.freak <= player.maxFreak) player.freak += freakChanger;
          }

          if (Keyboard.isKeyDown(Keyboard.KEY_1)) {
            ListWorker.getList();
          }
          if (Keyboard.isKeyDown(Keyboard.KEY_M)) {
            gameConfiguration.mute = true;
            if (Draw.musicIsPlaying(Music.FON1)) Draw.musicStop(Music.FON1);
          }
          if (Keyboard.isKeyDown(Keyboard.KEY_N)) {
            gameConfiguration.mute = false;
            if (!Draw.musicIsPlaying(Music.FON1)) Draw.musicPlay(Music.FON1);
          }
          if (Keyboard.isKeyDown(Keyboard.KEY_0)) {
            mouseGrabbed = true;
          }
          if (Keyboard.isKeyDown(Keyboard.KEY_9)) {
            mouseGrabbed = false;
          }
          if (Keyboard.isKeyDown(Keyboard.KEY_P)) {
            pause = true;
          }
          if (Keyboard.isKeyDown(Keyboard.KEY_O)) {
            pause = false;
          }
          if (player2 != null) {
            if (Keyboard.isKeyDown(Keyboard.KEY_Q) && !player2.isBot) {
              if (player2.freak <= player2.maxFreak) player2.freak += freakChanger;
            }
          }
          break;
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_I)) {
        player.immortalityDie = 99999999;
        player.die = false;
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_O)) {
        player.immortalityDie = 0;
        player.die = false;
      }
      /*if (Keyboard.isKeyDown(Keyboard.KEY_3)) {
          if (gameStatus == 9)
              restartGame = true;
          gameStatus = 3;
          changedGameStatus = true;
          return;
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_1)) {
          if (gameStatus == 9)
              restartGame = true;
          gameStatus = 1;
          changedGameStatus = true;
          return;
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_2)) {
          if (gameStatus == 9)
              restartGame = true;
          gameStatus = 2;
          changedGameStatus = true;

          return;
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_0)) {
          if (gameStatus == 9)
              restartGame = true;
          gameStatus = 0;
          changedGameStatus = true;
          return;
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_4)) {
          if (gameStatus == 9)
              restartGame = true;
          gameStatus = 4;
          changedGameStatus = true;
          return;
      } */
    }
    lastKeyDownTime++;

    if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
      if (lastKeyDownTime > 10) {
        lastKeyDownTime = 0;
        changedGameStatus = true;
        if (gameStatus == 9) {
          restartGame = true;
          gameStatus = 0;
          changedGameStatus = true;
        } else {
          if (gameStatus == 2) {
            gameStatus = 1;
          } else {
            if (gameStatus == 1) {
              gameStatus = 2;
            } else {
              if (gameStatus == 0) {
                changedGameStatus = false;
              } else {
                gameStatus = 0;
              }
            }
          }
        }
      }
    }

    if (Mouse.isButtonDown(0)) {
      if (lastKeyDownTime > 10) {
        lastKeyDownTime = 0;
        switch (checkButtonIsOver()) {
          case 1:
            switch (gameStatus) {
              case (-1):
                gameStatus = 0;

                break;

              case 0:
                gameStatus = 2;
                changedGameStatus = true;
                Main.restartGame();

                break;
              case 1:
                gameStatus = 2;
                changedGameStatus = true;
                break;
              case 3:
                if (pg > 1) {
                  pg--;
                }
                //  getPreviousTopList();
                break;
              case 4:
                setMultiplayer();
                break;
              case 9:
                saveScore();
                gameStatus = 10;
                changedGameStatus = true;
                break;

              case 10:
                gameStatus = 2;

                Main.restartGame();
                break;
            }

            break;
          case 2:
            switch (gameStatus) {
              case 0:
                gameStatus = 3; // TOP SCORES
                changedGameStatus = true;
                break;
              case 1:
                gameStatus = 2;

                Main.restartGame();
                break;
              case 3:
                if (pg < maxPg) {
                  pg++;
                }
                //  getNextTopList();
                break;
              case 4:
                setBot();
                break;
              case 9:
                gameStatus = 10;

                break;

              case 10:
                gameStatus = 0;

                changedGameStatus = true;
                break;
            }
            changedGameStatus = true;
            break;
          case 3:
            switch (gameStatus) {
              case 0:
                gameStatus = 4; // Settings
                createNewConfiguration();
                changedGameStatus = true;
                break;
              case 1:
                gameStatus = 0;
                changedGameStatus = true;
                break;
              case 3:
                gameStatus = 0;
                changedGameStatus = true;
                break;
              case 4:
                setAudio();
                break;
            }

            break;
          case 4:
            switch (gameStatus) {
              case 0:
                exit();
                break;
              case 4:

                //   setPreviousMusicGenre();
                break;
            }
            break;
          case 5:
            if (gameStatus == 4)

              //  setNextMusicGenre();
              break;
          case 6:
            if (gameStatus == 4) gameStatus = 0;
            changedGameStatus = true;
            if (changedSettings == true) {
              changedSettings = false;
              saveConfiguration();
              gameConfigurationNew = null;
            }
            break;
          case 7:
            if (gameStatus == 4) gameStatus = 0;
            changedGameStatus = true;
            if (changedSettings == true) {
              changedSettings = false;
              gameConfigurationNew = null;
            }

            break;

          default:
            /*
            if (gameStatus == 9) {
                restartGame = true;
                gameStatus = 2;
                //changedGameStatus = true;

            }*/
            break;
        }
      }
    }

    if ((gameStatus == -1) || (gameStatus == 9)) {

      while (Keyboard.next()) {

        // System.out.println(playerName);

        char x = Keyboard.getEventCharacter();

        // if ((int)(x) == 42) {
        //     continue;
        //  }

        if ((int) (x) == 0) continue;

        if ((int) (x) == 32) continue;

        if ((int) (x) == 13) {
          gameStatus = 0;
          break;
        }

        if ((int) (x) == 8) {
          if (playerNamelenght > 0) {
            playerName.deleteCharAt(playerNamelenght - 1);
            playerNamelenght--;
          }
          continue;
        }

        // playerName = Keyboard.getKeyName(x);
        // playerNameChars[playerNamelenght] = Keyboard.get
        if (playerNamelenght < 15) {
          playerName.append(x);
          playerNamelenght++;
        }

        // System.out.println(playerName);

      }
    }
  }
Beispiel #26
0
  /**
   * Poll the state of the input
   *
   * @param width The width of the game view
   * @param height The height of the game view
   */
  public void poll(int width, int height) {
    if (paused) {
      while (Keyboard.next()) {}
      while (Mouse.next()) {}
      return;
    }

    this.height = height;

    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {
        int eventKey = resolveEventKey(Keyboard.getEventKey(), Keyboard.getEventCharacter());

        keys[eventKey] = Keyboard.getEventCharacter();
        pressed[eventKey] = true;
        nextRepeat[eventKey] = System.currentTimeMillis() + keyRepeatInitial;

        consumed = false;
        for (int i = 0; i < listeners.size(); i++) {
          InputListener listener = (InputListener) listeners.get(i);

          if (listener.isAcceptingInput()) {
            listener.keyPressed(eventKey, Keyboard.getEventCharacter());
            if (consumed) {
              break;
            }
          }
        }
      } else {
        int eventKey = resolveEventKey(Keyboard.getEventKey(), Keyboard.getEventCharacter());
        nextRepeat[eventKey] = 0;

        consumed = false;
        for (int i = 0; i < listeners.size(); i++) {
          InputListener listener = (InputListener) listeners.get(i);
          if (listener.isAcceptingInput()) {
            listener.keyReleased(eventKey, keys[eventKey]);
            if (consumed) {
              break;
            }
          }
        }
      }
    }

    while (Mouse.next()) {
      if (Mouse.getEventButton() >= 0) {
        if (Mouse.getEventButtonState()) {
          consumed = false;
          mousePressed[Mouse.getEventButton()] = true;
          for (int i = 0; i < listeners.size(); i++) {
            InputListener listener = (InputListener) listeners.get(i);
            if (listener.isAcceptingInput()) {
              listener.mousePressed(
                  Mouse.getEventButton(),
                  (int) (xoffset + (Mouse.getEventX() * scaleX)),
                  (int) (yoffset + ((height - Mouse.getEventY()) * scaleY)));
              if (consumed) {
                break;
              }
            }
          }
        } else {
          consumed = false;
          mousePressed[Mouse.getEventButton()] = false;
          for (int i = 0; i < listeners.size(); i++) {
            InputListener listener = (InputListener) listeners.get(i);
            if (listener.isAcceptingInput()) {
              listener.mouseReleased(
                  Mouse.getEventButton(),
                  (int) (xoffset + (Mouse.getEventX() * scaleX)),
                  (int) (yoffset + ((height - Mouse.getEventY()) * scaleY)));
              if (consumed) {
                break;
              }
            }
          }
        }
      } else {
        if (Mouse.isGrabbed()) {
          if ((Mouse.getEventDX() != 0) || (Mouse.getEventDY() != 0)) {
            consumed = false;
            for (int i = 0; i < listeners.size(); i++) {
              InputListener listener = (InputListener) listeners.get(i);
              if (listener.isAcceptingInput()) {
                listener.mouseMoved(0, 0, Mouse.getEventDX(), -Mouse.getEventDY());
                if (consumed) {
                  break;
                }
              }
            }
          }
        }

        int dwheel = Mouse.getEventDWheel();
        wheel += dwheel;
        if (dwheel != 0) {
          consumed = false;
          for (int i = 0; i < listeners.size(); i++) {
            InputListener listener = (InputListener) listeners.get(i);
            if (listener.isAcceptingInput()) {
              listener.mouseWheelMoved(dwheel);
              if (consumed) {
                break;
              }
            }
          }
        }
      }
    }

    if (!displayActive) {
      lastMouseX = getMouseX();
      lastMouseY = getMouseY();
    } else {
      if ((lastMouseX != getMouseX()) || (lastMouseY != getMouseY())) {
        consumed = false;
        for (int i = 0; i < listeners.size(); i++) {
          InputListener listener = (InputListener) listeners.get(i);
          if (listener.isAcceptingInput()) {
            listener.mouseMoved(lastMouseX, lastMouseY, getMouseX(), getMouseY());
            if (consumed) {
              break;
            }
          }
        }
        lastMouseX = getMouseX();
        lastMouseY = getMouseY();
      }
    }

    if (controllersInited) {
      for (int i = 0; i < getControllerCount(); i++) {
        int count = ((Controller) controllers.get(i)).getButtonCount() + 3;
        count = Math.min(count, 24);
        for (int c = 0; c <= count; c++) {
          if (controls[i][c] && !isControlDwn(c, i)) {
            controls[i][c] = false;
            fireControlRelease(c, i);
          } else if (!controls[i][c] && isControlDwn(c, i)) {
            controllerPressed[c] = true;
            controls[i][c] = true;
            fireControlPress(c, i);
          }
        }
      }
    }

    if (keyRepeat) {
      for (int i = 0; i < 1024; i++) {
        if (pressed[i] && (nextRepeat[i] != 0)) {
          if (System.currentTimeMillis() > nextRepeat[i]) {
            nextRepeat[i] = System.currentTimeMillis() + keyRepeatInterval;
            consumed = false;
            for (int j = 0; j < listeners.size(); j++) {
              InputListener listener = (InputListener) listeners.get(j);

              if (listener.isAcceptingInput()) {
                listener.keyPressed(i, keys[i]);
                if (consumed) {
                  break;
                }
              }
            }
          }
        }
      }
    }

    for (int i = 0; i < listeners.size(); i++) {
      InputListener listener = (InputListener) listeners.get(i);
      listener.inputEnded();
    }

    if (Display.isCreated()) {
      displayActive = Display.isActive();
    }
  }
 /** @return true if a keyboard event was read, false otherwise */
 public boolean next() {
   return Keyboard.next();
 }
Beispiel #28
0
  private void handleInput() {
    while (Keyboard.next()) {
      if (Keyboard.isRepeatEvent()) {
        continue;
      }

      if (!Keyboard.getEventKeyState()) {
        continue;
      }

      if (Keyboard.getEventKey() == Keyboard.KEY_A) {
        broadcastController.requestAuthToken(username, password);
      } else if (Keyboard.getEventKey() == Keyboard.KEY_S) {
        broadcastController.setStreamInfo(username, "Java Game", "Fun times");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_P) {
        if (broadcastController.getIsPaused()) {
          broadcastController.resumeBroadcasting();
        } else {
          broadcastController.pauseBroadcasting();
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
        if (broadcastController.getIsBroadcasting()) {
          broadcastController.stopBroadcasting();
        } else {
          VideoParams videoParams =
              broadcastController.getRecommendedVideoParams(
                  Display.getDisplayMode().getWidth(),
                  Display.getDisplayMode().getHeight(),
                  broadcastFramesPerSecond);
          videoParams.verticalFlip = true;

          broadcastController.startBroadcasting(videoParams);
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_R) {
        broadcastController.runCommercial();
      } else if (Keyboard.getEventKey() == Keyboard.KEY_I) {
        if (ingestTester != null) {
          broadcastController.cancelIngestTest();
          ingestTester = null;
        } else {
          ingestTester = broadcastController.startIngestTest();
          ingestTester.setListener(this);
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_G) {
        broadcastController.requestGameNameList("final");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_1) {
        broadcastController.sendActionMetaData(
            "TestAction",
            broadcastController.getCurrentBroadcastTime(),
            "Something cool happened",
            "{ \"MyValue\" : \"42\" }");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_2) {
        if (metaDataSpanSequenceId == -1) {
          metaDataSpanSequenceId =
              broadcastController.startSpanMetaData(
                  "TestSpan",
                  broadcastController.getCurrentBroadcastTime(),
                  "Something cool just started happening",
                  "{ \"MyValue\" : \"42\" }");
        } else {
          broadcastController.endSpanMetaData(
              "TestSpan",
              broadcastController.getCurrentBroadcastTime(),
              metaDataSpanSequenceId,
              "Something cool just stopped happening",
              "{ \"MyValue\" : \"42\" }");
          metaDataSpanSequenceId = -1;
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_C) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.disconnect();
          } else {
            chatController.connect(username);
          }
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_V) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.disconnect();
          } else {
            chatController.connectAnonymous(username);
          }
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_M) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.sendChatMessage("Test chat message: " + System.currentTimeMillis());
          }
        }
      }
    }
  }
Beispiel #29
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();
        }
      }
    }
  }
  /**
   * Process keyboard input - first look for "system" like events, then otherwise pass to the Player
   * object
   */
  public void processKeyboardInput() {
    boolean debugEnabled = Config.getInstance().isDebug();

    boolean screenHasFocus = screenHasFocus();

    while (Keyboard.next()) {
      int key = Keyboard.getEventKey();

      if (!Keyboard.isRepeatEvent() && Keyboard.getEventKeyState()) {
        if (key == Keyboard.KEY_ESCAPE) {
          if (_openDisplay != null) {
            closeScreen();
          } else {
            togglePauseMenu();
          }
        }

        // Should this be here?
        if (key == Keyboard.KEY_I) {
          toggleInventory();
        }

        if (key == Keyboard.KEY_F3) {
          Config.getInstance().setDebug(!Config.getInstance().isDebug());
        }

        if (key == Keyboard.KEY_F && !screenHasFocus) {
          toggleViewingDistance();
        }

        if (key == Keyboard.KEY_F12) {
          Terasology.getInstance().getActiveWorldRenderer().printScreen();
        }

        // Pass input to focused GUI element
        if (_openDisplay != null && !_openDisplay.isOverlay()) {
          _openDisplay.processKeyboardInput(key);
        } else {
          for (UIDisplayElement screen : _guiScreens) {
            if (screenCanFocus(screen)) {
              screen.processKeyboardInput(key);
            }
          }
        }
      }

      // Features for debug mode only
      if (debugEnabled && !screenHasFocus && Keyboard.getEventKeyState()) {
        if (key == Keyboard.KEY_UP) {
          getActiveWorldProvider().setTime(getActiveWorldProvider().getTime() + 0.005);
        }

        if (key == Keyboard.KEY_DOWN) {
          getActiveWorldProvider().setTime(getActiveWorldProvider().getTime() - 0.005);
        }

        if (key == Keyboard.KEY_RIGHT) {
          getActiveWorldProvider().setTime(getActiveWorldProvider().getTime() + 0.02);
        }

        if (key == Keyboard.KEY_LEFT) {
          getActiveWorldProvider().setTime(getActiveWorldProvider().getTime() - 0.02);
        }

        if (key == Keyboard.KEY_R && !Keyboard.isRepeatEvent()) {
          getWorldRenderer().setWireframe(!getWorldRenderer().isWireframe());
        }

        if (key == Keyboard.KEY_P && !Keyboard.isRepeatEvent()) {
          getWorldRenderer().setCameraMode(WorldRenderer.CAMERA_MODE.PLAYER);
        }

        if (key == Keyboard.KEY_O && !Keyboard.isRepeatEvent()) {
          getWorldRenderer().setCameraMode(WorldRenderer.CAMERA_MODE.SPAWN);
        }
      }

      // Pass input to the current player
      if (!screenHasFocus)
        _localPlayerSys.processKeyboardInput(
            key, Keyboard.getEventKeyState(), Keyboard.isRepeatEvent());
    }
  }