Example #1
0
  // Initialization of the Battle State
  public BattleState(Framework framework, BattleEnemy enemy) {
    windowWidth = framework.getWidth();
    windowHeight = framework.getHeight();
    this.enemy = enemy;
    turn = 0;
    turnState = 0;
    Font buttonFont = new Font("Arial", Font.BOLD, 15);
    int xButtonSpacing = 40;
    int yButtonSpacing = 35;
    cardButton =
        new MenuButton(
            "Cast Card",
            xButtonSpacing,
            3 * windowHeight / 4 + yButtonSpacing,
            buttonFont,
            (Graphics2D) framework.getGraphics(),
            5,
            5);
    itemButton =
        new MenuButton(
            "Use Item",
            xButtonSpacing,
            cardButton.getY() + cardButton.getHeight() + yButtonSpacing,
            buttonFont,
            (Graphics2D) framework.getGraphics(),
            5,
            5);
    drawButton =
        new MenuButton(
            "Draw Card",
            cardButton.getX() + cardButton.getWidth() + xButtonSpacing,
            cardButton.getY(),
            buttonFont,
            (Graphics2D) framework.getGraphics(),
            5,
            5);
    runButton =
        new MenuButton(
            "Run",
            cardButton.getX() + cardButton.getWidth() + xButtonSpacing,
            cardButton.getY() + cardButton.getHeight() + yButtonSpacing,
            buttonFont,
            (Graphics2D) framework.getGraphics(),
            5,
            5);
    buttonWidth = drawButton.getWidth();
    int buttonHeight = drawButton.getHeight();
    cardButton.setWidth(buttonWidth);
    itemButton.setWidth(buttonWidth);
    runButton.setWidth(buttonWidth);
    drawButton.setPosition(
        cardButton.getX() + cardButton.getWidth() + xButtonSpacing, drawButton.getY());
    runButton.setPosition(
        cardButton.getX() + cardButton.getWidth() + xButtonSpacing, runButton.getY());
    int scrollerBuffer = 5;
    BufferedImage scrollerImage = null;
    // Load the Scroller Image
    try {
      scrollerImage =
          ImageIO.read(this.getClass().getResource("/resources/images/pointerFinger.png"));
    } catch (IOException ex) {
      Logger.getLogger(Framework.class.getName()).log(Level.SEVERE, null, ex);
    }
    actionScroller =
        new MenuScroller2D(
            scrollerImage,
            cardButton.getX() - scrollerBuffer,
            cardButton.getY(),
            buttonWidth + xButtonSpacing,
            buttonHeight + yButtonSpacing,
            2,
            2,
            4,
            1,
            1);
    actionScroller.setWidth(cardButton.getHeight());
    actionScroller.setHeight(cardButton.getHeight());
    actionScroller.setPosition(
        cardButton.getX() - actionScroller.getWidth() - scrollerBuffer, cardButton.getY());
    enemyImage = enemy.getBattleImage();
    mainCharacterImage = StartGameState.character.getBattleImage();
    SoundManager.add(
        "BattleMusic",
        new Sound(this.getClass().getResource("/resources/sounds/Woodland_Fantasy_0.wav"), 0));
    hand = new IndexedLinkedHashMap<>();
    deckCount = 0;
    if (MainCharacter.maxHand <= MainCharacter.deck.size()) {
      for (int i = 0; i < MainCharacter.maxHand; i++) {
        hand.put(i, MainCharacter.deck.get(i));
        deckCount++;
      }
    } else {
      for (int i = 0; i < MainCharacter.deck.size(); i++) {
        hand.put(i, MainCharacter.deck.get(i));
        deckCount++;
      }
    }
    try {
      cardBack =
          ImageIO.read(
              this.getClass()
                  .getResource("/resources/images/Cards/40X56 Card Frames Revised/Card_Back.png"));
    } catch (IOException ex) {
      Logger.getLogger(Framework.class.getName()).log(Level.SEVERE, null, ex);
    }
    int x = drawButton.getX() + drawButton.getWidth() + 40;
    cardWidth = 3 * windowWidth / 4 - 2 * 15 - cardBack.getWidth() - x;
    int cardSpacing = cardWidth / hand.size();
    cardScroller =
        new MenuScroller2D(
            scrollerImage,
            drawButton.getX() + drawButton.getWidth() + 10,
            drawButton.getY() + hand.getIndexed(0).getHeight() / 2 - 10,
            cardSpacing,
            0,
            deckCount,
            1,
            deckCount,
            1,
            1);
    cardScroller.setWidth(actionScroller.getWidth());
    cardScroller.setHeight(actionScroller.getHeight());
    deckScroller =
        new MenuScroller2D(
            scrollerImage,
            3 * windowWidth / 4 - 15 - cardBack.getWidth() - 10 - actionScroller.getWidth(),
            drawButton.getY() + hand.getIndexed(0).getHeight() / 2 - 10,
            0,
            0,
            1,
            1,
            1,
            1,
            1);

    deckScroller.setWidth(actionScroller.getWidth());
    deckScroller.setHeight(actionScroller.getHeight());
    shouldWait = false;
    drawNoMana = false;
    drawNoCards = false;
    drawItemUsed = false;
    drawParalyzed = false;
    enemyMoveChosen = false;
    itemMenu = new ItemsMenu(framework);
  }