Пример #1
0
  @Override
  public void render() {
    red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1;

    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    spriteBatch.begin();
    logoSprite.draw(spriteBatch);
    switch (renderMode) {
      case 0:
        font.getData().setScale(1);
        renderNormal("normal");
        break;
      case 1:
        font.getData().setScale(1);
        renderCached();
        break;
      case 2:
        font.getData().setScale(red.a + 0.5f);
        renderNormal("normal scaled");
        break;
      case 3:
        font.getData().setScale(1);
        renderCachedScaled();
        break;
    }
    spriteBatch.end();
  }
Пример #2
0
  public GameRenderer(Viewport viewport, Camera camera, GameEngine engine) {
    this.viewport = viewport;
    this.camera = camera;
    this.engine = engine;

    shapeRenderer = new MyShapeRenderer();
    shapeRenderer.setAutoShapeType(true);

    spriteBatch = new SpriteBatch();
    font = new BitmapFont();
    font.setColor(Color.WHITE);
    font.setUseIntegerPositions(false);
    font.getData().setScale(0.01f);
    shadowBatch = new ModelBatch(new DepthShaderProvider());

    ShaderProgram.pedantic = false;
    final String vertUber = Gdx.files.internal("shaders/uber.vert").readString();
    final String fragUber = Gdx.files.internal("shaders/uber.frag").readString();
    modelBatch =
        new ModelBatch(
            new DefaultShaderProvider(vertUber, fragUber) {
              @Override
              protected Shader createShader(final Renderable renderable) {
                return new UberShader(renderable, config);
              }
            });
  }
Пример #3
0
 public AssetFonts() {
   // create three fonts using Libgdx's 15px bitmap font
   defaultSmall = new BitmapFont(Gdx.files.internal("font/arial-15.fnt"), false);
   // set font sizes
   defaultSmall.getData().setScale(2.5f);
   // enable linear texture filtering for smooth fonts
   defaultSmall.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
 }
Пример #4
0
  public static void drawCenteredText(
      SpriteBatch batch, Color color, String text, float x, float y, float scale) {
    final BitmapFont font = getFont();
    font.getData().setScale(scale);

    layout.setText(font, text);
    final float textWidth = layout.width;
    final float left = x - (textWidth / 2);
    final float textHeight = font.getLineHeight();
    font.setColor(color);
    font.draw(batch, text, left, y + (textHeight / 2));
  }
Пример #5
0
 protected void drawCursor(Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) {
   cursorPatch.draw(
       batch,
       x
           + textOffset
           + glyphPositions.get(cursor)
           - glyphPositions.get(visibleTextStart)
           + fontOffset
           + font.getData().cursorX,
       y - textHeight - font.getDescent(),
       cursorPatch.getMinWidth(),
       textHeight);
 }
Пример #6
0
  @Override
  public void show() {
    batch = new SpriteBatch();

    viewport = new FitViewport(Constants.screenWidth, Constants.screenHeight);
    Gdx.input.setInputProcessor(this);

    font = new BitmapFont(Gdx.files.internal("data/modenine.fnt"));
    font.getData().setScale(Constants.DIFFICULTY_LABEL_SCALE);
    font.getRegion()
        .getTexture()
        .setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
  }
Пример #7
0
  @Override
  public void render(float delta) {
    super.render(delta);
    SpriteBatch batch = new SpriteBatch();

    BitmapFont font = new BitmapFont();
    font.getData().setScale(2f, 2f);
    font.setColor(Color.GREEN);

    batch.begin();
    font.draw(batch, Integer.toString(getGame().getHighScore()), 360, 310);
    font.draw(batch, Integer.toString(getGame().getCurrentScore()), 360, 280);
    batch.end();

    batch.dispose();
  }
Пример #8
0
  public void drawString(String s, float x, float y, float fontSize, boolean centered, Color col) {
    if (s == null) return;
    myTextureChecker.onString(myFont.getRegion().getTexture());
    myFont.setColor(col);
    myFont.getData().setScale(fontSize / myOrigFontHeight);
    if (!centered) {
      myFont.draw(mySpriteBatch, s, x, y);
      return;
    }

    // http://www.badlogicgames.com/wordpress/?p=3658
    layout.reset();
    layout.setText(myFont, s);
    x -= layout.width / 2;
    y -= layout.height / 2;
    myFont.draw(mySpriteBatch, layout, x, y);
  }
