Пример #1
1
  @Override
  public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    this.drawDefaultBackground();

    mc.getTextureManager().bindTexture(skrivemaskinegui);

    this.drawTexturedModalRect(this.width / 2 - 128, this.height / 2 - 128, 0, 0, 256, 256);

    /* this is where the editor reads keys and writes to the screen */
    if (org.lwjgl.input.Keyboard.getEventKeyState()) {
      //
      if (isAllowedDeletion()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedNewLine()) {
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, '\n');
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedLeftArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (isAllowedRightArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (Keyboard.getEventKey() == Keyboard.KEY_TAB) {
        text.deleteCharAt(cursorLocation);
        for (int i = 0; i < 3; i++) {
          text.insert(cursorLocation, " ");
          cursorLocation++;
        }
        text.insert(cursorLocation, cursor); // moving cursor

      } else {
        if (isAllowedCharacters()) {
          // System.out.println(org.lwjgl.input.Keyboard.getEventKey());
          text.deleteCharAt(cursorLocation);
          text.insert(cursorLocation, org.lwjgl.input.Keyboard.getEventCharacter());
          cursorLocation++;
          text.insert(cursorLocation, cursor); // moving cursor
        }
      }

      org.lwjgl.input.Keyboard.destroy();
    } else if (!org.lwjgl.input.Keyboard.isCreated()) {
      try {
        org.lwjgl.input.Keyboard.create();
      } catch (Exception e) {
      }
    }

    /* writes the text string to the screen */
    renderer.drawSplitString(
        text.toString(), this.width / 2 - 118, this.height / 2 - 119, 238, 0xFFFFF0);

    super.drawScreen(mouseX, mouseY, partialTicks);
  }
Пример #2
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;
      }
    }
  }
  @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;
        }
      }
    }
  }
  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
  }
Пример #5
0
 @Override
 public void handleKeyboardInput() {
   super.handleKeyboardInput();
   if (Keyboard.getEventKeyState()) {
     int key = Keyboard.getEventKey();
     if (key == Keyboard.KEY_UP) {
       navigateMap(0, navigateStep);
     } else if (key == Keyboard.KEY_DOWN) {
       navigateMap(0, -navigateStep);
     } else if (key == Keyboard.KEY_LEFT) {
       navigateMap(navigateStep, 0);
     } else if (key == Keyboard.KEY_RIGHT) {
       navigateMap(-navigateStep, 0);
     } else if (key == Keyboard.KEY_ADD || key == Keyboard.KEY_EQUALS) {
       setMapScale(mapScale * 2);
     } else if (key == Keyboard.KEY_SUBTRACT || key == Keyboard.KEY_MINUS) {
       setMapScale(mapScale / 2);
     }
     // Close the GUI if a hotbar key is pressed
     else {
       KeyBinding[] hotbarKeys = mc.gameSettings.keyBindsHotbar;
       for (KeyBinding bind : hotbarKeys) {
         if (key == bind.getKeyCode()) {
           close();
           break;
         }
       }
     }
   }
 }
Пример #6
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);
  }
Пример #7
0
  /** Handles keyboard input. */
  public void handleKeyboardInput() throws IOException {
    if (Keyboard.getEventKeyState()) {
      this.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey());
    }

    this.mc.dispatchKeypresses();
  }
Пример #8
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);
   }
 }
  /**
   * *************************************************************************************************************************************************************************************************
   * 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;
    }
  }
Пример #10
0
  public void func_569_f() {
    if (Keyboard.getEventKeyState()) {
      if (Keyboard.getEventKey() == 87) {
        this.field_945_b.func_6270_h();
        return;
      }

      this.func_580_a(Keyboard.getEventCharacter(), Keyboard.getEventKey());
    }
  }
Пример #11
0
 @Override
 public void handleKeyboardInput() {
   ControlsBasicItem item = model.getEditingItem();
   if (item != null) {
     this.keyTyped(
         org.lwjgl.input.Keyboard.getEventCharacter(),
         org.lwjgl.input.Keyboard.getEventKey(),
         org.lwjgl.input.Keyboard.getEventKeyState());
   } else {
     super.handleKeyboardInput();
   }
 }
Пример #12
0
 /*     */ 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;
   /*     */ }
