Search in sources :

Example 1 with Menu

use of com.agorria.shootandmove.menu.Menu in project ShootAndRun by IonAgorria.

the class GameUI method processMenu.

/**
 * Processes menu input
 *
 * @param x position
 * @param y position
 * @param press if was pressed
 */
private void processMenu(float x, float y, boolean press) {
    Menu menu = menuMap.get(currentMenu);
    if (menu != null) {
        boolean change = menu.touch(x, y, press);
        requireDraw |= change;
        vibrate |= change && press;
    }
}
Also used : Menu(com.agorria.shootandmove.menu.Menu)

Example 2 with Menu

use of com.agorria.shootandmove.menu.Menu in project ShootAndRun by IonAgorria.

the class GameUI method setCurrentMenu.

/**
 * Sets current menu
 *
 * @param currentMenu to set
 */
public void setCurrentMenu(Class<? extends Menu> currentMenu) {
    Log.d(TAG, "setCurrentMenu " + (currentMenu == null ? "null" : currentMenu.getSimpleName()));
    if (this.currentMenu != null) {
        Menu menu = menuMap.get(this.currentMenu);
        if (menu != null)
            menu.close();
    }
    this.currentMenu = currentMenu;
    if (this.currentMenu != null) {
        Menu menu = menuMap.get(this.currentMenu);
        menu.open();
    }
    requireDraw = true;
}
Also used : Menu(com.agorria.shootandmove.menu.Menu)

Example 3 with Menu

use of com.agorria.shootandmove.menu.Menu in project ShootAndRun by IonAgorria.

the class GameUI method draw.

/**
 * Draws the UI if required
 *
 * @param view of game
 * @param player instance
 */
void draw(GameView view, Player player) {
    if (player != null) {
        requireDraw |= player.hasChanged();
    }
    if (requireDraw) {
        requireDraw = false;
        List<Drawable> drawables = new ArrayList<>();
        // Draw death overlay
        if (player != null) {
            int health = player.getCurrentHealth();
            if (health <= 50)
                drawables.add(deathDrawables[0]);
            if (health <= 25)
                drawables.add(deathDrawables[1]);
        }
        // Draw UI per state
        Color color = null;
        String text = null;
        if (currentGameState == GameState.Menu) {
            // Draw current menu
            color = Color.WHITE;
            Menu menu = menuMap.get(currentMenu);
            if (menu != null) {
                menu.draw(view, drawables);
            }
        } else if (currentGameState == GameState.Active) {
            color = Color.GRAY_LIGHT_50;
            drawables.addAll(gameDrawables);
            // Movement mode
            if (movementDrawables != null) {
                drawables.add(movementDrawables[movementMode ? 1 : 0]);
            }
            // Add player stuff
            if (player != null) {
                Weapon weapon = player.getWeapon();
                Drawable weaponDrawable = weapon.getDrawable();
                float playerPadding = (1 - PLAYER_PADDING) - PLAYER_SIZE;
                float middle = aspect / 2f;
                // Draw player health
                int health = player.getCurrentHealth();
                view.drawText(drawables, middle, playerPadding, 0, PLAYER_SIZE, false, false, String.valueOf(health));
                // Draw weapon
                weaponDrawable.getPosition().set(middle - PLAYER_SIZE - PLAYER_SPACE, playerPadding - PLAYER_SIZE - PLAYER_SPACE, 0);
                weaponDrawable.getSize().set(PLAYER_SIZE, PLAYER_SIZE, 0);
                drawables.add(weaponDrawable);
                // Draw weapon ammo
                view.drawText(drawables, middle, playerPadding - PLAYER_SIZE - PLAYER_SPACE, 0, PLAYER_SIZE, false, false, String.valueOf(weapon.getShots()));
            }
        } else if (currentGameState == GameState.Lost) {
            color = Color.RED;
            drawables.add(deathDrawables[2]);
            text = view.getText(R.string.lost);
        } else if (currentGameState == GameState.Pause) {
            color = Color.GRAY_LIGHT_50;
            text = view.getText(R.string.paused);
        }
        // Add text
        if (text != null) {
            String[] lines = Utilities.getTextLines(text);
            int textWidth = Utilities.getTextWidth(lines) + 2;
            float charWidth = aspect / textWidth;
            view.drawText(drawables, aspect / 2f, 0.5f, charWidth, 0, true, true, lines);
        }
        // Draw slow text if any
        if (slowTextElement != null) {
            slowTextElement.onDraw(view, drawables);
        }
        // Send drawables to batch if any
        if (drawables.isEmpty()) {
            view.clearBatches(DrawableBatch.SLOT.UI);
        } else {
            DrawableBatch batch = view.createBatchOrthographic(DrawableBatch.SLOT.UI, drawables, color);
            view.submitBatch(batch);
        }
    }
    if (vibrate) {
        vibrate = false;
        view.vibrate(Constants.VIBRATE_UI);
    }
}
Also used : Color(com.agorria.shootandmove.graphics.Color) Drawable(com.agorria.shootandmove.graphics.Drawable) ArrayList(java.util.ArrayList) Menu(com.agorria.shootandmove.menu.Menu) DrawableBatch(com.agorria.shootandmove.graphics.DrawableBatch)

Aggregations

Menu (com.agorria.shootandmove.menu.Menu)3 Color (com.agorria.shootandmove.graphics.Color)1 Drawable (com.agorria.shootandmove.graphics.Drawable)1 DrawableBatch (com.agorria.shootandmove.graphics.DrawableBatch)1 ArrayList (java.util.ArrayList)1