Пример #9
0
  // Metodo para preparar los elementos de la fase de Muestreo de Imagenes
  private void SetupShowStage() {
    texturesList = new ArrayList<Texture>();

    texturesList.add(new Texture("img_1.png"));
    texturesList.add(new Texture("img_2.png"));
    texturesList.add(new Texture("img_3.png"));
    texturesList.add(new Texture("img_4.png"));
    texturesList.add(new Texture("img_5.png"));
    texturesList.add(new Texture("img_6.png"));
    texturesList.add(new Texture("img_7.png"));
    texturesList.add(new Texture("img_8.png"));

    imgActor = new Image(texturesList.get(0));
    stage.addActor(imgActor);
    CenterImgActorToScreen(imgActor);

    titlesList = new ArrayList<String>();

    titlesList.add("Cojo el cepillo");
    titlesList.add("Me cepillo los dientes");
    titlesList.add("Me enjuago la boca");
    titlesList.add("Escupo el agua");
    titlesList.add("Abro el grifo y limpio");
    titlesList.add("Me lavo las manos");
    titlesList.add("Cierro el grifo");
    titlesList.add("Me seco las manos");

    font = new BitmapFont();
    imageTitle = new TitleActor(font, titlesList.get(0));
    SetFontTextCenter(imageTitle, titlesList.get(0));
    font.getData().setScale(1f, 1f);
    stage.addActor(imageTitle);

    soundsList = new ArrayList<Music>();
    soundsList.add(Gdx.audio.newMusic((Gdx.files.internal("sound_1.mp3"))));
    soundsList.add(Gdx.audio.newMusic((Gdx.files.internal("sound_2.mp3"))));
    soundsList.add(Gdx.audio.newMusic((Gdx.files.internal("sound_3.mp3"))));
    soundsList.add(Gdx.audio.newMusic((Gdx.files.internal("sound_4.mp3"))));
    soundsList.add(Gdx.audio.newMusic((Gdx.files.internal("sound_5.mp3"))));
    soundsList.add(Gdx.audio.newMusic((Gdx.files.internal("sound_6.mp3"))));
    soundsList.add(Gdx.audio.newMusic((Gdx.files.internal("sound_7.mp3"))));
    soundsList.add(Gdx.audio.newMusic((Gdx.files.internal("sound_8.mp3"))));
    soundPlayed = false;
  }
Пример #10
0
  public DialogText(
      @NtN String displayName,
      @NtN BitmapFont font,
      int width,
      int lineCount,
      @NtN Drawable window,
      @NtN String rawText,
      @NtN TimeUntilLetterSource timeUntilLetterSource,
      @N Listener listener) {
    super(displayName, V2.get(width, font.getLineHeight() * lineCount), window, listener);

    this.font = font;
    this.lineCount = lineCount;
    this.rawText = rawText;
    this.timeUntilLetterSource = timeUntilLetterSource;

    glyphLayout = new GlyphLayout();
    font.getData().markupEnabled = true;
  }
Пример #11
0
  @Override
  public void create() {
    Gdx.input.setInputProcessor(
        new InputAdapter() {
          public boolean touchDown(int x, int y, int pointer, int newParam) {
            renderMode = (renderMode + 1) % 4;
            return false;
          }
        });

    spriteBatch = new SpriteBatch();
    spriteBatch.setProjectionMatrix(
        new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1));

    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    logoSprite = new Sprite(texture);
    logoSprite.flip(false, true);
    logoSprite.setPosition(0, 320 - 256);
    logoSprite.setColor(1, 1, 1, 0.5f);

    font =
        new BitmapFont(
            Gdx.files.internal("data/verdana39.fnt"),
            Gdx.files.internal("data/verdana39.png"),
            true);

    cache1 = font.newFontCache();
    cache2 = font.newFontCache();
    cache3 = font.newFontCache();
    cache4 = font.newFontCache();
    cache5 = font.newFontCache();
    createCaches("cached", cache1, cache2, cache3, cache4, cache5);

    font.getData().setScale(1.33f);
    cacheScaled1 = font.newFontCache();
    cacheScaled2 = font.newFontCache();
    cacheScaled3 = font.newFontCache();
    cacheScaled4 = font.newFontCache();
    cacheScaled5 = font.newFontCache();
    createCaches(
        "cache scaled", cacheScaled1, cacheScaled2, cacheScaled3, cacheScaled4, cacheScaled5);
  }
