@SuppressWarnings("unchecked") public GameOver(String text, int score, boolean victory) { this.text = text; this.score = score; this.victory = victory; font = new UnicodeFont(Database.instance().getDefaultFont().getFont(), 50, true, false); font.addAsciiGlyphs(); font.getEffects().add(new ColorEffect()); try { font.loadGlyphs(); } catch (SlickException e1) { e1.printStackTrace(); } nameInput = new TextField( GameCore.getInstance().getApp(), Database.instance().getDefaultFont(), 150, 20, 500, Database.instance().getDefaultFont().getLineHeight() + 20, new ComponentListener() { public void componentActivated(AbstractComponent source) { input = nameInput.getText(); } }); nameInput.setFocus(true); nameInput.setBorderColor(Color.black); nameInput.setText("Anonymous"); nameInput.setMaxLength(20); }
public ConsoleGuiNewChat(Minecraft par1Minecraft) { this.mc = par1Minecraft; font = new UnicodeFont(new Font("Arial Bold", Font.TRUETYPE_FONT, 16)); font.addAsciiGlyphs(); font.getEffects().add(new ColorEffect(java.awt.Color.white)); try { font.loadGlyphs(); } catch (Exception e) { } }
public Fuente(Font fuente, int tamano) throws SlickException { this.tamano = tamano; uFont = new UnicodeFont(fuente, this.tamano, this.italica, this.negrita); uFont.addAsciiGlyphs(); uFont.addGlyphs(400, 600); uFont.getEffects().add(new ColorEffect(this.color)); uFont.loadGlyphs(); cargado = true; }
public RendererText() { Font awtFont = new Font("Consola", Font.BOLD, 18); unicodeFont = new UnicodeFont(awtFont); unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.white)); unicodeFont.addAsciiGlyphs(); try { unicodeFont.loadGlyphs(); } catch (SlickException e) { e.printStackTrace(); } }
public void renderStringWithShadow( float paramXpos, float paramYpos, String paramStringToRender, Color paramColor) { GL11.glPushMatrix(); GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glTranslatef(paramXpos, paramYpos, 0); unicodeFont.drawString(1, -1, paramStringToRender, Color.black); unicodeFont.drawString(0, 0, paramStringToRender, paramColor); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_BLEND); GL11.glPopMatrix(); }
@Override public void init(GameContainer container, StateBasedGame game) throws SlickException { this.game = game; Font awtFont = new Font("SansSerif", Font.BOLD, 14); font = new UnicodeFont(awtFont); font.getEffects().add(new ShadowEffect(Color.black, 2, 2, 0.5f)); font.getEffects().add(new ColorEffect(Color.white)); font.addAsciiGlyphs(); font.loadGlyphs(); background = new Image("new-assets/background/background-no-shelf.png"); mouseOffsetX = (container.getWidth() - PlatformerGame.WIDTH) / 2; mouseOffsetY = (container.getHeight() - PlatformerGame.HEIGHT) / 2; }
public Fuente(String fuente, int tamano, boolean italica, boolean negrita, Color color) throws SlickException { this.tamano = tamano; this.italica = italica; this.negrita = negrita; this.color = color; uFont = new UnicodeFont(fuente, this.tamano, this.italica, this.negrita); uFont.addAsciiGlyphs(); uFont.addGlyphs(400, 600); uFont.getEffects().add(new ColorEffect(this.color)); uFont.loadGlyphs(); cargado = true; }
@Override public void init(GameContainer gc, StateBasedGame sbg) throws SlickException { this.bg = new Image("res/menu/backgroundLoad.jpg"); this.espace = new Image("res/score/espace.png"); this.score = new Image("res/score/score.png"); this.rubis = new Image("res/score/rubis.png"); this.saphirs = new Image("res/score/saphirs.png"); this.timing = new Image("res/score/timing.png"); this.point = new Image("res/score/points.png"); uFont = new UnicodeFont("res/score/police.ttf", 35, false, false); uFont.addAsciiGlyphs(); uFont.addGlyphs(400, 600); java.awt.Color color = new java.awt.Color(136, 213, 242); uFont.getEffects().add(new ColorEffect(color)); uFont.loadGlyphs(); }
@SuppressWarnings("unchecked") public Font loadFont(String filename, int size) { Font font; try { UnicodeFont unicodeFont = new UnicodeFont(filename, size, false, false); unicodeFont.addAsciiGlyphs(); unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE)); unicodeFont.loadGlyphs(); font = unicodeFont; } catch (SlickException e) { font = container.getDefaultFont(); } catch (RuntimeException e) { font = container.getDefaultFont(); } return font; }
@Override public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException { world.render(g); if (world.isGameOver()) { g.setColor(Color.black); g.setFont(font); int gameOverWidth = font.getWidth("G A M E O V E R"); g.drawString("G A M E O V E R", (ShootingGame.WIDTH - gameOverWidth) / 2, 150); } }
public void render() { glPushMatrix(); glLoadIdentity(); glOrtho(0, Juego.obtenerAnchura(), Juego.obtenerAltura(), 0, 1, -1); uFont.drawString(x, y, texto); glLoadIdentity(); glOrtho(0, Juego.obtenerAnchura(), 0, Juego.obtenerAltura(), 1, -1); glPopMatrix(); }
@Override public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException { bg.draw(0, 0); espace.draw(60, 500); rubis.draw(230, 120); saphirs.draw(200, 200); score.draw(230, 0); timing.draw(175, 300); point.draw(380, 400); int Nb_rubis = Item.getNB_Rubis(); int Nb_saphirs = Item.getNB_Saphir(); int time = Event.time * 60; int score = (int) (3000 * Math.exp(-0.00075 * (time - 15 * 60)) + 50 * Nb_rubis + 20 * Nb_saphirs); uFont.drawString(400, 130, "" + Nb_rubis); uFont.drawString(400, 210, "" + Nb_saphirs); uFont.drawString(350, 310, "" + time / 60); uFont.drawString(250, 420, "" + score); }
private int[] getGlyphMetrics(Font font, int codePoint) { // xOffset and xAdvance will be incorrect for unicode characters such as combining marks or // non-spacing characters // (eg Pnujabi's "\u0A1C\u0A47") that require the context of surrounding glyphs to determine // spacing, but thisis the // best we can do with the BMFont format. char[] chars = Character.toChars(codePoint); GlyphVector vector = font.layoutGlyphVector( GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); GlyphMetrics metrics = vector.getGlyphMetrics(0); int xOffset = vector.getGlyphPixelBounds(0, null, 0, 0).x - unicodeFont.getPaddingLeft(); int xAdvance = (int) (metrics.getAdvanceX() + unicodeFont.getPaddingAdvanceX() + unicodeFont.getPaddingLeft() + unicodeFont.getPaddingRight()); return new int[] {xOffset, xAdvance}; }
@Override public void init(GameContainer gc, StateBasedGame st) throws SlickException { // Lade Pixel Font try { font = Font.createFont(Font.TRUETYPE_FONT, new File("./resources/pixel.ttf")); } catch (FontFormatException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Große Pixel Font uniTitle = new UnicodeFont(font, 100, true, false); uniTitle.getEffects().add(new ColorEffect(java.awt.Color.orange)); uniTitle.addAsciiGlyphs(); uniTitle.loadGlyphs(); // Kleine Pixel Font uniNormal = new UnicodeFont(font, 30, true, false); uniNormal.getEffects().add(new ColorEffect(java.awt.Color.white)); uniNormal.addAsciiGlyphs(); uniNormal.loadGlyphs(); levelNames = new ArrayList<>(); playerNames = new ArrayList<>(); times = new ArrayList<>(); selection = new Rectangle(0, 0, 0, 40); }
@Override public void update(GameContainer gc, StateBasedGame sb, int delta) throws SlickException { background.rotate(0.05F * delta); Input input = gc.getInput(); if (input.isKeyPressed(Input.KEY_ESCAPE)) sb.enterState(0); if (input.isKeyPressed(Input.KEY_DOWN)) { // Wenn ausgewählter Index + 1 kleiner als die Items auf der Seite sind, erhöre den Index if (currentIndex + 1 < itemsOnSide) currentIndex++; } if (input.isKeyPressed(Input.KEY_UP)) { // gleiches wie oben, nur andersrum if (currentIndex != 0) currentIndex--; } if (input.isKeyPressed(Input.KEY_RIGHT)) { // Seite wechseln if (side + 1 < sideCount) { currentIndex = 0; side++; start = side * 10 + 1; end = start + 9; } } if (input.isKeyPressed(Input.KEY_LEFT)) { // Seite wechseln if (side - 1 >= 0) { currentIndex = 0; side--; start = side * 10 + 1; end = start + 9; } } count = 0; // Anpassung des Selection-Rectangles // Muss immer auf die Breite/Position des jeweiligen MenuItems angepasst werden for (MenuItem item : levelNames) { if (count == currentIndex + start) { selection.setLocation(item.getPos().x - 5, item.getPos().y - 5); } count++; } count = 0; for (MenuItem item : times) { if (count == currentIndex + start) { selection.setWidth( item.getPos().x + uniNormal.getWidth(item.getName()) - selection.getX() + 5); } count++; } }
@Override public void render(GameContainer container, Graphics g) throws SlickException { nameInput.render(container, g); float w = font.getWidth(text); float h = font.getLineHeight(); font.drawString(container.getWidth() / 2 - w / 2, container.getHeight() / 2 - h / 2, text); UnicodeFont namefont = Database.instance().getDefaultFont(); namefont.drawString( container.getWidth() / 8, container.getHeight() / 2 - h / 2 + font.getLineHeight(), name); nameInput.setLocation( container.getWidth() / 8 + namefont.getWidth(name) + 20, (int) (container.getHeight() / 2 - h / 2 + font.getLineHeight())); nameInput.render(container, g); }
public void render() { if (selected) { glColor4f(0.3f, 0.3f, 0.3f, 0.6f); if (isMouseOver()) glColor4f(0.4f, 0.4f, 0.4f, 0.6f); renderQuad(x + 1, y + 1, width, height); glColor4f(0.1f, 0.1f, 0.1f, 0.8f); } else { glColor4f(0.1f, 0.1f, 0.1f, 0.8f); if (isMouseOver()) glColor4f(0.2f, 0.2f, 0.2f, 0.8f); renderQuad(x + 1, y + 1, width, height); } font.drawString(x + 10, y + 2, text, Color.white); glDisable(GL_TEXTURE_2D); }
@SuppressWarnings("unchecked") public static UnicodeFont getFontWithSize(int fontSize) { for (UnicodeFont f : fonts) { if (f.getFont().getSize() == fontSize) { return f; } } try { UnicodeFont newFont = new UnicodeFont("res/font/Tahoma.ttf", fontSize, false, false); newFont.addAsciiGlyphs(); newFont.getEffects().add(new ColorEffect()); newFont.loadGlyphs(); return newFont; } catch (SlickException e) { return null; } }
public int obtenerAltura(String texto) { return uFont.getHeight(texto); }
public int obtenerAnchura(String texto) { return uFont.getWidth(texto); }
public void asignarY(int y) { this.y = Juego.obtenerAltura() - y - uFont.getLineHeight(); }
@Override public void enter(GameContainer gc, StateBasedGame st) { // Reset aller ArrayLists levelNames.clear(); playerNames.clear(); times.clear(); sideCount = 1; // Auslesen und Speichern der Highscores HighscoreManager.getInstance().readHighscores(); highscores = HighscoreManager.getInstance().getHighscores(); // Überschriften, erkennbar an der grünen Farbe, nicht auswählbar MenuItem header = new MenuItem("[Spieler-Name]"); header.setColor(Color.green); playerNames.add(header); header = new MenuItem("[Level]"); header.setColor(Color.green); levelNames.add(header); header = new MenuItem("[Zeit]"); header.setColor(Color.green); times.add(header); // Erstellung der Reihen basieren auf der Anzahl der Highscores for (Highscore hs : highscores) { playerNames.add(new MenuItem(hs.getPlayerName())); levelNames.add(new MenuItem(hs.getLevelName())); times.add(new MenuItem(StopWatch.getTimeAsString(hs.getTime()))); } // Komplizierter Teil // Hier werden die Positionen der MenuItems gesetzt int y = 120; for (int i = 0; i < levelNames.size(); i++) { MenuItem item = levelNames.get(i); item.setPos( new Vector2f(gc.getWidth() / 3 - 100 - uniNormal.getWidth(item.getName()) / 2, y)); item = playerNames.get(i); item.setPos( new Vector2f(gc.getWidth() / 3 * 2 - 80 - uniNormal.getWidth(item.getName()) / 2, y)); item = times.get(i); item.setPos( new Vector2f(gc.getWidth() / 3 * 2 + 200 - uniNormal.getWidth(item.getName()) / 2, y)); // Erhöhung des y Wertes, da sie sonst alle den gleichen Y Wert haben würden y += 50; // Falls i / 10 keinen Rest hat, ist eine Seite voll // Das % bedeutet Modulo-Operator. Ein kleines Beispiel: 10 % 4 = (10 Flaschen sollen in // Kästen, die 4 Flaschen fassen, verpackt werden, der Rest ist das Ergebnis(also 2)) if (i % 10 == 0 && i != 0) { sideCount++; // Reset der y Variable aber + 50, da die Überschrift ja ganz oben ist y = 170; } } // Momentan ausgewählt currentIndex = 0; // Wo soll in der ArrayList gestartet werden? Und bis wohin? start = side * 10 + 1; // Bei Seite 0: 1 end = start + 9; // Bei Seite 0: 9 }
public static void drawString(UnicodeFont font, float x, float y, String drawString) { font.drawString(x, y, drawString); }
public static void drawString( UnicodeFont font, float x, float y, String drawString, Color color) { font.drawString(x, y, drawString, color); }
public static int getWidth(UnicodeFont font, String s) { return font.getWidth(s); }
public void save(File outputBMFontFile) throws IOException, SlickException { File outputDir = outputBMFontFile.getParentFile(); String outputName = outputBMFontFile.getName(); if (outputName.endsWith(".fnt")) outputName = outputName.substring(0, outputName.length() - 4); unicodeFont.loadGlyphs(); PrintStream out = new PrintStream(new FileOutputStream(new File(outputDir, outputName + ".fnt"))); Font font = unicodeFont.getFont(); int pageWidth = unicodeFont.getGlyphPageWidth(); int pageHeight = unicodeFont.getGlyphPageHeight(); out.println( "info face=\"" + font.getFontName() + "\" size=" + font.getSize() + " bold=" + (font.isBold() ? 1 : 0) + " italic=" + (font.isItalic() ? 1 : 0) + " charset=\"\" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1"); out.println( "common lineHeight=" + unicodeFont.getLineHeight() + " base=26 scaleW=" + pageWidth + " scaleH=" + pageHeight + " pages=" + unicodeFont.getGlyphPages().size() + " packed=0"); int pageIndex = 0, glyphCount = 0; for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext(); ) { GlyphPage page = (GlyphPage) pageIter.next(); String fileName; if (pageIndex == 0 && !pageIter.hasNext()) fileName = outputName + ".png"; else fileName = outputName + (pageIndex + 1) + ".png"; out.println("page id=" + pageIndex + " file=\"" + fileName + "\""); glyphCount += page.getGlyphs().size(); pageIndex++; } out.println("chars count=" + glyphCount); // Always output space entry (codepoint 32). int[] glyphMetrics = getGlyphMetrics(font, 32); int xAdvance = glyphMetrics[1]; out.println( "char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=" + unicodeFont.getAscent() + " xadvance=" + xAdvance + " page=0 chnl=0 "); pageIndex = 0; List allGlyphs = new ArrayList(512); for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext(); ) { GlyphPage page = (GlyphPage) pageIter.next(); for (Iterator glyphIter = page.getGlyphs().iterator(); glyphIter.hasNext(); ) { Glyph glyph = (Glyph) glyphIter.next(); glyphMetrics = getGlyphMetrics(font, glyph.getCodePoint()); int xOffset = glyphMetrics[0]; xAdvance = glyphMetrics[1]; out.println( "char id=" + glyph.getCodePoint() + " " + "x=" + (int) (glyph.getImage().getTextureOffsetX() * pageWidth) + " y=" + (int) (glyph.getImage().getTextureOffsetY() * pageHeight) + " width=" + glyph.getWidth() + " height=" + glyph.getHeight() + " xoffset=" + xOffset + " yoffset=" + glyph.getYOffset() + " xadvance=" + xAdvance + " page=" + pageIndex + " chnl=0 "); } allGlyphs.addAll(page.getGlyphs()); pageIndex++; } String ttfFileRef = unicodeFont.getFontFile(); if (ttfFileRef == null) Log.warn( "Kerning information could not be output because a TTF font file was not specified."); else { Kerning kerning = new Kerning(); try { kerning.load(ResourceLoader.getResourceAsStream(ttfFileRef), font.getSize()); } catch (IOException ex) { Log.warn("Unable to read kerning information from font: " + ttfFileRef); } Map glyphCodeToCodePoint = new HashMap(); for (Iterator iter = allGlyphs.iterator(); iter.hasNext(); ) { Glyph glyph = (Glyph) iter.next(); glyphCodeToCodePoint.put( new Integer(getGlyphCode(font, glyph.getCodePoint())), new Integer(glyph.getCodePoint())); } List kernings = new ArrayList(256); class KerningPair { public int firstCodePoint, secondCodePoint, offset; } for (Iterator iter1 = allGlyphs.iterator(); iter1.hasNext(); ) { Glyph firstGlyph = (Glyph) iter1.next(); int firstGlyphCode = getGlyphCode(font, firstGlyph.getCodePoint()); int[] values = kerning.getValues(firstGlyphCode); if (values == null) continue; for (int i = 0; i < values.length; i++) { Integer secondCodePoint = (Integer) glyphCodeToCodePoint.get(new Integer(values[i] & 0xffff)); if (secondCodePoint == null) continue; // We may not be outputting the second character. int offset = values[i] >> 16; KerningPair pair = new KerningPair(); pair.firstCodePoint = firstGlyph.getCodePoint(); pair.secondCodePoint = secondCodePoint.intValue(); pair.offset = offset; kernings.add(pair); } } out.println("kernings count=" + kerning.getCount()); for (Iterator iter = kernings.iterator(); iter.hasNext(); ) { KerningPair pair = (KerningPair) iter.next(); out.println( "kerning first=" + pair.firstCodePoint + " second=" + pair.secondCodePoint + " amount=" + pair.offset); } } out.close(); pageIndex = 0; ImageIOWriter imageWriter = new ImageIOWriter(); for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext(); ) { GlyphPage page = (GlyphPage) pageIter.next(); String fileName; if (pageIndex == 0 && !pageIter.hasNext()) fileName = outputName + ".png"; else fileName = outputName + (pageIndex + 1) + ".png"; File imageOutputFile = new File(outputDir, fileName); FileOutputStream imageOutput = new FileOutputStream(imageOutputFile); try { imageWriter.saveImage(page.getImage(), "png", imageOutput, true); } finally { imageOutput.close(); } // Flip output image. Image image = new ImageIcon(imageOutputFile.getAbsolutePath()).getImage(); BufferedImage bufferedImage = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = bufferedImage.getGraphics(); g.drawImage(image, 0, 0, null); AffineTransform tx = AffineTransform.getScaleInstance(-1, 1); tx.translate(0, -image.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); bufferedImage = op.filter(bufferedImage, null); ImageIO.write(bufferedImage, "png", imageOutputFile); pageIndex++; } }
@Override public void render(GameContainer gc, StateBasedGame sb, Graphics g) throws SlickException { // Background etc. g.setAntiAlias(true); g.drawImage( background, gc.getWidth() / 2 - background.getWidth() / 2, gc.getHeight() / 2 - background.getHeight() / 2); uniTitle.drawString( gc.getWidth() / 2 - uniTitle.getWidth("Highscores") / 2, (float) 0, "Highscores", Color.orange); count = 0; // Zeichnet die Überschrift MenuItem item = levelNames.get(0); uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor()); item = playerNames.get(0); uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor()); item = times.get(0); uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor()); // Von start bis zu end for (int i = start; i <= end; i++) { // Falls wir am ende der Liste angekommen sind, abbrechen und itemsOnSide setzen if (i == levelNames.size()) { itemsOnSide = i - start; break; } // Maximale itemsOnSide = 10 else { itemsOnSide = 10; } // Zeichnen der Highscores item = levelNames.get(i); uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor()); item = playerNames.get(i); uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor()); item = times.get(i); uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor()); } g.setColor(Color.green); g.draw(selection); // aktuelle Seite zeichnen String displayside = "Seite " + (side + 1) + " von " + sideCount; uniNormal.drawString( gc.getWidth() / 2 - uniNormal.getWidth(displayside) / 2, gc.getHeight() - uniNormal.getHeight(displayside), displayside, Color.orange); // ESC String uniNormal.drawString( 0, gc.getHeight() - uniNormal.getHeight("ESC = Zurück"), "ESC = Zurück", Color.orange); }