Search in sources :

Example 1 with DrawableRectangle

use of com.agorria.shootandmove.graphics.DrawableRectangle in project ShootAndRun by IonAgorria.

the class GameView method drawText.

/**
 * Draws the specified text in position by creating drawables
 *
 * @param drawables to add the drawables
 * @param x position
 * @param y position
 * @param width of each character, 0 to use relative to height
 * @param height of each character, 0 to use relative to width
 * @param centerX enables centering in X axis
 * @param centerY enables centering in Y axis
 * @param lines to draw
 */
public void drawText(List<Drawable> drawables, float x, float y, float width, float height, boolean centerX, boolean centerY, String... lines) {
    if (width == 0)
        width = height * CHARACTER_ASPECT_WH;
    else if (height == 0)
        height = width * CHARACTER_ASPECT_HW;
    float currentY = centerY ? -(lines.length * height * 0.5f) : 0;
    // Draw lines in inverse order as the Y axis is upside down and I don't have time to make some dark magic
    for (int i = lines.length - 1; 0 <= i; i--) {
        String line = lines[i];
        final char[] chars = line.toCharArray();
        float currentX = centerX ? -(chars.length * width * 0.5f) : 0;
        // Draw each character
        for (char c : chars) {
            if (c != ' ') {
                // Attempt to get region for this character
                TextureRegion region = characters.get(c);
                if (region == null) {
                    region = unknownCharacter;
                }
                // Add drawable
                drawables.add(new DrawableRectangle(x + currentX, y + currentY, width, height, region));
            }
            currentX += width;
        }
        currentY += height;
    }
}
Also used : TextureRegion(com.agorria.shootandmove.graphics.TextureRegion) DrawableRectangle(com.agorria.shootandmove.graphics.DrawableRectangle) SuppressLint(android.annotation.SuppressLint)

Example 2 with DrawableRectangle

use of com.agorria.shootandmove.graphics.DrawableRectangle in project ShootAndRun by IonAgorria.

the class MenuHelp method createHelp.

/**
 * Creates help info
 *
 * @param view to use
 * @param x position
 * @param y position
 * @param size of help
 * @param padding to use between image and text
 * @param region to show
 * @param textID of help
 */
private void createHelp(GameView view, float x, float y, Vector2f size, float padding, TextureRegion region, int textID) {
    String text = view.getText(textID);
    // noinspection SuspiciousNameCombination
    menuDrawables.add(new DrawableRectangle(x, y, size.y, size.y, region));
    String[] lines = Utilities.getTextLines(text);
    int textWidth = Utilities.getTextWidth(lines);
    padding += size.y;
    view.drawText(menuDrawables, x + padding, y + size.y / 2, (size.x - padding) / textWidth, 0, false, true, lines);
}
Also used : DrawableRectangle(com.agorria.shootandmove.graphics.DrawableRectangle)

Example 3 with DrawableRectangle

use of com.agorria.shootandmove.graphics.DrawableRectangle in project ShootAndRun by IonAgorria.

the class GameUI method sizeChanged.

/**
 * Called when size of view is changed
 *
 * @param width in pixes
 * @param height in pixels
 */