Пример #12
0
  private void saveFontToFile(BitmapFont font, int fontSize, String fontName, PixmapPacker packer) {
    FileHandle fontFile = getFontFile(fontName + ".fnt"); // .fnt path
    FileHandle pixmapDir = getFontFile(fontName); // png dir path
    BitmapFontWriter.setOutputFormat(BitmapFontWriter.OutputFormat.Text);

    String[] pageRefs = BitmapFontWriter.writePixmaps(packer.getPages(), pixmapDir, fontName);
    Gdx.app.debug(
        TAG,
        String.format(
            "Saving font [%s]: fontfile: %s, pixmapDir: %s\n", fontName, fontFile, pixmapDir));
    // here we must add the png dir to the page refs
    for (int i = 0; i < pageRefs.length; i++) {
      pageRefs[i] = fontName + "/" + pageRefs[i];
    }
    BitmapFontWriter.writeFont(
        font.getData(),
        pageRefs,
        fontFile,
        new BitmapFontWriter.FontInfo(fontName, fontSize),
        1,
        1);
  }
Пример #13
0
  void updateDisplayText() {
    BitmapFont font = style.font;
    BitmapFontData data = font.getData();
    String text = this.text;
    int textLength = text.length();

    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < textLength; i++) {
      char c = text.charAt(i);
      buffer.append(data.hasGlyph(c) ? c : ' ');
    }
    String newDisplayText = buffer.toString();

    if (passwordMode && data.hasGlyph(passwordCharacter)) {
      if (passwordBuffer == null) passwordBuffer = new StringBuilder(newDisplayText.length());
      if (passwordBuffer.length() > textLength) passwordBuffer.setLength(textLength);
      else {
        for (int i = passwordBuffer.length(); i < textLength; i++)
          passwordBuffer.append(passwordCharacter);
      }
      displayText = passwordBuffer;
    } else displayText = newDisplayText;

    layout.setText(font, displayText);
    glyphPositions.clear();
    float x = 0;
    if (layout.runs.size > 0) {
      GlyphRun run = layout.runs.first();
      FloatArray xAdvances = run.xAdvances;
      fontOffset = xAdvances.first();
      for (int i = 1, n = xAdvances.size; i < n; i++) {
        glyphPositions.add(x);
        x += xAdvances.get(i);
      }
    } else fontOffset = 0;
    glyphPositions.add(x);

    if (selectionStart > newDisplayText.length()) selectionStart = textLength;
  }
