Ejemplo n.º 1
0
  /**
   * Loads a font based on file path
   *
   * @param String filePath
   * @param float fontSize
   * @param FontStyle fontStyle
   * @throws FontFormatException
   * @throws IOException
   */
  public INFont(String filePath, float fontSize, FontStyle fontStyle)
      throws FontFormatException, IOException {
    File fontFile = new File(filePath);

    this.loadedFont = Font.createFont(Font.TRUETYPE_FONT, fontFile);
    this.loadedFont = this.loadedFont.deriveFont(fontSize);

    this.style = fontStyle;
    this.size = fontSize;

    switch (fontStyle) {
      case BOLD:
        this.loadedFont = this.loadedFont.deriveFont(Font.BOLD);
        break;
      case ITALIC:
        this.loadedFont = this.loadedFont.deriveFont(Font.ITALIC);
        break;
      case PLAIN:
        this.loadedFont = this.loadedFont.deriveFont(Font.PLAIN);
        break;
      case BOLDANDITALIC:
        this.loadedFont = this.loadedFont.deriveFont(Font.BOLD + Font.ITALIC);
        break;
    }
  }
Ejemplo n.º 2
0
  /**
   * Create a new font data element
   *
   * @param ttf The TTF file to read
   * @param size The size of the new font
   * @throws java.io.IOException Indicates a failure to
   */
  private FontData(InputStream ttf, float size) throws IOException {
    if (ttf.available() > MAX_FILE_SIZE) {
      throw new IOException("Can't load font - too big");
    }
    byte[] data = IOUtils.toByteArray(ttf);
    if (data.length > MAX_FILE_SIZE) {
      throw new IOException("Can't load font - too big");
    }

    this.size = size;
    try {
      javaFont = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(data));
      TTFFile rawFont = new TTFFile();
      if (!rawFont.readFont(new FontFileReader(data))) {
        throw new IOException("Invalid font file");
      }
      upem = rawFont.getUPEM();
      ansiKerning = rawFont.getAnsiKerning();
      charWidth = rawFont.getAnsiWidth();
      fontName = rawFont.getPostScriptName();
      familyName = rawFont.getFamilyName();

      String name = getName();
      System.err.println("Loaded: " + name + " (" + data.length + ")");
      boolean bo = false;
      boolean it = false;
      if (name.indexOf(',') >= 0) {
        name = name.substring(name.indexOf(','));

        if (name.indexOf("Bold") >= 0) {
          bo = true;
        }
        if (name.indexOf("Italic") >= 0) {
          it = true;
        }
      }

      if ((bo & it)) {
        javaFont = javaFont.deriveFont(Font.BOLD | Font.ITALIC);
      } else if (bo) {
        javaFont = javaFont.deriveFont(Font.BOLD);
      } else if (it) {
        javaFont = javaFont.deriveFont(Font.ITALIC);
      }
    } catch (FontFormatException e) {
      IOException x = new IOException("Failed to read font");
      x.initCause(e);
      throw x;
    }
  }
