Example #1
0
 public GameMenu(GameMain midlet_ /*,ConnectionServer conn_,RoleDataValue roleData_*/) {
   // true->使用GameAction(boolean suppressKeyEvents) , false->不使用GameAction(boolean
   // suppressKeyEvents)
   super(false);
   // 使用全螢幕
   setFullScreenMode(true);
   midlet = midlet_;
   // music = music_;
   // roleData = roleData_;
   display = midlet.getDisplay();
   layMa = new LayerManager();
   spInterface = new Sprite(createImage("/image/gameInterface/inface.png"), bgWidth, bgHeight);
   spName = new Sprite(createImage("/image/gameInterface/Title.png"), 84, 15);
   menustate = 0;
   menuNum = 3;
   // setFullScreenMode(true);
   g = getGraphics();
   /*if(!(getWidth()<176) || !(getHeight()<208)){
   	disWidth = (getWidth()-176)/2;//抓取螢幕的中心點
   	disHeight = (getHeight()-208)/2;//抓取螢幕的中心點
   }*/
   // 設定Sprite位置
   spName.setPosition(80, 20);
   spInterface.setPosition(0, 0);
   // 加入到LayerManager
   layMa.append(spName);
   spName.setVisible(false);
   layMa.append(spInterface);
   spInterface.setFrame(0);
   System.out.println("start");
   start();
 }
Example #2
0
  /**
   * Metoda wyswietlajaca okreg obrazujacy postep wykrywania urzadzen
   *
   * @param g Referencja do obiektu klasy Graphics, ktory pozwala na narysowanie pasku postepu
   * @param progress Liczba z zakresu 0 - 359: zakres luku
   */
  public void showInquiryProgress(Graphics g, int progress) {
    int c = g.getColor();

    g.setColor(255, 255, 255);

    g.drawArc(screenWidth - 25, screenHeight - 57, 10, 16, 0, progress);

    g.setColor(c);

    bluetoothLogoSmallSprite.setPosition(screenWidth - 24, screenHeight - 56);
    bluetoothLogoSmallSprite.paint(g);
  }
Example #3
0
 private int[] getDiceX() {
   int w = getWidth();
   int diceWidth = red_dice.getWidth();
   int ax = w / 2 - MoveDialog.distanceFromCenter - diceWidth / 2;
   int dx = w / 2 + MoveDialog.distanceFromCenter - diceWidth / 2;
   return new int[] {ax, dx};
 }