Пример #14
0
  public static void load() {

    logoTexture = new Texture(Gdx.files.internal("data/logo.png"));
    logoTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    logo = new TextureRegion(logoTexture, 0, 0, 512, 114);

    texture = new Texture(Gdx.files.internal("data/texture.png"));
    texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);

    playButtonUp = new TextureRegion(texture, 0, 83, 29, 16);
    playButtonDown = new TextureRegion(texture, 29, 83, 29, 16);
    playButtonUp.flip(false, true);
    playButtonDown.flip(false, true);

    ready = new TextureRegion(texture, 59, 83, 34, 7);
    ready.flip(false, true);

    retry = new TextureRegion(texture, 59, 110, 33, 7);
    retry.flip(false, true);

    gameOver = new TextureRegion(texture, 59, 92, 46, 7);
    gameOver.flip(false, true);

    scoreboard = new TextureRegion(texture, 111, 83, 97, 37);
    scoreboard.flip(false, true);

    star = new TextureRegion(texture, 152, 70, 10, 10);
    noStar = new TextureRegion(texture, 165, 70, 10, 10);

    star.flip(false, true);
    noStar.flip(false, true);

    highScore = new TextureRegion(texture, 59, 101, 48, 7);
    highScore.flip(false, true);

    zbLogo = new TextureRegion(texture, 0, 55, 135, 24);
    zbLogo.flip(false, true);

    bg = new TextureRegion(texture, 0, 0, 136, 43);
    bg.flip(false, true);

    grass = new TextureRegion(texture, 0, 43, 143, 11);
    grass.flip(false, true);

    birdDown = new TextureRegion(texture, 136, 0, 17, 12);
    birdDown.flip(false, true);

    bird = new TextureRegion(texture, 153, 0, 17, 12);
    bird.flip(false, true);

    birdUp = new TextureRegion(texture, 170, 0, 17, 12);
    birdUp.flip(false, true);

    // creates an array of TextureRegions
    TextureRegion[] birds = {birdDown, bird, birdUp};
    // Creates a new Animation in which each frame is 0.06 seconds long, using the above array.
    birdAnimation = new Animation(0.06f, birds);
    // Sets play mode to be ping pong, in which we will see a bounce.
    birdAnimation.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);

    skullUp = new TextureRegion(texture, 192, 0, 24, 14);
    // Create by flipping existing skullUp
    skullDown = new TextureRegion(skullUp);
    skullDown.flip(false, true);

    bar = new TextureRegion(texture, 136, 16, 22, 3);
    bar.flip(false, true);

    dead = Gdx.audio.newSound(Gdx.files.internal("data/dead.wav"));
    flap = Gdx.audio.newSound(Gdx.files.internal("data/flap.wav"));
    coin = Gdx.audio.newSound(Gdx.files.internal("data/coin.wav"));
    fall = Gdx.audio.newSound(Gdx.files.internal("data/fall.wav"));

    font = new BitmapFont(Gdx.files.internal("data/text.fnt"));
    font.getData().setScale(.25f, -.25f);

    whiteFont = new BitmapFont(Gdx.files.internal("data/whitetext.fnt"));
    whiteFont.getData().setScale(.1f, -.1f);

    shadow = new BitmapFont(Gdx.files.internal("data/shadow.fnt"));
    shadow.getData().setScale(.25f, -.25f);

    // Create (or retrieve existing) preferences file
    prefs = Gdx.app.getPreferences("Zombie Bird");

    // Provide default high score of 0
    if (!prefs.contains("highScore")) {
      prefs.putInteger("highScore", 0);
    }
  }