Ejemplo n.º 3
0
  private void addFont(String fontKey, String fontName, float scale) {
    try {
      fontName = fontName.toLowerCase();

      FileInputStream stream = new FileInputStream("data/fonts/ttf/" + fontName + ".ttf");

      Font f = Font.createFont(Font.TRUETYPE_FONT, stream);
      f = f.deriveFont(scale);

      fonts.put(fontKey, f);
      stream.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 4
0
  public MancalaPanel(LetsPlayMancala game) {

    // ------------------------------------------------------------------------------
    // Import font "Belta Regular"
    // -----------------------------------------------------------------------------
    try {
      InputStream in = MancalaPanel.class.getResourceAsStream("belta-regular.ttf");
      Font font = Font.createFont(Font.TRUETYPE_FONT, in);
    } catch (Exception ex) {
      System.out.println("Font couldn't be loaded.");
    }

    // ----------------------------------------------------------------------------
    // Set background image
    // ----------------------------------------------------------------------------
    imageFile = "/Images/GameBackground.png";
    this.game = game;
    SMALL_PIT_COUNT = 12;

    setLayout(new BorderLayout());

    add(northWindowPanel(), BorderLayout.NORTH);
    add(westWindowPanel(), BorderLayout.WEST);
    add(makeBoardPanel(), BorderLayout.CENTER);
    add(eastWindowPanel(), BorderLayout.EAST);
    add(southWindowPanel(), BorderLayout.SOUTH);

    winners = new LinkedStack<String>();
    winnersLabel = new JLabel();

    resultFrame = new JFrame();
    boardResultPanel = new BkImagePanel("/Images/board2.png");
    resultNorth = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 50));
    resultNorth.setOpaque(false);
    resultCenter = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
    resultCenter.setOpaque(false);
    resultSouth = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 20));
    resultSouth.setOpaque(false);

    playAgainBtn.setPreferredSize(new Dimension(240, 80));
    playAgainBtn.setBackground(new Color(135, 17, 76));
    playAgainBtn.setForeground(Color.white);
    playAgainBtn.setBorder(BorderFactory.createLineBorder(Color.white, 6));
    playAgainBtn.setFont(new Font("Belta Regular", Font.BOLD, 40));
    playAgainBtn.addActionListener(new ButtonListener());

    scoresBtn.setPreferredSize(new Dimension(340, 80));
    scoresBtn.setBorder(BorderFactory.createLineBorder(Color.white, 6));
    scoresBtn.addActionListener(new ButtonListener());

    quitBtn.setPreferredSize(new Dimension(150, 80));
    quitBtn.setBorder(BorderFactory.createLineBorder(Color.white, 6));
    quitBtn.addActionListener(new ButtonListener());

    result = new JLabel();
    result.setFont(new Font("Belta Regular", Font.BOLD, 40));
    result.setForeground(Color.white);
    result.setBackground(new Color(0, 158, 121));
    result.setBorder(BorderFactory.createLineBorder(Color.white, 6));
    result.setOpaque(true);
    result.setPreferredSize(new Dimension(380, 80));

    winnersLabel = new JLabel();
    winnersLabel.setFont(new Font("Belta Regular", Font.BOLD, 40));
    winnersLabel.setForeground(Color.white);
    winnersLabel.setPreferredSize(new Dimension(420, 200));

    boardResultPanel.setLayout(new BorderLayout(50, 50));
    boardResultPanel.setPreferredSize(new Dimension(800, 700));
    boardResultPanel.setBackground(Color.yellow);
    boardResultPanel.add(resultNorth, BorderLayout.NORTH);
    boardResultPanel.add(resultCenter, BorderLayout.CENTER);
    boardResultPanel.add(resultSouth, BorderLayout.SOUTH);

    resultCenter.add(winnersLabel);
    resultSouth.add(scoresBtn);
    resultSouth.add(playAgainBtn);
    resultSouth.add(quitBtn);

    resultFrame.add(boardResultPanel);
  }
Ejemplo n.º 5
0
  public GamePanel(String name, int l) {
    setFocusable(true);
    grabFocus();
    addMouseListener(this);
    addMouseMotionListener(this);
    addKeyListener(this);
    keys = new boolean[10000];

    try {
      scoreFont =
          Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(new File("BRLNSB.ttf")))
              .deriveFont(0, 32);
    } catch (IOException ioe) {
      System.out.println("error loading BRLNSB.tff");
    } catch (FontFormatException ffe) {
      System.out.println("Something went wrong with the font.");
    }

    gameBckgrnd = new ImageIcon("Backgroundimage.png").getImage();
    for (int i = 1; i < 7; i++) {
      magnetList.add(new ImageIcon("gamelayerstuff/powerups/magnet" + i + ".png").getImage());
    }

    coinPic = new ImageIcon("gamelayerstuff/coins/byellowcoin1.png").getImage();
    player1 = new Player(200, 300, 100, "sheldon");

    click = false;
    ground = true;
    pause = false;
    lvlClear = false;
    die = false;
    musicOn = true;

    player1.setVelo(150);
    player1.setInvi(true);
    // ------------------------------------------------------------------------------------------------------------------------------------
    // Sound
    coinSound = Applet.newAudioClip(getClass().getResource("coin_pickup_2.wav"));
    clicked = Applet.newAudioClip(getClass().getResource("menu_deselect.wav"));
    starSound = Applet.newAudioClip(getClass().getResource("star.wav"));
    bounce = Applet.newAudioClip(getClass().getResource("grav_step_4.wav"));
    bckGrndMusic = Applet.newAudioClip(getClass().getResource("bgmusic00.wav"));
    bckGrndMusic.loop();
    // ------------------------------------------------------------------------------------------------------------------------------------

    // distance=0;
    score = 0;
    coins = 0;
    level = 1;
    prevLvl = level;
    backy = 0;
    height = backy;
    dieHeight = 0;
    dieMenuHeight = 0;

    pauseB = new SButton(400, 670, "pause", "");
    resumeB = new SButton(100, 500, "resume", "");
    menuB = new SButton(100, 620, "back", "");
    muteB = new SButton(400, 600, "mute", "");
    unmuteB = new SButton(400, 600, "unmute", "");
    // System.out.println("characters/"+name+"/"+name+"35.png");
  }