コード例 #1
0
ファイル: BattleDialog.java プロジェクト: hernol/ConuWar
  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;
  }
コード例 #2
0
ファイル: Animation.java プロジェクト: bernadetaanjani/jgeek
 public int getSizeY() {
   return sprite.getHeight();
 }
コード例 #3
0
ファイル: BattleDialog.java プロジェクト: hernol/ConuWar
  @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);
      }
    }
  }
コード例 #4
0
ファイル: Sprite.java プロジェクト: papog/Microlib
 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);
 }