Пример #15
0
  public Gamescreen(Jamwteatrze game) {

    this.game = game;

    // set game state

    currentState = GameState.TITLE;
    // currentState = GameState.MAP;
    // currentState = GameState.ARENA;

    batch = new SpriteBatch();
    camera = new OrthographicCamera(1280, 720);
    camera.position.set(camera.viewportWidth / 2f, camera.viewportHeight / 2f, 0);
    viewport = new FitViewport(1280, 720, camera);
    camera.update();

    // spine

    sr = new SkeletonRenderer();
    dr = new SkeletonRendererDebug();
    dr.setBoundingBoxes(false);
    dr.setRegionAttachments(false);

    // stage

    stage = new Stage(viewport, batch);
    stageCharacters = new Stage(viewport, batch);

    Gdx.input.setInputProcessor(stage);

    // ----------------- DEKLARACJE

    playerIcon = new SpineActor(batch, sr, shpr, "characters/goral", true, game.player.playerHp);

    playerIcon.setPosition(-400, 180);
    stageCharacters.addActor(playerIcon);

    generujEnemys();

    // atakuj button

    atakujTex = Assets.manager.get(Assets.atakuj, Texture.class);
    atakujTex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    atakujButton = new ImageButton(new SpriteDrawable(new Sprite(atakujTex)));
    atakujButton.setPosition(565, -200);
    atakujButton.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (pulaGracza > 0 && !atakowanie) {
              atakowanie = true;
              System.out.println("atakuj button pressed");
              atakuj();
            }
            return true;
          }
        });

    stage.addActor(atakujButton);

    // gui

    font = Assets.manager.get(Assets.myFont, BitmapFont.class);
    font.getData().setScale(0.7f);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    scena = Assets.manager.get(Assets.scena, Texture.class);
    scena.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    panel = Assets.manager.get(Assets.panel, Texture.class);
    panel.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    // tla

    swiat00tlo = Assets.manager.get(Assets.swiat00tlo, Texture.class);
    swiat00tlo.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    swiat01tlo = Assets.manager.get(Assets.swiat01tlo, Texture.class);
    swiat01tlo.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    swiat02tlo = Assets.manager.get(Assets.swiat02tlo, Texture.class);
    swiat02tlo.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    swiat03tlo = Assets.manager.get(Assets.swiat03tlo, Texture.class);
    swiat03tlo.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    kowadloTex = Assets.manager.get(Assets.kowadloTex, Texture.class);
    kowadloTex.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    // kowadlo = new Sprite(kowadloTex);
    // kowadlo.setPosition(100, 100);

    // DICES

    heroDices = new Array<Dice>();
    enemyDices = new Array<Dice>();

    // ------ generate hero dieces
    heroDices.add(new Dice(this, true));
    heroDices.add(new Dice(this, true));
    // heroDices.add(new Dice(this));

    numberHeroDieces = heroDices.size;
    baseHeroDieces = numberHeroDieces;

    for (Dice dice : heroDices) {
      // dice.debug();
      dice.setTouchable(Touchable.disabled);
      dice.setVisible(false);
      stage.addActor(dice);
    }

    // ------ generate enemy dieces

    enemyDices.add(new Dice(this, false));
    enemyDices.add(new Dice(this, false));

    numberEnemyDieces = enemyDices.size;
    baseEnemyDieces = numberEnemyDieces;

    for (int i = 0; i < enemyDices.size; i++) {
      enemyDices.get(i).setPosition(725 + (i * 133), -150);
      if (!heroTurn) {
        enemyDices.get(i).addAction(moveTo(725 + (i * 133), 37, 1.0f, Interpolation.bounceOut));
      }
    }

    for (Dice dice : enemyDices) {
      // dice.debug();
      stage.addActor(dice);
    }

    // kotara

    kotaraAtlas = new TextureAtlas(Gdx.files.internal("gui/kotara.atlas"));
    kotaraJson = new SkeletonJson(kotaraAtlas);
    kotaraSkeletonData = kotaraJson.readSkeletonData(Gdx.files.internal("gui/kotara.json"));
    kotaraSkeleton = new Skeleton(kotaraSkeletonData);
    kotaraIdleAnimation = kotaraSkeletonData.findAnimation("idle");
    AnimationStateData stateData = new AnimationStateData(kotaraSkeletonData);
    kotaraState = new AnimationState(stateData);
    kotaraState.addAnimation(0, "idle", true, 0);
    kotaraSkeleton.setPosition(-200, -150);

    // title

    title = new SpineButton(batch, sr, "gui/title", "idle", 100, 0, 800, 600);
    // title.debug();
    title.setClicked(false);

    if (currentState == GameState.TITLE) {
      resetTitle();
    }

    // title listeners

    title.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (!title.isClicked() && title.getY() <= 20) {
              title.setClicked(true);
              fadeOutTitle(Gdx.graphics.getDeltaTime());
            }
            return true;
          }
        });

    stage.addActor(title);

    // mapa

    mapa = new SpineButton(batch, sr, "gui/mapa", "show0", 100, 0, 800, 600);
    mapa.setPosition(mapaX, -900);
    // mapa.debug();
    mapa.setClicked(false);

    // mapa listeners TODO!

    mapa.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            fadeOutMapa(Gdx.graphics.getDeltaTime());
            return true;
          }
        });

    stage.addActor(mapa);

    // if (currentState == GameState.ARENA) {
    // resetArena();
    // }
  }
Пример #16
0
  public static BitmapFont cloneBitmapFont(BitmapFont old) {
    BitmapFont.BitmapFontData data = new BitmapFont.BitmapFontData();
    data.ascent = old.getData().ascent;
    data.capHeight = old.getData().capHeight;
    data.descent = old.getData().descent;
    data.down = old.getData().down;
    data.flipped = old.getData().flipped;
    data.fontFile = old.getData().fontFile;
    data.lineHeight = old.getData().lineHeight;
    data.scaleX = old.getData().scaleX;
    data.scaleY = old.getData().scaleY;
    data.spaceWidth = old.getData().spaceWidth;
    data.xHeight = old.getData().xHeight;
    data.imagePaths = old.getData().imagePaths;
    for (int i = 0; i < old.getData().glyphs.length; ++i) {
      data.glyphs[i] = old.getData().glyphs[i];
    }

    return new BitmapFont(data, old.getRegions(), old.usesIntegerPositions());
  }
Пример #17
0
 public BitmapFontData getData() {
   return font.getData();
 }