Ejemplo n.º 1
0
  private void renderMouse(Screen screen, MouseButtons mouseButtons) {

    if (mouseHidden) return;

    int crosshairSize = 15;
    int crosshairSizeHalf = crosshairSize / 2;

    Bitmap marker = new Bitmap(crosshairSize, crosshairSize);

    // horizontal line
    for (int i = 0; i < crosshairSize; i++) {
      if (i >= crosshairSizeHalf - 1 && i <= crosshairSizeHalf + 1) continue;

      marker.pixels[crosshairSizeHalf + i * crosshairSize] = 0xffffffff;
      marker.pixels[i + crosshairSizeHalf * crosshairSize] = 0xffffffff;
    }

    screen.blit(
        marker,
        mouseButtons.getX() / SCALE - crosshairSizeHalf - 2,
        mouseButtons.getY() / SCALE - crosshairSizeHalf - 2);
  }
Ejemplo n.º 2
0
 public void mouseReleased(MouseEvent e) {
   mouseButtons.setNextState(e.getButton(), false);
 }
Ejemplo n.º 3
0
 public void mousePressed(MouseEvent e) {
   mouseButtons.setNextState(e.getButton(), true);
 }
Ejemplo n.º 4
0
 public void mouseExited(MouseEvent e) {
   mouseButtons.releaseAll();
 }
Ejemplo n.º 5
0
  private void tick() {
    if (level != null) {
      if (level.player1Score >= Level.TARGET_SCORE) {
        addMenu(new WinMenu(GAME_WIDTH, GAME_HEIGHT, 1));
        level = null;
        return;
      }
      if (level.player2Score >= Level.TARGET_SCORE) {
        addMenu(new WinMenu(GAME_WIDTH, GAME_HEIGHT, 2));
        level = null;
        return;
      }
      if (keys.escape.wasPressed()) {
        clearMenus();
        addMenu(new TitleMenu(GAME_WIDTH, GAME_HEIGHT));
        level = null;
        return;
      }
    }
    if (packetLink != null) {
      packetLink.tick();
    }

    mouseButtons.setPosition(getMousePosition());
    if (!menuStack.isEmpty()) {
      menuStack.peek().tick(mouseButtons);
    }
    if (mouseMoved) {
      mouseMoved = false;
      mouseHideTime = 0;
      if (mouseHidden) {
        mouseHidden = false;
      }
    }
    if (mouseHideTime < 60) {
      mouseHideTime++;
      if (mouseHideTime == 60) {
        mouseHidden = true;
      }
    }
    mouseButtons.tick();

    if (level != null) {
      if (synchronizer.preTurn()) {
        synchronizer.postTurn();
        for (int index = 0; index < keys.getAll().size(); index++) {
          Keys.Key key = keys.getAll().get(index);
          boolean nextState = key.nextState;
          if (key.isDown != nextState) {
            synchronizer.addCommand(new ChangeKeyCommand(index, nextState));
          }
        }
        if (keys.save.isDown) {
          level.save();
        }
        keys.tick();
        for (Keys skeys : synchedKeys) {
          skeys.tick();
        }

        // if mouse is in use, update player orientation before level
        // tick
        if (!mouseHidden) {

          // update player mouse, in world pixels relative to player
          player.setAimByMouse(
              ((mouseButtons.getX() / SCALE) - (screen.w / 2)),
              (((mouseButtons.getY() / SCALE) + 24) - (screen.h / 2)));
        } else {
          player.setAimByKeyboard();
        }

        level.tick();
      }
    }

    if (createServerState == 1) {
      createServerState = 2;

      synchronizer = new TurnSynchronizer(MojamComponent.this, packetLink, localId, 2);

      clearMenus();
      createLevel(TitleMenu.level);

      synchronizer.setStarted(true);
      packetLink.sendPacket(new StartGamePacket(TurnSynchronizer.synchedSeed, TitleMenu.level));
      packetLink.setPacketListener(MojamComponent.this);
    }
  }