Пример #13
0
  public void pollKeyboard() {
    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {

        switch (Keyboard.getEventKey()) {
            // Quit the game
          case Keyboard.KEY_ESCAPE:
            System.exit(0);
            break;
        }
      }
    }
  }
Пример #14
0
  // TODO: Deal with duplicates. Can't use Traits sadly.
  public void keyboardInput() {
    HashMap<String, Object> passedInformation = new HashMap<String, Object>(0);
    passedInformation.put("character", Keyboard.getEventCharacter());
    passedInformation.put("key", Keyboard.getEventKey());
    passedInformation.put("down", Keyboard.getEventKeyState());
    passedInformation.put("time", Keyboard.getEventNanoseconds());
    passedInformation.put("count", Keyboard.getKeyCount());

    for (ScreenLayer layer : guiLayers) {
      MinecraftForge.EVENT_BUS.post(new LayerEvent.KeyboardInput(GUIAPIEvent.Phase.START, layer));
      layer.keyInputEvent(passedInformation);
      MinecraftForge.EVENT_BUS.post(new LayerEvent.KeyboardInput(GUIAPIEvent.Phase.END, layer));
    }
  }
  public void manageBiostats(InputEvent.KeyInputEvent event) {
    AndroidPlayer androidPlayer =
        AndroidPlayer.get(FMLClientHandler.instance().getClientPlayerEntity());

    for (IBionicStat stat : AndroidStatRegistry.stats.values()) {
      int level = androidPlayer.getUnlockedLevel(stat);
      if (level > 0 && stat.isEnabled(androidPlayer, level)) {
        stat.onKeyPress(
            androidPlayer,
            androidPlayer.getUnlockedLevel(stat),
            Keyboard.getEventKey(),
            Keyboard.getEventKeyState());
      }
    }
  }
  @SubscribeEvent
  public void onKeyInput(InputEvent.KeyInputEvent event) {
    if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) {
      int key = Keyboard.getEventKey();
      boolean isDown = Keyboard.getEventKeyState();

      // Matter Scanner key
      if (isDown && keys[MATTER_SCANNER_KEY].getKeyCode() == key) {
        // send packet to open gui
        MatterScanner.DisplayGuiScreen();
      }

      manageBiostats(event);
    }
  }
Пример #17
0
 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;
       }
     }
   }
 }
Пример #18
0
  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());
      }
    }
  }
Пример #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());
       }
     }
   }
 }
Пример #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);
   }
 }
Пример #21
0
  @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;
          }
        }
      }
    }
  }
Пример #22
0
 @Override
 protected boolean onEvent(InputEvent event) {
   if (current != null) {
     if (event instanceof MouseInputEvent) {
       int mid = Mouse.getEventButton();
       if (mid == 1 && Mouse.getEventButtonState()) {
         current.handleClicking(Raytrace.traceLiving(player, 4, EntitySelectors.nothing));
       }
     } else {
       if (Keyboard.getEventKeyState()) {
         if (current.handlesKeyInput())
           current.handleKeyInput(Keyboard.getEventCharacter(), Keyboard.getEventKey());
       }
     }
   } else {
     AcademyCraft.log.error("Human is dead. Mismatch.");
     this.setDead();
   }
   return true;
 }
Пример #23
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;
        }
      }
    }
  }