public void sizeChanged(GameView view, int width, int height) {
    Log.d(TAG, "sizeChanged " + width + "x" + height);
    this.viewWidth = width == 0 ? 1 : width;
    this.viewHeight = height == 0 ? 1 : height;
    this.aspect = viewWidth / viewHeight;
    // Create non scaled background and submit
    TextureAtlas sprite128 = view.getTextureAtlas(TextureAtlas.Atlas.Sprite128);
    List<Drawable> backgrounds = new ArrayList<>();
    backgrounds.add(new DrawableRectangle(aspect / 2f - 1f, 0, 1f, 1f, sprite128.getRegion(0, 0).copy().flip(false, true)));
    backgrounds.add(new DrawableRectangle(aspect / 2f, 0, 1f, 1f, sprite128.getRegion(0, 0)));
    DrawableBatch batch = view.createBatchOrthographic(DrawableBatch.SLOT.Background, backgrounds, Color.WHITE);
    view.submitBatch(batch);
    // Generate menus
    menuMap.put(MenuMain.class, new MenuMain(this, view));
    menuMap.put(MenuHelp.class, new MenuHelp(this, view));
    menuMap.put(MenuPlay.class, new MenuPlay(this, view));
    menuMap.put(MenuIntro.class, new MenuIntro(this, view));
    menuMap.put(MenuEnding.class, new MenuEnding(this, view));
    menuMap.put(MenuCredits.class, new MenuCredits(this, view));
    menuMap.put(MenuOptions.class, new MenuOptions(this, view));
    // Generate control drawables
    TextureAtlas atlas = view.getTextureAtlas(TextureAtlas.Atlas.Sprite32);
    gameDrawables.clear();
    float controlSize = CONTROLS_SIZE / 2;
    // Joystick
    joystickRectangle = new Rectangle(CONTROLS_PADDING, CONTROLS_PADDING, controlSize * 2, controlSize * 2);
    gameDrawables.add(new DrawableRectangle(joystickRectangle, atlas.getRegion(14, 0)));
    // Shoot
    gameDrawables.add(new DrawableRectangle(aspect - controlSize - CONTROLS_PADDING, CONTROLS_PADDING + controlSize, controlSize, controlSize, atlas.getRegion(14, 1)));
    // Prev
    gameDrawables.add(new DrawableRectangle(aspect - controlSize * 2 - CONTROLS_PADDING, CONTROLS_PADDING, controlSize, controlSize, atlas.getRegion(15, 0)));
    // Next
    gameDrawables.add(new DrawableRectangle(aspect - controlSize - CONTROLS_PADDING, CONTROLS_PADDING, controlSize, controlSize, // Flip side
    atlas.getRegion(15, 0).copy().flip(true, false)));
    // Cross
    gameDrawables.add(new DrawableRectangle(aspect / 2f - CROSS_SIZE / 2f, 0.5f - CROSS_SIZE / 2f, CROSS_SIZE, CROSS_SIZE, atlas.getRegion(8, 1)));
    // Health
    float playerSpace = aspect * PLAYER_SPACE;
    float playerPadding = (1f - PLAYER_PADDING) - PLAYER_SIZE;
    gameDrawables.add(new DrawableRectangle(aspect / 2 - playerSpace - PLAYER_SIZE, playerPadding, PLAYER_SIZE, PLAYER_SIZE, atlas.getRegion(4, 2).copy().setSizeCentered(20, 20)));
    // Movement
    movementDrawables = new Drawable[] { new DrawableRectangle(aspect - controlSize * 2 - CONTROLS_PADDING, CONTROLS_PADDING + controlSize, controlSize, controlSize, atlas.getRegion(15, 1)), new DrawableRectangle(aspect - controlSize * 2 - CONTROLS_PADDING, CONTROLS_PADDING + controlSize, controlSize, controlSize, atlas.getRegion(15, 2)) };
    // Death drawables
    deathDrawables = new Drawable[] { new DrawableRectangle(0, 0, aspect, 1f, atlas.getRegion(14, 2)), new DrawableRectangle(0, 0, aspect, 1f, atlas.getRegion(13, 2)), new DrawableRectangle(0, 0, aspect, 1f, atlas.getRegion(12, 2)) };
    // Set flag
    requireDraw = true;
}
Also used : DrawableRectangle(com.agorria.shootandmove.graphics.DrawableRectangle) MenuMain(com.agorria.shootandmove.menu.MenuMain) MenuCredits(com.agorria.shootandmove.menu.MenuCredits) Drawable(com.agorria.shootandmove.graphics.Drawable) ArrayList(java.util.ArrayList) MenuPlay(com.agorria.shootandmove.menu.MenuPlay) DrawableRectangle(com.agorria.shootandmove.graphics.DrawableRectangle) Rectangle(com.agorria.shootandmove.math.Rectangle) MenuEnding(com.agorria.shootandmove.menu.MenuEnding) MenuOptions(com.agorria.shootandmove.menu.MenuOptions) MenuIntro(com.agorria.shootandmove.menu.MenuIntro) TextureAtlas(com.agorria.shootandmove.graphics.TextureAtlas) MenuHelp(com.agorria.shootandmove.menu.MenuHelp) DrawableBatch(com.agorria.shootandmove.graphics.DrawableBatch)

Aggregations

DrawableRectangle (com.agorria.shootandmove.graphics.DrawableRectangle)3 SuppressLint (android.annotation.SuppressLint)1 Drawable (com.agorria.shootandmove.graphics.Drawable)1 DrawableBatch (com.agorria.shootandmove.graphics.DrawableBatch)1 TextureAtlas (com.agorria.shootandmove.graphics.TextureAtlas)1 TextureRegion (com.agorria.shootandmove.graphics.TextureRegion)1 Rectangle (com.agorria.shootandmove.math.Rectangle)1 MenuCredits (com.agorria.shootandmove.menu.MenuCredits)1 MenuEnding (com.agorria.shootandmove.menu.MenuEnding)1 MenuHelp (com.agorria.shootandmove.menu.MenuHelp)1 MenuIntro (com.agorria.shootandmove.menu.MenuIntro)1 MenuMain (com.agorria.shootandmove.menu.MenuMain)1 MenuOptions (com.agorria.shootandmove.menu.MenuOptions)1 MenuPlay (com.agorria.shootandmove.menu.MenuPlay)1 ArrayList (java.util.ArrayList)1