Example #4
0
  public void run() {
    try {
      if (init) {
        Thread.sleep(500);
        disWidth = (getWidth() - 176) / 2; // 抓取螢幕的中心點
        disHeight = (getHeight() - 208) / 2; // 抓取螢幕的中心點
        drawDisplay();

        systemShowInf("建立資料庫...");
        new DataBaseWrite();
        systemShowInf("設定音樂...");
        GameMain.music = new BackupMusic();
        music = GameMain.music;
        systemShowInf("設定遊戲環境...");
        GameMain.roleData = new RoleDataValue();
        roleData = GameMain.roleData;
        GameMain.gaminf = new GameInfString();
        GameMain.music.musicStart("1");
        spInterface.setFrame(1);
        drawDisplay();
        changeMeun();
        init = false;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #5
0
  /*
   * 图片特旋转
   */
  public Image effect_rotate(Image src, int direction) {
    Sprite sprite = new Sprite(src);
    switch (direction) {
      case 1:
        sprite.setTransform(sprite.TRANS_ROT270);
        break;
      case 2:
        sprite.setTransform(sprite.TRANS_ROT90);
        break;
    }

    Image temp = Image.createImage(src.getHeight(), src.getWidth());
    Graphics g = temp.getGraphics();
    sprite.setPosition(0, 0);
    sprite.paint(g);
    return temp;
  }
  /**
   * Set up all of the data.
   *
   * <p>This is called from a separate init method in order to limit the amount of resource loading
   * that is done by the thread that called the startApp method.
   */
  public void init() throws Exception {
    // TODO: [Exercise 3][step 1] - initialization code. Please, don't forget to fix the missing
    // imports and fields
    mazeDesign = new MazeGameDesign(); // [Exercise3]
    jamesSprite = mazeDesign.getJamesS(); // [Exercise3]
    dukeSprite = mazeDesign.getDukeS(); // [Exercise3]
    dukeSprite.defineReferencePixel(dukeSprite.getWidth() / 2, 0); // [Exercise3]
    dukeSpriteAnimator = new SpriteAnimationTask(dukeSprite, false); // [Exercise3]
    myWalls = mazeDesign.getMaze1(); // [Exercise3]
    mazeDesign.updateLayerManagerForLevel1(this); // [Exercise3]

    timer = new Timer(); // [Exercise3]
    timer.scheduleAtFixedRate(dukeSpriteAnimator, 0, mazeDesign.dukeSseq001Delay); // [Exercise3]
    // this sets the view screen so that the player is
    // in the center.
    myViewWindowX = dukeSprite.getX() - ((DISP_HEIGHT - SQUARE_WIDTH) / 2);
    myViewWindowY = dukeSprite.getY() - ((DISP_HEIGHT - SQUARE_WIDTH) / 2);

    System.gc();
  }
Example #7
0
  public boolean animate(Graphics g) {
    if (animatedOnce) {
      if (frameSkipRate == 0) {
        sprite.nextFrame();
      } else {
        frameCurrent++;
        if (frameCurrent > 1000) frameCurrent = 0;
        if (frameCurrent % frameSkipRate == 0) sprite.nextFrame();
      }
    } else {
      animatedOnce = true;
    }

    sprite.paint(g);
    if (sprite.getFrame() == endFrame) {
      executeCustomMethods();
      return false;
    }
    return true;
  }
Example #8
0
  public int insideButton(int x, int y) {

    // <copy-pasta>
    int imageAreaHeight = getImageAreaHeight();
    int heightOfComponents =
        ((MoveDialog.DialogLayout) getContentPane().getLayout())
            .getHeightOfComponents(getContentPane());
    // this is the MIDDLE of the images area
    int xOffset = getContentPane().getWidth() / 2;
    int yOffset =
        (getContentPane().getHeight() - heightOfComponents) / 2
            + imageAreaHeight / 4
            + getContentPane().getY();

    int y1 = yOffset + imageAreaHeight / 4; // top of dice
    int y2 = y1 + red_dice.getHeight() + XULLoader.adjustSizeToDensity(2);
    int y3 = y2 + red_dice.getHeight() + XULLoader.adjustSizeToDensity(2);
    // </copy-pasta>

    int[] diceXs = getDiceX();
    int ax = diceXs[0], dx = diceXs[1];

    int W = red_dice.getWidth();
    int H = red_dice.getHeight();

    if (x >= ax && x < (ax + W) && y >= y1 && y < (y1 + H)) {
      return 1;
    } else if (x >= ax && x < (ax + W) && y >= y2 && y < (y2 + H)) {
      return 2;
    } else if (x >= ax && x < (ax + W) && y >= y3 && y < (y3 + H)) {
      return 3;
    } else if (x >= dx && x < (dx + W) && y >= y1 && y < (y1 + H)) {
      return 4;
    } else if (x >= dx && x < (dx + W) && y >= y2 && y < (y2 + H)) {
      return 5;
    } else if (x >= dx && x < (dx + W) && y >= y3 && y < (y3 + H)) {
      return 6;
    }
    return 0;
  }
Example #9
0
  /**
   * Metoda wczytujaca obrazki z zasobow i tworzaca tlo oraz ikony
   *
   * @throws IOException
   */
  public void loadResources() throws IOException {
    int i, j;

    Image image = Image.createImage("/res/layer.png"); // wczytanie obrazku tla
    Image iconsImage =
        Image.createImage("/res/icons.png"); // wczytanie obrazu przechowujacego ikony przyciskow
    Image logoImage =
        Image.createImage(
            "/res/blue_logo_small.png"); // wczytanie obrazku przechowujacego male logo Bluetooth
    int rows = getHeight() / 16;
    int cols = getWidth() / 16;

    backgroundLayer = new TiledLayer(cols, rows, image, 16, 16);
    backgroundLayer.setCell(0, 0, 3);

    for (i = 0; i < cols - 2; i++) backgroundLayer.setCell(i + 1, 0, 2);
    backgroundLayer.setCell(cols - 1, 0, 1);
    for (i = 1; i < rows - 1; i++) {
      backgroundLayer.setCell(0, i, 4);
      backgroundLayer.setCell(cols - 1, i, 8);
    }
    backgroundLayer.setCell(0, rows - 1, 5);
    for (i = 0; i < cols - 2; i++) backgroundLayer.setCell(i + 1, rows - 1, 6);
    backgroundLayer.setCell(cols - 1, rows - 1, 7);

    for (i = 1; i < cols - 1; i++) for (j = 1; j < rows - 1; j++) backgroundLayer.setCell(i, j, 9);

    backgroundLayer.setPosition(
        (getWidth() % 16) / 2,
        (getHeight() % 16) / 2); // przesuniecie utworzonej warstwy na srodek wyswietlacza

    playPauseSprite = new Sprite(iconsImage, 32, 32);
    playPauseSprite.setFrame(PLAY_ICON);
    nextSprite = new Sprite(iconsImage, 32, 32);
    nextSprite.setFrame(NEXT_ICON); // ustawienie sprite'a tak, aby wyswietlal ikone 'Next'
    previousSprite = new Sprite(iconsImage, 32, 32);
    previousSprite.setFrame(
        PREVIOUS_ICON); // ustawienie sprite'a tak, aby wyswietlal ikone 'Previous'
    bluetoothLogoSmallSprite = new Sprite(logoImage, 8, 14);
  }
Example #10
0
  public void drawButton(GuiButton selectedButton) {
    if (!drawButton) {
      if (!Touch.isInputHandled() && Touch.isPressed() && checkPoint(Touch.getX(), Touch.getY())) {
        Touch.setInputHandled();
      }
      return;
    }

    if (getButtonImage() != buttonImage) {
      initButtonSprite();
    }

    boolean flag = false;

    if ((!Touch.isInputHandled() || cc.currentScreen == null)
        && Touch.isPressed()
        && checkPoint(Touch.getX(), Touch.getY())) {
      flag = true;
    } else if (selectedButton == this) {
      flag = true;
    }

    int i = getHooverState(flag);

    int y = yPos;

    if (selectedButton != null
        && selectedButton.yPos + selectedButton.getHeight() > Comcraft.screenHeight) {
      y -= selectedButton.yPos + selectedButton.getHeight() - Comcraft.screenHeight + 10;
    }

    buttonSprite.setPosition(xPos, y);
    buttonSprite.setFrame(i);
    buttonSprite.paint(cc.g);

    drawButtonString(flag, y);
  }
Example #11
0
  public void drawDice(boolean isAttacker, int result, int dx, int dy, Graphics2D g) {
    g.translate(dx, dy);

    if (isAttacker) {
      g.drawSprite(red_dice, DICE_NORMAL, 0, 0);
    } else {
      g.drawSprite(blue_dice, DICE_NORMAL, 0, 0);
    }

    int w = red_dice.getWidth();

    int size = (int) (w / (29D / 3D) + 0.5);
    int close = (int) (w / (29D / 7D) + 0.5);
    int middle = (w - size) / 2;
    int far = w - close - size;

    g.setColor(0xC8FFFFFF);

    if (result == 0) {
      g.fillOval(middle, middle, size, size);
    } else if (result == 1) {
      g.fillOval(close, close, size, size);
      g.fillOval(far, far, size, size);
    } else if (result == 2) {
      g.fillOval(close, close, size, size);
      g.fillOval(middle, middle, size, size);
      g.fillOval(far, far, size, size);
    } else if (result == 3) {
      g.fillOval(close, close, size, size);
      g.fillOval(far, close, size, size);
      g.fillOval(far, far, size, size);
      g.fillOval(close, far, size, size);
    } else if (result == 4) {
      g.fillOval(close, close, size, size);
      g.fillOval(far, close, size, size);
      g.fillOval(far, far, size, size);
      g.fillOval(close, far, size, size);
      g.fillOval(middle, middle, size, size);
    } else if (result == 5) {
      g.fillOval(close, close, size, size);
      g.fillOval(far, close, size, size);
      g.fillOval(far, far, size, size);
      g.fillOval(close, far, size, size);
      g.fillOval(middle, close, size, size);
      g.fillOval(middle, far, size, size);
    }

    g.translate(-dx, -dy);
  }
Example #12
0
 public void moveFight() {
   sptSword.setPosition(
       fightRange[fightCurIndex][1] * MyGameCanvas.CHECKWIDTH,
       fightRange[fightCurIndex][0] * MyGameCanvas.CHECKHEIGHT);
   int dR = fightRange[fightCurIndex][0] - thisRow;
   int dC = fightRange[fightCurIndex][1] - thisCol;
   if (abs(dR) > abs(dC)) {
     if (dR > 0) direction = DOWN;
     else direction = UP;
   } else {
     if (dC > 0) direction = RIGHT;
     else direction = LEFT;
   }
   setFrame(moveFrame[direction][0]);
 }
  /**
   * Internal to requestMove. Set the duke sprite to the correct frame depending on her movements..
   */
  private void updateSprite(int hdirection, int vdirection) {
    // if the duke is moving left or right, we set
    // his image to be facing the right direction
    if (hdirection > 0) {
      dukeSprite.setTransform(Sprite.TRANS_NONE);
    } else if (hdirection < 0) {
      dukeSprite.setTransform(Sprite.TRANS_MIRROR);
    }
    // in case that duke is moving, change the showing sprite image
    if (lastHorDirection != hdirection) {
      dukeSprite.setFrameSequence(
          mazeDesign.dukeSseq001); // TODO: [Exercise 3][step 2] Let the duke move set to vertical
      // sequence
    }

    if (lastVertDirection != vdirection) {
      if (vdirection > 0) { // he's jumping
        dukeSprite.setFrameSequence(
            mazeDesign.dukeSfalling); // TODO: [Exercise 3][step 2] set to falling sequence
      } else if (vdirection < 0) {
        dukeSprite.setFrameSequence(
            mazeDesign.dukeSjumping); // TODO: [Exercise 3][step 2] set to jumping sequence
      }
    }

    if ((vdirection != 0) || (hdirection != 0)) {
      dukeSpriteAnimator.forward();
    } else {
      dukeSpriteAnimator.setMoving(false);
      dukeSprite.setFrameSequence(
          mazeDesign.dukeSseq001); // TODO: [Exercise 3][step 2] set to vertical sequence
    }

    lastHorDirection = hdirection;
    lastVertDirection = vdirection;
  }
Example #14
0
 // 畫面選單改變
 public void changePage() {
   try {
     switch (page) {
       case -1:
         spName.setVisible(false);
         spInterface.setFrame(1);
         drawDisplay();
         break;
       case 0: // 遊戲帳號輸入選單
         menustate = 0;
         spName.setVisible(true);
         spInterface.setFrame(2);
         spName.setFrame(0);
         drawDisplay();
         for (int i = 0; i < loginStr.length; i++) nowString[i] = loginStr[i];
         menuNum = loginStr.length; // MENU 數量
         // System.out.println(page);
         break;
       case 1: // 遊戲說明選單
         spInterface.setFrame(2);
         spName.setFrame(1);
         drawDisplay();
         for (int i = 2; i < nowString.length; i++) nowString[i] = gameInfo[i - 2];
         menuNum = loginStr.length;
         menustate = 2;
         break;
       case 2: // 遊戲姓名輸入選單
         spInterface.setFrame(2);
         spName.setFrame(2);
         spName.setVisible(true);
         drawDisplay();
         for (int i = 1; i < nowString.length; i++) nowString[i] = gameNameInp[i - 1];
         menuNum = loginStr.length;
         menustate = 1;
         break;
       case 3: // 遊戲角色建立成功選單
         spName.setVisible(false);
         spInterface.setFrame(3);
         drawDisplay();
         for (int i = 2; i < nowString.length; i++) nowString[i] = showGameUser[i - 2];
         menuNum = loginStr.length;
         menustate = 2;
         break;
     }
     drawMenu();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #15
0
  /** Metoda odpowiedzialna za przerysowanie ekranu */
  public void updateScreen() {
    Graphics g = getGraphics();
    if (displayedScreen == PLAYER_SCREEN) {
      if (backgroundLayer != null) {
        backgroundLayer.paint(g);
      }

      if ((bluetoothPlayer.getIsConnectedToServer() == false)
          && (bluetoothPlayer.getBluetoothError() == false)) drawText(g, "Connecting...", 0);
      else if (bluetoothPlayer.getBluetoothError() == true) drawText(g, "Disconnected", 0);
      else {
        if (bluetoothPlayer.getTitle() != null) {
          drawText(g, bluetoothPlayer.getTitle(), 0);
        }
        if (bluetoothPlayer.getArtist() != null) {
          drawText(g, bluetoothPlayer.getArtist(), 1);
        }

        if (showVolume > 0) {
          showVolume--;

          drawText(g, "      Volume: " + volumeLevel + "%", 2);
        }
      }

      if (bluetoothPlayer.isBluetoothOn()) {
        if (bluetoothPlayer.getInquiryStarted()) {
          showInquiryProgress(g, inquiryProgress += 20);
          if (inquiryProgress >= 360) inquiryProgress = 0;
        } else {
          inquiryProgress = 0;
          showInquiryProgress(g, 0);
        }

      } else {
        drawText(g, "Please turn your Bluetooth device on", 1);
      }

      playPauseSprite.setPosition(screenWidth / 2 - 16, screenHeight - 66 + buttonsLocation);
      previousSprite.setPosition(screenWidth / 2 - 55, screenHeight - 66 + buttonsLocation);
      nextSprite.setPosition(screenWidth / 2 + 23, screenHeight - 66 + buttonsLocation);
      playPauseSprite.paint(g);
      previousSprite.paint(g);
      nextSprite.paint(g);

      if (bluetoothPlayer.getTotalTime() != 0)
        showProgressBar(g, bluetoothPlayer.getCurrentTime(), bluetoothPlayer.getTotalTime());
      else showProgressBar(g, 0, 100);
    } else if (displayedScreen == MEDIA_LIBRARY_LOADING) {
      if (backgroundLayer != null) {
        backgroundLayer.paint(g);
      }

      if (bluetoothPlayer.getIsConnectedToServer() == true) {
        drawText(g, "Loading media library", 0);
        drawText(g, "Please wait...", 1);

        // display size of the media library
        if (bluetoothPlayer.getMediaLibrarySize() >= 1024) {
          drawText(
              g,
              "Total size: "
                  + bluetoothPlayer.getMediaLibrarySize() / 1024
                  + "."
                  + (bluetoothPlayer.getMediaLibrarySize() % 1024) * 100 / 1024
                  + " kB",
              3);
        } else drawText(g, "Total size: " + bluetoothPlayer.getMediaLibrarySize() + " B", 3);

        int size = bluetoothPlayer.getMediaLibrarySize();

        if (size == 0) // to avoid dividing by zero
        size = 1;

        showProgressBar(g, bluetoothPlayer.getMediaLibraryDownloadedBytes(), size);

        // if the playlist file was downloaded and parsed
        if (bluetoothPlayer.getMediaLibrary().getLibraryDownloadedAndParsed() == true)
          setDisplayedScreen(MainCanvas.MEDIA_LIBRARY_SCREEN);
      } else drawText(g, "You're not connected", 0);
    } else if (displayedScreen == MEDIA_LIBRARY_SCREEN) {
      if (backgroundLayer != null) {
        backgroundLayer.paint(g);
      }
      showMediaLibrary(
          g, bluetoothPlayer, mediaLibrarySelectedItemOnScreen, mediaLibraryItemsNumberOnScreen);
    }

    flushGraphics();
  }
Example #16
0
  /** Metoda sprawdzajaca stan klawiszy i aktualizujaca zmienne odpowiedzialne za stan gry */
  public void updateState() {
    int keys = getKeyStates();

    if (bluetoothPlayer.getIsConnectedToServer() == true) {
      if (displayedScreen == PLAYER_SCREEN) { // jesli wyswietlany jest ekran odtwarzacza
        // jesli przycisk 'Play / Pause' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & FIRE_PRESSED) != 0) && (nextPressed == false) && (previousPressed == false)) {
          if (playPauseSprite.getFrame() == PLAY_ICON) {
            playPauseSprite.setFrame(PLAY_ICON_PRESSED);
          } else if (playPauseSprite.getFrame() == PAUSE_ICON) {
            playPauseSprite.setFrame(PAUSE_ICON_PRESSED);
          }

          if (firePressed == false) soundPlayer.play(SoundPlayer.CLICK_SOUND);

          firePressed = true;
        }
        // przycisk zostal zwolniony
        else if (((keys & FIRE_PRESSED) == 0) && (firePressed == true)) {
          if (playPauseSprite.getFrame() == PLAY_ICON_PRESSED) { // zmiana stanu przycisku
            bluetoothPlayer.play();
            playPauseSprite.setFrame(PAUSE_ICON);

          } else if (playPauseSprite.getFrame() == PAUSE_ICON_PRESSED) {
            bluetoothPlayer.pause();
            playPauseSprite.setFrame(PLAY_ICON);
          }

          firePressed = false;
        }
        // jesli przycisk 'Next' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & RIGHT_PRESSED) != 0) && (firePressed == false) && (previousPressed == false)) {
          if (nextSprite.getFrame() == NEXT_ICON) nextSprite.setFrame(NEXT_ICON_PRESSED);

          if (nextPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          nextPressed = true;
        }
        // przycisk zostal zwolniony
        else if (((keys & RIGHT_PRESSED) == 0) && (nextPressed == true)) {
          if (nextSprite.getFrame() == NEXT_ICON_PRESSED) nextSprite.setFrame(NEXT_ICON);

          bluetoothPlayer.addCommandToProcess(BluetoothPlayer.COMMAND_NEXT);
          nextPressed = false;

          if (bluetoothPlayer.getTotalTime() != 0) // jesli utwor jest odtwarzany lub zapauzowany
          playPauseSprite.setFrame(PAUSE_ICON);
        }
        // jesli przycisk 'Previous' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & LEFT_PRESSED) != 0) && (nextPressed == false) && (firePressed == false)) {
          if (previousSprite.getFrame() == PREVIOUS_ICON)
            previousSprite.setFrame(PREVIOUS_ICON_PRESSED);

          if (previousPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          previousPressed = true;
        }
        // przycisk zostal zwolniony
        else if (((keys & LEFT_PRESSED) == 0) && (previousPressed == true)) {
          if (previousSprite.getFrame() == PREVIOUS_ICON_PRESSED)
            previousSprite.setFrame(PREVIOUS_ICON);

          bluetoothPlayer.addCommandToProcess(BluetoothPlayer.COMMAND_PREV);
          previousPressed = false;

          if (bluetoothPlayer.getTotalTime() != 0) // jesli utwor jest odtwarzany lub zapauzowany
          playPauseSprite.setFrame(PAUSE_ICON);
        }
        // jesli przycisk 'Up' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & UP_PRESSED) != 0)
            && (previousPressed == false)
            && (nextPressed == false)
            && (firePressed == false)) {
          if (previousPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          bluetoothPlayer.volumeUp();
        }
        // jesli przycisk 'Down' jest wcisniety, a pozostale nie sa wcisniete
        if (((keys & DOWN_PRESSED) != 0)
            && (previousPressed == false)
            && (nextPressed == false)
            && (firePressed == false)) {
          if (previousPressed == false) {
            soundPlayer.play(SoundPlayer.CLICK_SOUND);
          }

          bluetoothPlayer.volumeDown();
        }
      }
    }
    // jesli wyswietlany jest ekran biblioteki muzycznej
    if (displayedScreen == MEDIA_LIBRARY_SCREEN) {
      // jesli przycisk akcji jest wcisniety, a pozostale nie sa wcisniete
      if (((keys & FIRE_PRESSED) != 0) && (nextPressed == false) && (previousPressed == false)) {
        buttonPressedInARowCount = 0;
        if (firePressed == false) soundPlayer.play(SoundPlayer.CLICK_SOUND);
        firePressed = true;
      }
      // przycisk zostal zwolniony
      else if (((keys & FIRE_PRESSED) == 0) && (firePressed == true)) {
        buttonPressedInARowCount = 0;
        firePressed = false;
      }
      // jesli przycisk 'Down' jest wcisniety, a pozostale nie sa wcisniete
      if (((keys & DOWN_PRESSED) != 0) && (firePressed == false) && (previousPressed == false)) {
        if (nextPressed == true) buttonPressedInARowCount++;
        else buttonPressedInARowCount = 0;
        nextPressed = true;
      }
      // button was released or hold down for more than MAX_BUTTON_PRESSED_IN_A_ROW_COUNT clicks
      if ((((keys & DOWN_PRESSED) == 0) && (nextPressed == true))
          || (((keys & DOWN_PRESSED) != 0)
              && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))) {
        // jesli wybrany utwor nie byl ostatni na liscie
        if (bluetoothPlayer.getMediaLibrary().selectItemInMediaLibrary(NEXT_ITEM) == true) {
          if (mediaLibrarySelectedItemOnScreen < mediaLibraryItemsNumberOnScreen - 1)
            mediaLibrarySelectedItemOnScreen++;
        }

        // nextPressed is set to false only if button was released
        if ((((keys & DOWN_PRESSED) != 0)
                && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))
            == false) nextPressed = false;
      }

      // jesli przycisk 'Previous' jest wcisniety, a pozostale nie sa wcisniete
      if (((keys & UP_PRESSED) != 0) && (nextPressed == false) && (firePressed == false)) {
        if (previousPressed == true) buttonPressedInARowCount++;
        else buttonPressedInARowCount = 0;
        previousPressed = true;
      }

      // button was released or hold down for more than MAX_BUTTON_PRESSED_IN_A_ROW_COUNT clicks
      if ((((keys & UP_PRESSED) == 0) && (previousPressed == true))
          || (((keys & UP_PRESSED) != 0)
              && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))) {

        // jesli wybrany utwor nie byl pierwszy na liscie
        if (bluetoothPlayer.getMediaLibrary().selectItemInMediaLibrary(PREVIOUS_ITEM) == true) {
          if (mediaLibrarySelectedItemOnScreen > 0) mediaLibrarySelectedItemOnScreen--;
        }

        // previousPressed is set to false only if button was released
        if ((((keys & UP_PRESSED) != 0)
                && (buttonPressedInARowCount >= MAX_BUTTON_PRESSED_IN_A_ROW_COUNT))
            == false) previousPressed = false;
      }
    }
    // if volume level has changed
    if (volumeLevel != bluetoothPlayer.getVolumeLevel()) {
      showVolume = 15;
      volumeLevel = bluetoothPlayer.getVolumeLevel();
    }

    if (bluetoothPlayer.getIsConnectedToServer() == false) {
      if (buttonsLocation < 70) buttonsLocation += 5;
    }

    if ((bluetoothPlayer.getIsConnectedToServer() == true) && (buttonsLocation > 0)) {
      buttonsLocation -= 5;
    }

    if (bluetoothPlayer.getStateChanged()) {
      String state = bluetoothPlayer.getPlayingState();

      if (state != null) {
        if (state.equals("PLAY") || state.equals("OTHER")) {
          playPauseSprite.setFrame(PAUSE_ICON);
        } else if (state.equals("PAUSE") || state.equals("STOP"))
          playPauseSprite.setFrame(PLAY_ICON);
      }

      soundPlayer.play(SoundPlayer.POPUP_SOUND);
    }
  }
Example #17
0
 public boolean collidesWith(Sprite s, boolean pixelLevel) {
   java.awt.Rectangle r1 =
       new java.awt.Rectangle(this.getX(), this.getY(), getWidth(), getHeight());
   java.awt.Rectangle r2 = new java.awt.Rectangle(s.getX(), s.getY(), s.getWidth(), s.getHeight());
   return r1.intersects(r2);
 }
  /**
   * respond to keystrokes by deciding where to move and then moving the pieces and the view window
   * correspondingly.
   */
  public void requestMove(int hdirection, int vdirection) {
    // vdirection < 0 indicates that the user has
    // pressed the UP button and would like to jump.
    // therefore, if we're not currently jumping,
    // we begin the jump.
    if ((myIsJumping == NO_JUMP) && (vdirection < 0)) {
      myIsJumping++;
    } else if (myIsJumping == NO_JUMP) {
      // if we're not jumping at all, we need to check
      // if the duke should be falling:
      // we (temporarily) move the duke down and see if that
      // causes a collision with the floor:
      dukeSprite.move(0, 1);
      // if the duke can move down without colliding
      // with the floor, then we set the duke to
      // be falling.  The variable myIsJumping starts
      // negative while the duke is jumping up and
      // is zero or positive when the duke is coming
      // back down.  We therefore set myIsJumping to
      // zero to indicate that the duke should start
      // falling.
      if (!checkCollision()) {
        myIsJumping = 0;
      }
      // we move the duke Sprite back to the correct
      // position she was at before we (temporarily) moved
      // her down to see if she would fall.
      dukeSprite.move(0, -1);
    }
    // if the duke is currently jumping or falling,
    // advance the jump (change the vertical distance
    // the duke is supposed to move)
    if ((myIsJumping <= MAX_FREE_FALL) && (myIsJumping != NO_JUMP)) {
      myIsJumping++;
    }
    // also accellerate the horizontal motion if the duke
    // runs runs in the same horizontal direction for more than
    // one game tick:
    myIsRunning++;
    // But don't accellerate past the maximum speed:
    if (myIsRunning > MAX_SPEED) {
      myIsRunning = MAX_SPEED;
    }
    int horizontal = MOVE_LENGTH * myIsRunning;
    // if the duke is currently jumping or falling,
    // we calculate the vertical distance she should move.
    // This is a parabola given by y = (x*x) * (a + b/c)
    // where x is how far we have advanced in the jump
    // or fall (myIsJumping), and a, b, and c are constants
    // based on the screen size. (The actual values are
    // read from a properties file and were originally
    // computed through trial and error.)
    int vertical = 0;
    if (myIsJumping != NO_JUMP) {
      vertical =
          myIsJumping * myIsJumping * JUMP_INT
              + (myIsJumping * myIsJumping * JUMP_FRAC_NUM) / JUMP_FRAC_DENOM;
      // for the first half of the jump we go up,
      // then for the second half go down:
      if (myIsJumping < 0) {
        vdirection = -1;
      } else {
        vdirection = 1;
      }
    }
    // set the sprite to the correct frame based
    // on the duke's current motion:
    updateSprite(hdirection, vdirection);
    boolean vcrash = false;
    boolean hcrash = false;
    // now calculate the motion one pixel at a time
    // (vertically then horizontally) to see precisely
    // how far the duke can move in each of the
    // requested directions:
    while ((vertical >= 1 && !vcrash) || (horizontal >= 1 && !hcrash)) {
      dukeSprite.move(0, vdirection);
      if (checkCollision()) {
        dukeSprite.move(0, -vdirection);
        vcrash = true;
      } else {
        vertical -= 1;
        vcrash = false;
        myViewWindowY += vdirection;
      }
      dukeSprite.move(MOVE_BUFFER * hdirection, 0);
      if (checkCollision()) {
        dukeSprite.move(-MOVE_BUFFER * hdirection, 0);
        hcrash = true;
      } else {
        dukeSprite.move(-MOVE_BUFFER * hdirection, 0);
        dukeSprite.move(hdirection, 0);
        horizontal -= 1;
        hcrash = false;
        myViewWindowX += hdirection;
      }
    }
    // If the duke is blocked vertically,
    // then the jump or fall in progress stops:
    if (vcrash) {
      myIsJumping = NO_JUMP;
    }
    // If the duke is blocked horizontally,
    // forget any horizontal accelleration:
    if (hcrash) {
      myIsRunning = 0;
    }

    if (dukeSprite.collidesWith(jamesSprite, true)) {
      myCanvas.setGameOver();
      return;
    }
  }
Example #19
0
  @Override
  public void paintComponent(Graphics2D g) {

    int csrc = myrisk.hasArmiesInt(c1num);
    int cdes = myrisk.hasArmiesInt(c2num);
    int color1 = myrisk.getColorOfOwner(c1num);
    int color2 = myrisk.getColorOfOwner(c2num);

    int imageAreaHeight = getImageAreaHeight();
    int heightOfComponents =
        ((MoveDialog.DialogLayout) getContentPane().getLayout())
            .getHeightOfComponents(getContentPane());
    // this is the MIDDLE of the images area
    int xOffset = getContentPane().getWidth() / 2;
    int yOffset =
        (getContentPane().getHeight() - heightOfComponents) / 2
            + imageAreaHeight / 4
            + getContentPane().getY();

    // g.setColor(0xFFFF0000);
    // g.drawRect( (getContentPane().getWidth()-imageAreaHeight)/2 ,
    // (getContentPane().getHeight()-heightOfComponents)/2 + getContentPane().getY(),
    // imageAreaHeight, imageAreaHeight);

    MoveDialog.paintMove(
        g,
        xOffset,
        yOffset,
        c1img,
        c2img,
        color1,
        color2,
        myrisk.getCountryCapital(c1num),
        myrisk.getCountryCapital(c2num),
        myrisk.getCountryName(c1num),
        myrisk.getCountryName(c2num),
        csrc,
        cdes,
        0);

    // #####################################################
    // ################## drawing DICE!!!!! ################

    int[] diceXs = getDiceX();
    int ax = diceXs[0], dx = diceXs[1];

    int y1 = yOffset + imageAreaHeight / 4; // top of dice
    int y2 = y1 + red_dice.getHeight() + XULLoader.adjustSizeToDensity(2);
    int y3 = y2 + red_dice.getHeight() + XULLoader.adjustSizeToDensity(2);

    // just in case in the middle of the draw the att and def get set to null
    int[] atti = att;
    int[] defi = def;

    // this is the max defend dice allowed for this battle
    int deadDice = myrisk.hasArmiesInt(c2num);
    if (deadDice > myrisk.getGame().getMaxDefendDice()) {
      deadDice = myrisk.getGame().getMaxDefendDice();
    }

    // if we need input
    if (max != 0) {
      // selecting the number of attacking dice
      if (canRetreat) {
        g.drawSprite(red_dice, DICE_NORMAL, ax, y1);

        if (noda > 1) {
          g.drawSprite(red_dice, DICE_NORMAL, ax, y2);
        } else if (max > 1) {
          g.drawSprite(red_dice, DICE_DARK, ax, y2);
        }

        if (noda > 2) {
          g.drawSprite(red_dice, DICE_NORMAL, ax, y3);
        } else if (max > 2) {
          g.drawSprite(red_dice, DICE_DARK, ax, y3);
        }

        // draw the dead dice
        g.drawSprite(blue_dice, DICE_DARK, dx, y1);
        if (deadDice > 1) {
          g.drawSprite(blue_dice, DICE_DARK, dx, y2);
        }
        if (deadDice > 2) {
          g.drawSprite(blue_dice, DICE_DARK, dx, y3);
        }
      }
      // selecting the number of dice to defend
      else {
        g.drawSprite(blue_dice, DICE_NORMAL, dx, y1);

        if (nodd > 1) {
          g.drawSprite(blue_dice, DICE_NORMAL, dx, y2);
        } else if (max > 1) {
          g.drawSprite(blue_dice, DICE_DARK, dx, y2);
        }

        if (nodd > 2) {
          g.drawSprite(blue_dice, DICE_NORMAL, dx, y3);
        } else if (max > 2) {
          g.drawSprite(blue_dice, DICE_DARK, dx, y3);
        }
      }
    }
    // battle open and waiting for the attacker to select there number of dice
    else if (atti == null && defi == null && !spinD) {

      // draw the dead dice
      g.drawSprite(blue_dice, DICE_DARK, dx, y1);
      if (deadDice > 1) {
        g.drawSprite(blue_dice, DICE_DARK, dx, y2);
      }
      if (deadDice > 2) {
        g.drawSprite(blue_dice, DICE_DARK, dx, y3);
      }

      if (!spinA) {
        // draw dead dice for attacker
        int AdeadDice = myrisk.hasArmiesInt(c1num) - 1;
        // we assume that the attacker can attack with max of 3 dice

        g.drawSprite(red_dice, DICE_DARK, ax, y1);
        if (AdeadDice > 1) {
          g.drawSprite(red_dice, DICE_DARK, ax, y2);
        }
        if (AdeadDice > 2) {
          g.drawSprite(red_dice, DICE_DARK, ax, y3);
        }
      }
    }

    // #####################################################
    // ##################### END DICE ######################

    final int SPINS_OFFSET = 3;

    if (spinA) {
      g.drawSprite(red_dice, SPINS_OFFSET + r.nextInt(6), ax, y1);
      if (noda > 1) {
        g.drawSprite(red_dice, SPINS_OFFSET + r.nextInt(6), ax, y2);
      }
      if (noda > 2) {
        g.drawSprite(red_dice, SPINS_OFFSET + r.nextInt(6), ax, y3);
      }
      // g.drawString("ROLLING ATTACKER " + noda +"    " + Math.random() , 50, 100);

      if (spinD) {
        g.drawSprite(blue_dice, SPINS_OFFSET + r.nextInt(6), dx, y1);
        if (nodd > 1) {
          g.drawSprite(blue_dice, SPINS_OFFSET + r.nextInt(6), dx, y2);
        }
        if (nodd > 2) {
          g.drawSprite(blue_dice, SPINS_OFFSET + r.nextInt(6), dx, y3);
        }
        // g.drawString("ROLLING DEFENDER " + nodd +"    " + Math.random(), 300, 100);
      }
    }

    DirectGraphics g2 = DirectUtils.getDirectGraphics(g.getGraphics());

    int offset = (int) (red_dice.getWidth() / (29D / 4D) + 0.5);
    int bottom = red_dice.getHeight() - offset - 1; // TODO not sure why -1??
    int halfDice = red_dice.getHeight() / 2;

    if (atti != null && defi != null) {
      {
        int yCoords[] = {y1 + offset, y1 + bottom, y1 + halfDice};
        if (defi[0] >= atti[0]) {
          int xCoords[] = {dx + offset, dx + offset, ax + bottom};
          g2.fillPolygon(xCoords, 0, yCoords, 0, xCoords.length, COLOR_BLUE);
        } else {
          int xCoords[] = {ax + bottom, ax + bottom, dx + offset};
          g2.fillPolygon(xCoords, 0, yCoords, 0, xCoords.length, COLOR_RED);
        }
      }
      if (atti.length > 1 && defi.length > 1) {
        int yCoords[] = {y2 + offset, y2 + bottom, y2 + halfDice};
        if (defi[1] >= atti[1]) {
          int xCoords[] = {dx + offset, dx + offset, ax + bottom};
          g2.fillPolygon(xCoords, 0, yCoords, 0, xCoords.length, COLOR_BLUE);
        } else {
          int xCoords[] = {ax + bottom, ax + bottom, dx + offset};
          g2.fillPolygon(xCoords, 0, yCoords, 0, xCoords.length, COLOR_RED);
        }
      }
      if (atti.length > 2 && defi.length > 2) {
        int yCoords[] = {y3 + offset, y3 + bottom, y3 + halfDice};
        if (defi[2] >= atti[2]) {
          int xCoords[] = {dx + offset, dx + offset, ax + bottom};
          g2.fillPolygon(xCoords, 0, yCoords, 0, xCoords.length, COLOR_BLUE);
        } else {
          int xCoords[] = {ax + bottom, ax + bottom, dx + offset};
          g2.fillPolygon(xCoords, 0, yCoords, 0, xCoords.length, COLOR_RED);
        }
      }

      // draw attacker dice
      drawDice(true, atti[0], ax, y1, g);
      if (atti.length > 1) {
        drawDice(true, atti[1], ax, y2, g);
      }
      if (atti.length > 2) {
        drawDice(true, atti[2], ax, y3, g);
      }

      // draw defender dice
      drawDice(false, defi[0], dx, y1, g);
      if (defi.length > 1) {
        drawDice(false, defi[1], dx, y2, g);
      }
      if (defi.length > 2) {
        drawDice(false, defi[2], dx, y3, g);
      }
    }
  }
  /** Checks of the player hits a stone wall or a door. */
  boolean checkCollision() {

    return dukeSprite.collidesWith(myWalls, true);
  }
Example #21
0
 public int getSizeX() {
   return sprite.getWidth();
 }
Example #22
0
 public int getSizeY() {
   return sprite.getHeight();
 }
Example #23
0
 // 判斷選取的選單選項
 public void changeMeunStart() {
   try {
     if (page == -1) {
       switch (menustate) {
         case 0:
           page = 0;
           spName.setVisible(true);
           changePage();
           break;
         case 1:
           page = 0;
           spName.setVisible(true);
           changePage();
           break;
         case 2:
           // spWelcome.setVisible(false);
           spName.setVisible(false);
           spInterface.setFrame(4);
           drawDisplay();
           GameMain.music.stop();
           exit();
           break;
       }
     } else {
       switch (menustate) {
         case 0:
           try {
             new InputText(nowString[0]);
           } catch (Exception e) {
             e.printStackTrace();
           }
           break;
         case 1:
           new InputText(nowString[1]);
           break;
         case 2: // 登入
           if (page == 0) { // 當在輸入帳號畫面時
             // 未輸入帳號
             if (username.equals("") || pass.equals("")) {
               g.drawString("「請 輸入帳號密碼」", disWidth + 75, disHeight + 140, 0);
               flushGraphics();
             } else if (username.equals("xlinx") && pass.equals("x")) {
               runGame();
               g.drawString("進入遊戲...", disWidth + 15, disHeight + 129, 0);
               flushGraphics();
             } else { // 連到Server
               try {
                 GameMain.conn.setLoginAccess(username, pass); // 送出帳號密碼
               } catch (Exception e) {
                 e.printStackTrace();
               }
               g.setColor(255, 255, 255);
               g.drawString("「登入中」", disWidth + 95, disHeight + 140, 0);
               flushGraphics();
               while (!ConnectionServer.connFin) ; // Server是否回傳完資訊
               page = 0;
               drawDisplay();
               g.setColor(255, 255, 255);
               gameUserInfCount = 0;
               // 成功登入將繼續到下一頁面(第一次進入遊戲)
               if (GameMain.conn.getConnSucess() == 1) {
                 g.drawString("「登入成功」", disWidth + 95, disHeight + 140, 0);
                 flushGraphics();
                 RoleDataValue.userpass = pass;
                 page = 1;
                 changePage();
               } else if (GameMain.conn.getConnSucess() == 0) { // 登入,不是第一次遊戲
                 try {
                   page = -2;
                   g.drawString("「登入成功」", disWidth + 95, disHeight + 140, 0);
                   flushGraphics();
                   RoleDataValue.userpass = pass;
                   g.drawString("讀取使用者資料....", disWidth + 15, disHeight + 69, 0);
                   flushGraphics();
                   GameMain.conn.setGameName("");
                   while (!ConnectionServer.connFin) ; // Server是否回傳完資訊
                   g.drawString("人物狀態初始化.....", disWidth + 15, disHeight + 89, 0);
                   flushGraphics();
                   roleData.getFirstRoleStateForInternet(GameMain.conn.getRequestState());
                   roleData.loginSuccessStart();
                   g.drawString("地圖初始化..........", disWidth + 15, disHeight + 109, 0);
                   flushGraphics();
                 } catch (Exception e) {
                   e.printStackTrace();
                 }
                 runGame();
                 g.drawString("進入遊戲...", disWidth + 15, disHeight + 129, 0);
                 flushGraphics();
               } else {
                 g.drawString("「登入失敗」", disWidth + 95, disHeight + 140, 0);
                 flushGraphics();
               }
             }
           } else if (page == 1) { // 當畫面在遊戲說明時
             if (gameUserInfCount < gameUserInf.length) // 如果遊戲說明未結速時
             changePage();
             else { // 遊戲說明完成,畫面改變為輸入遊戲名稱
               page = 2;
               gameUserInfCount = 20;
               changePage();
             }
           } else if (page == 2) { // 輸入名稱完成,畫面改變為角色建立完成
             if (nickname.equals("")) g.drawString("「請輸入名稱」", disWidth + 90, disHeight + 140, 0);
             else {
               page = 3;
               changePage();
             }
           } else if (page == 3) { // 第一進入遊戲,完成輸入名稱
             page = -2;
             GameMain.conn.setGameName(nickname);
             while (!ConnectionServer.connFin) ; // Server是否回傳完資訊
             try {
               roleData.getFirstRoleStateForInternet(GameMain.conn.getRequestState());
               roleData.loginSuccessStart();
             } catch (Exception e) {
               e.printStackTrace();
             }
             runGame();
           }
           break;
         case 3: // 回主選單,上一頁
           if (page == 0) {
             page = -1;
             menustate = 0;
             menuNum = 3;
           }
           // 判斷當為GameInformation時,要回輸入帳號密碼
           if (page == 1 && gameUserInfCount == 5) page--;
           else if (page == 2 || page == 3) // 判斷當不是GameInformation時
           page--;
           // 切換GameInformaion的頁面
           if (page == 1) {
             gameUserInfCount -= 5 * gameUserInfPage;
             gameUserInfPage++;
             if (gameUserInfPage >= 3) gameUserInfPage = 2;
             changePage();
           } // 回到輸入姓名部份
           else if (page == 2) {
             // rolesprite=true;
             Thread.sleep(300);
             gameUserInfPage = 2;
             changePage();
           } else changePage();
           break;
       }
       showBufferString();
     }
   } catch (Exception e) {
   }
 }