Пример #24
0
  @Override
  public void update() {

    if (x < 0) {
      x = 1;
    }
    // System.out.println(viX);

    if (GameB.mouseCont) {
      this.x = (Mouse.getX()) - this.sx / 2;
    }

    if (Keyboard.getEventKey() == Keyboard.KEY_D) {

      if (Keyboard.getEventKeyState()) {

        //	if(x<0 ){x=0;x-=SPEED*mag;}
        //	else if(x>Display.getWidth()-this.sx){x=Display.getWidth()-sx;x-=SPEED*mag;}
        // else
        if (SPEED < 5) {
          SPEED += 0.2f;
        }
        if (x + sx < Display.getWidth() && x > 0) {
          x += SPEED;
          viX = (float) Math.pow(SPEED, 2);
        }

        // System.out.println("A Key Pressed");
      } else {
        if (SPEED > 0) {
          SPEED -= 0.2f;
          if (x + sx < Display.getWidth() && x >= 0) {
            x += SPEED;
            viX = (float) Math.pow(SPEED, 2);
          } else {
            x = Display.getWidth() - 1 - sx;
            viX = (float) Math.pow(SPEED, 2);
          }
        }
        // System.out.println("A Key Released");

      }
    }
    if (Keyboard.getEventKey() == Keyboard.KEY_A) {

      if (Keyboard.getEventKeyState()) {

        // System.out.println("A Key Pressed");
        if (SPEED < 5) {
          SPEED += 0.2f;
          viX = (float) Math.pow(SPEED, 2) * -1;
        }
        if (x < Display.getWidth() && x >= 3) {
          x += SPEED * -1;
          viX = (float) Math.pow(SPEED, 2) * -1;
        }
      } else {
        // System.out.println("A Key Released");
        if (SPEED > 0) {
          SPEED -= 0.2f;
          if (x < Display.getWidth() && x > 0) {
            x -= SPEED;
            viX = (float) Math.pow(SPEED, 2) * -1;
          } else {
            x = 2;
            viX = 0;
          }
          // viX=(int)SPEED;
        }
      }
    }

    // System.out.println(a + " " + t);

    /*
     *
     *
     * if(ftime2 == 0){ftime2 = 1;ciX=this.x;t=0;viX = velF; a*=-1;}
     * t=t+(float)(0.08f);
     *
     * if(this.x<Display.getWidth()-this.sx){this.x =
     * .5f*(a)*t*t+viX*t+ciX;}
     * if(velF-1<0){ciX=this.x;ftime=0;a*=-1;System.out
     * .println("changed2");System.out.println(aO);} } else
     * if(Keyboard.isKeyDown(Keyboard.KEY_A)==false &&
     * Keyboard.isKeyDown(Keyboard.KEY_D)==false && (ftime3==1) &&velF2<0 ){
     *
     * if(ftime4 == 0){;ftime4 = 1;ciX=this.x;t2=0;viX = velF2; aO*=-1;}
     * t2=t2+(float)(0.08f);
     *
     * if(this.x>0){this.x = .5f*(aO)*t2*t2+viX*t2+ciX;}
     * if(velF2+1>0){ftime3
     * =0;ciX=this.x;aO*=-1;viX=0;System.out.println("changed"
     * );System.out.println(aO);}
     *
     * } if(this.x<0){this.x=1;}
     */

    // if(ball.getY()>Display.getHeight()){ball.resetPosition();Game.pScore++;
    // System.out.println(Game.pScore);}
    // if(ball.getY()<0){ball.resetPosition();Game.eScore++;
    // System.out.println(Game.eScore);}

    if (Physics.checkCollisions(this, ball) && this.y - sy <= ball.y) {

      // a=4/Math.abs(ball.x-x);						float diff = Math.abs(ball.x-x);

      // ball.reverseY(getCenterX()); //getCenterY() FORCES TESTING Trig
      // calculations are not the best solution. I resorted to simplified
      // compoenent method.
      // ball.whywouldthiswork2();
      // ball.viY = 0;
      // ball.viX = 0;
      // ball.a = 0;
      // ball.t = 0;
      // ball.ci = this.y-this.getSY();
      /*
       * float resFx = ball.velF *
       * (float)Math.acos(ball.velF/ball.x)+this.viX;
       *
       * float resFy = ball.vfY*(float)Math.asin(ball.vfY/ball.x); float
       * test = (float)Math.sqrt(Math.pow(resFx, 2)+Math.pow(resFy, 2));
       * float resF = test*(float)Math.atan(resFy/resFx); ball.t = 0;
       * ball.ci = this.y-this.getSY(); ball.ciX= this.x; ball.y--;
       * ball.viX = resFx; ball.viY = resFy;
       */
      // ball.reverseY();

      ball.reverseY();

      float resFx = ball.viX + this.viX;
      // float resFy = ball.vfY;
      if ((int) ball.viX == 0) {}
      ball.viX = (ball.viX + (this.viX) * 2) * .45f;
      // ball.viY= -resFy;

    }

    // this.sy = SIZEY;

  }
Пример #25
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();
  }
Пример #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) {
      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();
    }
  }
Пример #27
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();
        }
      }
    }
  }
 public boolean getEventKeyState() {
   return Keyboard.getEventKeyState();
 }
Пример #29
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());
          }
        }
      }
    }
  }
Пример #30
0
  /**
   * 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());
    }
  }