Example usage for com.badlogic.gdx.graphics Color WHITE

List of usage examples for com.badlogic.gdx.graphics Color WHITE

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Color WHITE.

Prototype

Color WHITE

To view the source code for com.badlogic.gdx.graphics Color WHITE.

Click Source Link

Usage

From source file:com.smeanox.games.sg002.screen.PauseScreen.java

License:Open Source License

/**
 * Create all GUI elements//from  www.j  a v  a  2 s  .  co  m
 */
private void createUI() {
    LinkedList<Button> toLayout = new LinkedList<Button>();
    Button b;

    // quit game
    b = new Button(new Sprite(Assets.button), Assets.liberationMedium,
            Language.getStrings().get("menu.quitGame"), Color.BLACK, Color.WHITE, Color.LIGHT_GRAY,
            Color.DARK_GRAY);
    b.addClickHandler(new ClickHandler() {
        @Override
        public void onClick() {
            quitGame();
        }
    });
    addGUIElement(b);
    toLayout.add(b);
    // save game
    b = new Button(new Sprite(Assets.button), Assets.liberationMedium,
            Language.getStrings().get("menu.saveGame"), Color.BLACK, Color.WHITE, Color.LIGHT_GRAY,
            Color.DARK_GRAY);
    b.addClickHandler(new ClickHandler() {
        @Override
        public void onClick() {
            saveGame();
        }
    });
    addGUIElement(b);
    toLayout.add(b);
    // load game
    b = new Button(new Sprite(Assets.button), Assets.liberationMedium,
            Language.getStrings().get("menu.loadGame"), Color.BLACK, Color.WHITE, Color.LIGHT_GRAY,
            Color.DARK_GRAY);
    b.addClickHandler(new ClickHandler() {
        @Override
        public void onClick() {
            loadGame();
        }
    });
    addGUIElement(b);
    toLayout.add(b);
    // resume game
    b = new Button(new Sprite(Assets.button), Assets.liberationMedium,
            Language.getStrings().get("menu.resumeGame"), Color.BLACK, Color.WHITE, Color.LIGHT_GRAY,
            Color.DARK_GRAY);
    b.addClickHandler(new ClickHandler() {
        @Override
        public void onClick() {
            resumeGame();
        }
    });
    addGUIElement(b);
    toLayout.add(b);
    // game name
    b = new Button(null, Assets.liberationLarge, Language.getStrings().get("game.name"), Color.ORANGE,
            Color.WHITE, Color.LIGHT_GRAY, Color.DARK_GRAY);
    addGUIElement(b);
    toLayout.add(b);

    layout(toLayout, 1, 5, 0, 0, 0, 0, 300, 60, 0, 30);

    toLayout.clear();
}

From source file:com.spaceapps.liftoffgame.actors.ButtonActor.java

public ButtonActor(Sprite image) {
    this.image = image;
    blendColor = Color.WHITE;
}

From source file:com.squidpony.pandora.PandoraGame.java

private void toggleHelp() {
    if (help != null) {
        clearHelp();//w  ww .  j  av  a2  s . co  m
        return;
    }
    final int nbMonsters = monsters.size();

    /* Prepare the String to display */
    final IColoredString<Color> cs = new IColoredString.Impl<Color>();
    cs.append("Still ", null);
    final Color nbColor;
    if (nbMonsters <= 1)
        /* Green */
        nbColor = Color.GREEN;
    else if (nbMonsters <= 5)
        /* Orange */
        nbColor = Color.ORANGE;
    else
        /* Red */
        nbColor = Color.RED;
    cs.appendInt(nbMonsters, nbColor);
    cs.append(String.format(" monster%s to kill on this floor", nbMonsters == 1 ? "" : "s"), null);

    IColoredString<Color> helping1 = new IColoredString.Impl<Color>(
            "Use numpad or vi-keys (hjklyubn) to move, bump to attack.", Color.WHITE);
    IColoredString<Color> helping2 = new IColoredString.Impl<Color>("Use ? for help, q to quit.", Color.WHITE);
    IColoredString<Color> helping3 = new IColoredString.Impl<Color>(
            "Click the top or bottom border of the lower message box to scroll.", Color.WHITE);

    /* The panel's width */
    final int w = Math.max(helping3.length(), cs.length());
    /* The panel's height. */
    final int h = 5;
    final SquidPanel bg = new SquidPanel(w, h, display.getTextFactory());
    final SquidPanel fg = new SquidPanel(w, h, display.getTextFactory());
    final GroupCombinedPanel<Color> gcp = new GroupCombinedPanel<Color>();
    /*
     * We're setting them late just for the demo, as it avoids giving 'w'
     * and 'h' at construction time.
     */
    gcp.setPanels(bg, fg);

    /*
     * Set the position (the center), using libgdx's 'setPosition'
     * method, that takes the bottom left corner as input.
     */
    gcp.setPosition((width - (w / 2)) * cellWidth, (height / 2) * cellHeight);

    /* Fill the background with some grey */
    gcp.fill(ICombinedPanel.What.BG, new Color(0.3f, 0.3f, 0.3f, 0.9f));

    /* Now, to set the text we have to follow SquidPanel's convention */
    /* First 0: align left, second 0: first line */
    gcp.putFG(0, 0, cs);

    /* 0: align left, 2: third line */
    gcp.putFG(0, 2, helping1);
    gcp.putFG(0, 3, helping2);
    gcp.putFG(0, 4, helping3);

    help = gcp;

    stage.addActor(gcp);
}

From source file:com.squidpony.the.tsar.TsarGame.java

private void toggleHelp() {
    if (help != null) {
        clearHelp();// ww w.  ja v  a2s .  c om
        return;
    }
    final int nbMonsters = monsters.size();

    /* Prepare the String to display */
    final IColoredString<Color> cs = new IColoredString.Impl<Color>();
    cs.append("Still ", null);
    final Color nbColor;
    if (nbMonsters <= 1)
        /* Green */
        nbColor = Color.GREEN;
    else if (nbMonsters <= 5)
        /* Orange */
        nbColor = Color.ORANGE;
    else
        /* Red */
        nbColor = Color.RED;
    cs.appendInt(nbMonsters, nbColor);
    cs.append(" guard" + (nbMonsters == 1 ? "" : "s") + " left", null);

    IColoredString<Color> helping1 = new IColoredString.Impl<Color>("Use numpad or vi-keys (hjklyubn) to move.",
            Color.WHITE);
    IColoredString<Color> helping2 = new IColoredString.Impl<Color>(
            "Use ? for help, f to change colors, q to quit.", Color.WHITE);
    IColoredString<Color> helping3 = new IColoredString.Impl<Color>(
            "Click the top or bottom border of the lower message box to scroll.", Color.WHITE);

    /* The panel's width */
    final int w = Math.max(helping3.length(), cs.length());
    /* The panel's height. */
    final int h = 5;
    final SquidPanel bg = new SquidPanel(w, h, display.getTextFactory());
    final SquidPanel fg = new SquidPanel(w, h, display.getTextFactory());
    final GroupCombinedPanel<Color> gcp = new GroupCombinedPanel<Color>();
    /*
     * We're setting them late just for the demo, as it avoids giving 'w'
     * and 'h' at construction time.
     */
    gcp.setPanels(bg, fg);

    /*
     * Set the position (the center), using libgdx's 'setPosition'
     * method, that takes the bottom left corner as input.
     */
    gcp.setPosition(((width / 2) - (w / 2)) * cellWidth, (height / 2) * cellHeight);

    /* Fill the background with some grey */
    gcp.fill(ICombinedPanel.What.BG, new Color(0.3f, 0.3f, 0.3f, 0.9f));

    /* Now, to set the text we have to follow SquidPanel's convention */
    /* First 0: align left, second 0: first line */
    gcp.putFG(0, 0, cs);

    /* 0: align left, 2: third line */
    gcp.putFG(0, 2, helping1);
    gcp.putFG(0, 3, helping2);
    gcp.putFG(0, 4, helping3);

    help = gcp;

    stage.addActor(gcp);
}

From source file:com.sturdyhelmetgames.roomforchange.screen.GameScreen.java

License:Apache License

@Override
public void renderScreen(float delta) {
    spriteBatch.setProjectionMatrix(camera.combined);
    spriteBatch.begin();/* ww w  .  j a va 2 s . c  o m*/
    level.render(delta, spriteBatch, false);

    final Color originalColor = spriteBatch.getColor();
    spriteBatch.setColor(1f, 1f, 1f, 1f);
    spriteBatch.draw(Assets.getFullGameObject("darkness"), camera.position.x - 7f, camera.position.y - 5f, 14f,
            10f);
    spriteBatch.setColor(originalColor);

    // calculate heart positions
    final float heartPositionX = camera.position.x - 5.9f;
    final float heartPositionY = camera.position.y + 2.9f;
    // draw player health
    final Player player = level.player;
    if (player != null) {
        for (int i = 0; i < player.maxHealth; i++) {
            final float x = heartPositionX + i * 0.55f;
            if (i < player.health) {
                spriteBatch.draw(Assets.getGameObject("heart-full"), x, heartPositionY, 1f, 1f);
            } else {
                spriteBatch.draw(Assets.getGameObject("heart-empty"), x, heartPositionY, 1f, 1f);
            }
        }
    }

    final float bombPosX = camera.position.x - 5.9f;
    final float bombPosY = camera.position.y + 3f;
    spriteBatch.draw(Assets.getGameObject("bomb-3"), bombPosX, bombPosY, 0.5f, 0.5f);
    font.draw(spriteBatch, "x" + level.player.bombs, bombPosX + 0.6f, bombPosY);

    final float gemPosX = camera.position.x + 4f;
    final float gemPosY = camera.position.y + 3.4f;

    spriteBatch.setColor(1f, 1f, 1f, 0.5f);
    spriteBatch.draw(Assets.getGameObject("black"), gemPosX - 0.05f, gemPosY - 0.05f, 3f, 1f);
    spriteBatch.setColor(originalColor);

    if (player.gotGem) {
        spriteBatch.draw(Assets.getGameObject("gem"), gemPosX, gemPosY, 0.5f, 0.5f);
    } else {
        spriteBatch.setColor(0f, 0f, 0f, 1f);
        spriteBatch.draw(Assets.getGameObject("gem"), gemPosX, gemPosY, 0.5f, 0.5f);
        spriteBatch.setColor(originalColor);
    }
    final float scrollPosX = gemPosX + 0.75f;
    final float scrollPosY = gemPosY;
    if (player.gotScroll) {
        spriteBatch.draw(Assets.getGameObject("scroll"), scrollPosX, scrollPosY, 0.5f, 0.5f);
    } else {
        spriteBatch.setColor(0f, 0f, 0f, 1f);
        spriteBatch.draw(Assets.getGameObject("scroll"), scrollPosX, scrollPosY, 0.5f, 0.5f);
        spriteBatch.setColor(originalColor);
    }
    final float talismanPosX = scrollPosX + 0.75f;
    final float talismanPosY = scrollPosY;
    if (player.gotTalisman) {
        spriteBatch.draw(Assets.getGameObject("talisman"), talismanPosX, talismanPosY, 0.5f, 0.5f);
    } else {
        spriteBatch.setColor(0f, 0f, 0f, 1f);
        spriteBatch.draw(Assets.getGameObject("talisman"), talismanPosX, talismanPosY, 0.5f, 0.5f);
        spriteBatch.setColor(originalColor);
    }

    spriteBatch.end();

    batchMiniMap.setProjectionMatrix(cameraMiniMap.combined);
    batchMiniMap.begin();
    final Color origColor = batchMiniMap.getColor();
    batchMiniMap.setColor(1f, 1f, 1f, 0.5f);
    batchMiniMap.draw(Assets.getGameObject("black"), 0f, 0f, 48f, 32f);
    batchMiniMap.setColor(origColor);
    level.render(delta, batchMiniMap, true);
    batchMiniMap.end();

    if (game.isDebug()) {
        shapeRenderer.setProjectionMatrix(camera.combined);
        shapeRenderer.begin(ShapeType.Line);

        for (int i = 0; i < level.entities.size; i++) {
            shapeRenderer.setColor(Color.WHITE);
            final Entity entity = level.entities.get(i);
            shapeRenderer.rect(entity.bounds.x, entity.bounds.y, entity.bounds.width, entity.bounds.height);

            shapeRenderer.setColor(Color.RED);
            for (int i2 = 0; i2 < entity.holes.length; i2++) {
                HoleFallWrapper hole = entity.holes[i2];
                shapeRenderer.rect(hole.bounds.x, hole.bounds.y, hole.bounds.width, hole.bounds.height);
            }
        }

        shapeRenderer.rect(level.player.hitBounds.x, level.player.hitBounds.y, level.player.hitBounds.width,
                level.player.hitBounds.height);

        shapeRenderer.end();
    }
}

From source file:com.talas777.ZombieLord.CombatEffect.java

License:Open Source License

public void applyEffect(Combatant caster, Combatant target) {
    float multiplier = 1f;
    float divisor = 1f;
    boolean critical = false;

    if (this.effectType == TYPE_MAGICAL) {
        multiplier = caster.getMATK() / 10f;
        // NOTE: cant dodge or luck magical stuffs

        if (this.element == ZombieLord.ELEM_PHYSICAL) {
            // spell that deal physical damage use DEF instead of MDEF.
            // but still no dodge or luck
            divisor = target.getDEF() / 10f;
        } else {/*from  ww  w  . j a va 2s . co  m*/
            divisor = target.getMDEF() / 10f;
        }
    } else if (this.effectType == TYPE_PHYSICAL) {
        // luck has a chance to cause 'critical hit', which is double damage (only physical attacks)

        if (caster.getCriticalHitChance() > Math.random()) {
            // critical hit!
            critical = true;
        }

        // agi can help dodge the attacker. agi also helps counter the enemys dodge attempt
        // dodging a critical hit -> normal hit

        float dodgeChance = target.getDodgeChance();
        float hitChance = caster.getHitChance();

        if (Math.random() * dodgeChance > Math.random() * hitChance) {
            // dodge!
            if (critical) {
                // hit normal
                ZombieLord.announce("Deflect!");
            } else {
                // completely dodged the attack, no damage or status changes.
                ZombieLord.announce("Dodge!");
                return;
            }
        } else if (critical) {
            // double damage
            multiplier *= 2;
            ZombieLord.announce("Critical hit!");
        }

        multiplier = caster.getATK() / 10f;
        divisor = target.getDEF() / 10f;
    }

    // else, TYPE_ITEM is not affected by atk and def

    if (divisor < 1)
        divisor = 1f;

    float elemMult = 1;

    if (this.effectType != TYPE_ITEM)
        caster.getElementStrength(this.element);

    float elemDefense = target.getElementDefense(this.element);

    double healthChange = baseHealthChange * multiplier / divisor * elemMult;
    double manaChange = baseManaChange * multiplier / divisor * elemMult;

    if (healthChange < 0.0 && this.effectType == TYPE_PHYSICAL) // minimum 1 damage physical attack (unless element immune).. so just inc by 1
        healthChange -= 1;

    // def 1 -> *= 0 -> 0 effect (no effect)
    // def 0.5 -> *= 0.5 -> 50% effect (halve)
    // def 0 -> *= 1 -> 100% effect (normal)
    // def -1 -> *= 2 -> 200% effect (double effect)
    // def 1.5 -> *= -1.5 -> -50% effect (absorb)
    healthChange *= 1 - elemDefense;
    manaChange *= 1 - elemDefense;

    /*if(elemDefense == 1){
       // no effect
       healthChange = 0;
       manaChange = 0;
    }
    else if(elemDefense > 1){
       // absorb (reverse)
       healthChange = -healthChange;
       manaChange = -manaChange;
    }
    else if (elemDefense > 0){
       // remove some amount of damage
       healthChange *= 1-elemDefense;
       manaChange *= 1-elemDefense;
    }*/

    System.out.println("mul:" + multiplier + ", div:" + divisor + ", dmg: " + healthChange);
    Sprite s = target.getSprite();
    int posOffset = 32;
    if (s != null)
        ZombieLord.addFloatingNumbers((int) (Math.abs(healthChange)), s.getX() + posOffset,
                s.getY() + posOffset, (healthChange <= 0 ? Color.WHITE : Color.GREEN));
    if (healthPercent) { // percent changes are not affected by atk and def
        healthChange *= baseHealthChange;
    }
    if (manaPercent) { // percent changes are not affected by atk and def
        manaChange *= baseManaChange;
    }

    target.health += healthChange;
    target.mana += manaChange;

    if (target.health < 0)
        target.health = 0;
    if (target.health > target.getHealthMax())
        target.health = target.getHealthMax();

    if (target.mana < 0)
        target.mana = 0;
    if (target.mana > target.getManaMax())
        target.mana = target.getManaMax();

    for (StatusChange statusChange : statusChanges) {
        if (Math.random() < (critical ? statusChange.chance * 2 : statusChange.chance)) {
            // apply status change..

            if (critical && statusChange.status == Combat.STATE_POISONED) {
                // critical hit + poison -> double strength poison
                target.addStatusChange(statusChange.status, statusChange.state, statusChange.strength * 2);
            } else
                target.addStatusChange(statusChange.status, statusChange.state, statusChange.strength);
        }
    }

    for (AttributeChange change : this.attributeChanges) {
        if (Math.random() < (critical ? change.chance * 2 : change.chance)) {
            // apply attribute change

            if (change.duration == 0) {
                // permanent
                switch (change.attribute) {
                case STAT_STR:
                    // str
                    target.addStrength(change.change);
                    break;
                case STAT_VIT:
                    // vit
                    target.addVitality(change.change);
                    break;
                case STAT_AGI:
                    // agi
                    target.addAgility(change.change);
                    break;
                case STAT_INT:
                    // int
                    target.addIntelligence(change.change);
                    break;
                case STAT_WIS:
                    // wis
                    target.addWisdom(change.change);
                    break;
                case STAT_SPR:
                    // spr
                    target.addSpirit(change.change);
                    break;
                case STAT_LUCK:
                    // luck
                    target.addLuck(change.change);
                    break;
                default:
                    // error
                    System.err
                            .println("ERROR: status change " + change.attribute + " does not exist (yet)[1]!");
                    break;
                }
            } else {
                target.addTemporaryAttribute(change.attribute, change.change, change.duration);
            }
        }
    }
}

From source file:com.talas777.ZombieLord.Menu.java

License:Open Source License

public void draw(SpriteBatch batch) {
    int posx = 355;
    int posy = 313;
    switch (currentWindow) {

    case WINDOW_MAIN:
        drawParty(batch, 1, false);//from  www.j a va 2  s  . com
        ninePatch.draw(batch, posx - 55, posy - 7 * lineSpace, 180, 7 * lineSpace + 5);
        font.setColor(Color.WHITE);
        font.draw(batch, "Item", posx, posy - 0 * lineSpace);
        font.draw(batch, "Character", posx, posy - 1 * lineSpace);
        font.setColor(Color.GRAY);
        font.draw(batch, "Magic", posx, posy - 2 * lineSpace);
        font.setColor(Color.WHITE);
        font.draw(batch, "Quest", posx, posy - 3 * lineSpace);
        font.setColor(Color.GRAY);
        font.draw(batch, "Save", posx, posy - 4 * lineSpace);
        font.draw(batch, "Option", posx, posy - 5 * lineSpace);
        font.setColor(Color.WHITE);
        font.draw(batch, "Quit", posx, posy - 6 * lineSpace);
        cursor.setX(posx - 40);
        cursor.setY(posy - 2 - lineSpace - selectedOption * lineSpace);
        cursor.draw(batch);

        break;
    case OPTION_USE_ITEM:
    case WINDOW_ITEM:
        drawParty(batch, 0, true);
        int numItems = Math.min(party.getInventory().getNumItems(), 16);
        posx = 265;
        ninePatch.draw(batch, posx - 85, posy - numItems * lineSpace, 280, numItems * lineSpace + 5);
        int j = 0;
        for (Item i : party.getInventory().getItems()) {
            font.setColor(Color.GRAY);
            if (i instanceof ConsumeableItem) {
                ConsumeableItem it = (ConsumeableItem) i;
                if (it.nonCombatAllowed())
                    font.setColor(Color.WHITE);
            }
            font.draw(batch, party.getInventory().getItemCount(i) + "x " + i.name, posx - 50,
                    posy - lineSpace * j);
            j++;
        }
        if (this.selectedItem == null) {
            cursor.setX(posx - 40 - 45);
            cursor.setY(posy - 2 - lineSpace - selectedOption * lineSpace);
            cursor.draw(batch);
        } else {
            cursor.setX(posx - 40 - 45);
            cursor.setY(posy - 2 - lineSpace - this.selectedItemNumber * lineSpace);
            cursor.draw(batch);

            cursor.setX(40);
            cursor.setY(posy - 20 - lineSpace - this.selectedOption * 100);
            cursor.draw(batch);
        }
        break;
    case WINDOW_CHARACTER:
        drawParty(batch, 2, true);
        break;
    case WINDOW_QUEST:
        posx = 135;
        posy = 200;
        font.draw(batch, "Current Objective: ", posx, posy + lineSpace);
        font.draw(batch, this.questHint, posx, posy);
    }

}

From source file:com.talas777.ZombieLord.Menu.java

License:Open Source License

private void drawParty(SpriteBatch batch, int full, boolean pushBack) {
    int ms = 106;
    int m = 213;//from   w ww .j a  v  a2  s.co m
    int p = 50;

    if (full == 0)
        p -= 20;

    if (pushBack)
        p -= 25;

    PartyMember[] members = party.getActiveMembers();
    for (int i = 0; i < members.length && i < 3; i++) {
        // if for some reason we have 4 members, we still only care about 3..

        if (full == 1) {
            ninePatch.draw(batch, p - 20, m - ms * i, 260, 105);
        } else if (full == 2) {
            ninePatch.draw(batch, p - 20, m - ms * i, 475, 105);
        } else {
            ninePatch.draw(batch, p - 5, m - ms * i, 170, 105);
        }
        // draw the members ugly mug shot
        if (full != 0) {
            Texture t = members[i].getFace();
            Sprite s = new Sprite(t);
            s.scale(-0.29f);
            s.setPosition(p - 30, m - ms * i - 11);
            s.draw(batch);
        }
        font.setColor(Color.WHITE);
        int cur = members[i].getHealth();
        int max = members[i].getHealthMax();
        if (cur < max / 2f) {
            font.setColor(Color.YELLOW);
            if (members[i].getHealth() == 0)
                font.setColor(Color.GRAY);
        }
        font.draw(batch, members[i].getName(), p, m - ms * i + 20);

        int base = 80;

        if (full == 0)
            base = 5;

        font.draw(batch, "LVL: " + members[i].getLevel(), base + p, m - ms * i + 100);

        String xpString = "error";
        Color old = font.getColor();
        if (members[i].getLevel() == ZombieLord.MAX_PLAYER_LEVEL) {
            xpString = " --- ";
            font.setColor(Color.BLACK);
        } else
            xpString = members[i].getExperience() + "/"
                    + PartyMember.getExperienceForLevel(members[i].getLevel() + 1);
        font.draw(batch, "XP: " + xpString, base + p, m - ms * i + 85);
        font.setColor(old);

        font.draw(batch, "HP: " + cur + "/" + max, base + p, m - ms * i + 70);
        font.draw(batch, "MP: " + members[i].getMana() + "/" + members[i].getManaMax(), base + p,
                m - ms * i + 55);
        if (full == 2) {
            // draw all data
            font.draw(batch, "STR: " + members[i].getStrength(), 240 + p, m - ms * i + 100);
            font.draw(batch, "VIT: " + members[i].getVitality(), 350 + p, m - ms * i + 100);
            //font.draw(batch, "VIT: "+members[i].getVitality(), 240+p, m-ms*i+85);

            //font.draw(batch, "AGI: "+members[i].getAgility(), 240+p, m-ms*i+70);
            font.draw(batch, "INT: " + members[i].getIntelligence(), 240 + p, m - ms * i + 85);
            //font.draw(batch, "INT: "+members[i].getIntelligence(), 240+p, m-ms*i+55);
            font.draw(batch, "WIS: " + members[i].getWisdom(), 350 + p, m - ms * i + 85);
            font.draw(batch, "SPR: " + members[i].getSpirit(), 240 + p, m - ms * i + 70);
            font.draw(batch, "AGI: " + members[i].getAgility(), 350 + p, m - ms * i + 70);
            font.draw(batch, "LUCK: " + members[i].getLuck(), 240 + p, m - ms * i + 55);
        }
    }
}

From source file:com.talas777.ZombieLord.ZombieLord.java

License:Open Source License

public void drawCombatUISprites(SpriteBatch batch) {
    //LinkedList<Sprite> list = new LinkedList<Sprite>();

    //first make sprites for leoric.. hes always there and always nr.1 (atleast for now)

    PartyMember[] activeMembers = this.party.getActiveMembers();

    int num = 0;/*w w w  . j  a v a 2 s  . c om*/
    int fontOffset = 14;

    for (PartyMember m : activeMembers) {

        // draw characters name

        int healthPercent = (int) Math.min(100,
                Math.max(0, Math.ceil(((m.getHealth() + 0.0f) / m.getHealthMax()) * 100)));
        Color fontColor = Color.WHITE;
        if (m.getHealth() == 0)
            fontColor = Color.GRAY;
        else if (healthPercent <= 10)
            fontColor = Color.YELLOW;

        font.setColor(fontColor);
        smallFont.setColor(fontColor);
        font.draw(batch, m.getName(), 10, 67 - 32 * num + fontOffset);

        // draw the red inside the hp bar
        if (m.getHealth() > 0)
            barHp.draw(batch, 102 + 4, 67 - 32 * num + 1, healthPercent, 17);

        //Sprite myHp = new Sprite(hpTex,0,0+19*healthPerdeca,106,19);
        Sprite myHp = new Sprite(hpTex, 0, 0, 106, 19);
        myHp.setX(102);
        myHp.setY(67 - 32 * num);
        myHp.draw(batch);
        String healthstr = m.getHealth() + "/" + m.getHealthMax();
        smallFont.draw(batch, healthstr, 102 + 60 - (healthstr.length() / 2) * 13,
                67 - 32 * num + fontOffset + 2);

        int manaPercent = (int) Math.min(100,
                Math.max(0, Math.ceil(((m.getMana() + 0.0f) / m.getManaMax()) * 100)));
        if (m.getMana() > 0)
            barMp.draw(batch, 230 + 4, 67 - 32 * num + 1, manaPercent, 17);
        Sprite myMp = new Sprite(mpTex, 0, 0, 106, 19);
        myMp.setX(230);
        myMp.setY(67 - 32 * num);
        myMp.draw(batch);
        String manastr = m.getMana() + "/" + m.getManaMax();
        smallFont.draw(batch, manastr, 230 + 60 - (manastr.length() / 2) * 13, 67 - 32 * num + fontOffset + 2);

        int timePercent = (int) Math.min(100, Math.max(0, Math.round(((m.actionTimer + 0.0f) / 100f) * 100)));
        if (m.getHealth() > 0)
            barTime.draw(batch, 358 + 4, 67 - 32 * num + 1, 100 - timePercent, 17);
        Sprite myTime = new Sprite(tmTex, 0, 19 * 10, 106, 19);
        myTime.setX(358);
        myTime.setY(67 - 32 * num);
        myTime.draw(batch);

        num++;
    }
    font.setColor(Color.WHITE);
    smallFont.setColor(Color.WHITE);
}

From source file:com.talas777.ZombieLord.ZombieLord.java

License:Open Source License

@Override
public void render() {

    if (this.menu != null) {
        if (this.menu.isDead()) {
            // menu is scheduled for deletion, so carry it out
            this.menu.dispose();
            this.menu = null;
            this.gameMode = MODE_MOVE;
        }/*from ww  w .  j  ava2 s. c  o  m*/
    }

    if (musicVolume < 1f) {
        musicVolume += Gdx.graphics.getDeltaTime() / 10f;
        if (musicVolume > 1f) {
            musicVolume = 1f;
            System.out.println("Done fading..");
        }
        fadingMusic.setVolume(musicVolume * this.globalMusicVolume);
    }

    if (musicPause > 0) {
        musicPause -= Gdx.graphics.getDeltaTime();
        if (musicPause <= 0) {
            musicPause = 0;
            // resume music
            if (this.combatMusic != null)
                this.combatMusic.play();

            else if (this.currentMusic != null)
                this.currentMusic.play();
        }

        else {
            // pause music or keep it paused
            if (this.combatMusic != null)
                this.combatMusic.pause();

            if (this.currentMusic != null)
                this.currentMusic.pause();
        }
    }

    if (this.fallingTexture != null) {
        if (this.falling == null) {
            this.falling = new Array<Sprite>();
        }
        //System.out.println("rain: "+this.falling.size);
        // pour de rain (Count de money)
        //for(int i = 0; i < this.fallingDensity; i++){
        if (this.falling.size < this.fallingDensity) {
            Sprite newDrop = new Sprite(fallingTexture, 0, 0, 8, 8);
            newDrop.setY(posy + h);
            newDrop.setX(posx - 20 - w / 2 + (float) Math.random() * (w + 20));
            this.falling.add(newDrop);
            this.drawSprites.add(newDrop);
        }
        Iterator<Sprite> iter = falling.iterator();
        while (iter.hasNext()) {
            Sprite s = iter.next();
            s.setY(s.getY() - this.fallSpeed * Gdx.graphics.getDeltaTime());
            if (posy + h / 2 - s.getY() > this.minFallDist) {
                // OK to delete?
                if (posy + h / 2 - s.getY() >= this.maxFallDist) {
                    this.drawSprites.remove(s);
                    iter.remove();
                } else if (Math.random() * 100 > 90) {
                    addAnimation(new Sprite(new Texture(Gdx.files.internal("data/rain_splash.png"))),
                            (int) s.getX(), (int) s.getY(), 3);
                    this.drawSprites.remove(s);
                    iter.remove();
                }

            }
        }
    } else if (this.falling != null) {
        // Clean up rain..
        Iterator<Sprite> iter = falling.iterator();
        while (iter.hasNext()) {
            Sprite s = iter.next();
            this.drawSprites.remove(s);
            iter.remove();
        }
        this.falling = null;
    }

    if (gameMode == MODE_DIALOG) {
        // a Dialog is active or using the menus?

        if (this.currentDialog == null) {
            // menu
            // TODO: ???
        } else {
            // dialog
            if (this.dialogWait > 0) {
                this.dialogTicker += Gdx.graphics.getDeltaTime() * 20;
                if (Gdx.input.isButtonPressed(Keys.ENTER))// Speed up the dialog a bit
                    dialogWait = 0;
                else
                    dialogWait -= Gdx.graphics.getDeltaTime();

            } else if (this.currentDialog.hasNextUtterance()) {
                //TODO: this has to be done more nicely somehow..

                Utterance u = this.currentDialog.getNextUtterance();

                System.out.print(u.speaker + ": ");
                //System.out.println(u.sentence);

                this.curSpeaker = u.speaker;
                this.curSentence = u.getSentence();
                this.dialogTicker = 1;
                //for(int i = 0; i < this.curSentence.length; i++)
                //   System.out.println("_"+this.curSentence[i]+"_");

                dialogWait = (u.length * 0.07f); // TODO: hum hum
                if (dialogWait < 1.7f)
                    dialogWait = 1.7f;

            } else {
                // apply secondary effects and change gameMode back to whatever normal is
                // TODO: would be nice if dialogs could be had inside combat also..
                // but not strictly required.
                this.curSpeaker = null;
                this.curSentence = null;

                if (this.currentDialog.questHint != null) {
                    this.questHint = this.currentDialog.questHint;
                }

                if (this.currentDialog.getTimeChange() != null) {
                    this.timeTracker.setTime(this.currentDialog.getTimeChange());
                }

                ZombieDefense zd = this.currentDialog.getZombieDefense();
                if (zd != null) {
                    // Start zombie defense by going to the correct game mode..
                    this.gameMode = MODE_ZOMBIE_DEFENSE;
                    this.loadZombieDefense(zd);

                    // Zombie Defense has highest priority.
                    this.currentDialog = null;
                    return;
                }

                MonsterSetup setup = this.currentDialog.getFight();

                for (PartyMember joiner : this.currentDialog.getMemberJoins()) {
                    this.party.addMember(joiner);
                }

                if (this.currentDialog.nextLevel != null) {
                    // Level change..

                    if (setup != null) {
                        // after fight..
                        this.returnLevel = this.currentDialog.nextLevel;
                        this.posx = this.currentDialog.posx;
                        this.posy = this.currentDialog.posy;
                        this.lastDirection = this.currentDialog.direction;
                    }
                }
                if (setup != null) {
                    // fight!
                    this.loadCombat(setup);
                } else if (this.currentDialog.nextLevel != null) {
                    // change level

                    this.loadLevel(this.currentDialog.nextLevel, this.currentDialog.posx,
                            this.currentDialog.posy, this.currentDialog.direction);
                } else {
                    // No combat, no Level change..
                    // Guess we just have to go back to normal then :<
                    this.gameMode = MODE_MOVE;
                    return;
                }
                this.currentDialog = null;

            }
        }

    }

    boolean left = false;
    boolean right = false;
    boolean up = false;
    boolean down = false;

    if (gameMode == MODE_MOVE) {
        if (returnLevel instanceof MyHouse) {
            if (moverTimer > 0) {
                // load princess
                this.moverTimer -= Gdx.graphics.getDeltaTime();

                if (moverTimer <= 0) {
                    this.mover.setTexture(new Texture(Gdx.files.internal("data/princess.png")));
                    mover.setRegion(0, 64 * 2, 64, 64);
                }
            } else if (this.timeTracker.hasOccured("talk with gf")) {
                // unload princess
                this.mover.getTexture().dispose();
                this.drawSprites.remove(mover);
            }
        }
        if (returnLevel instanceof Church) {
            if (this.timeTracker.hasOccured(("zero"))) {
                // unload dead priest
                this.mover.getTexture().dispose();
                this.drawSprites.remove(mover);
            }
        }

        if (Gdx.input.isKeyPressed(Keys.UP)) {
            //System.out.println("damop:"+jumper.getLinearDamping());
            jumper.applyLinearImpulse(new Vector2(0.0f, moveSpeed), jumper.getWorldCenter());
            posy += (100 * Gdx.graphics.getDeltaTime());
            up = true;
        }
        if (Gdx.input.isKeyPressed(Keys.DOWN)) {
            jumper.applyLinearImpulse(new Vector2(0.0f, -moveSpeed), jumper.getWorldCenter());
            posy -= (100 * Gdx.graphics.getDeltaTime());
            down = true;
        }

        if (Gdx.input.isKeyPressed(Keys.LEFT) && !up && !down) {
            jumper.applyLinearImpulse(new Vector2(-moveSpeed, 0.0f), jumper.getWorldCenter());
            posx -= (100 * Gdx.graphics.getDeltaTime());
            left = true;
        }

        if (Gdx.input.isKeyPressed(Keys.RIGHT) && !up && !down) {
            jumper.applyLinearImpulse(new Vector2(moveSpeed, 0.0f), jumper.getWorldCenter());
            posx += (100 * Gdx.graphics.getDeltaTime());
            right = true;
        }
    }

    if (Gdx.input.isKeyPressed(Keys.ESCAPE)) //TODO: confirm dialog
        Gdx.app.exit();

    //camera.lookAt(princess.getX(), princess.getY(), 0);
    //background.scroll(posx, posy);
    //background.

    /*background.setX(posx);
    background.setY(posy);
    collisionLayer.setX(posx);
    collisionLayer.setY(posy);
    */

    if (gameMode == MODE_MOVE) {
        world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3);

        posx = jumper.getPosition().x * PIXELS_PER_METER;
        posy = jumper.getPosition().y * PIXELS_PER_METER;
        leoricSprite.setX(posx - 32);
        leoricSprite.setY(posy - 10);
        pointer.setTransform(jumper.getPosition().x, jumper.getPosition().y, 0);

        camera.position.x = leoricSprite.getX() + 32;
        camera.position.y = leoricSprite.getY() + 16;

        if ((left || right || up || down) && this.levelLoadGraceTime <= 0) {
            // Only attract monsters and dialogs when moving

            if (this.activeDialogs != null && this.activeDialogs.size() > 0) {
                for (Dialog d : activeDialogs) {

                    if (d.isInside((int) posx, (int) posy, timeTracker)) {
                        boolean activate = false;
                        // button?
                        if (d.button != 0) {
                            activate = Gdx.input.isKeyPressed(d.button);
                        } else
                            activate = true;

                        if (activate) {
                            // Start the dialog
                            this.gameMode = MODE_DIALOG;
                            this.currentDialog = d;
                            return;
                        }

                    }
                }
            }

            if (this.activeMonsterAreas != null && this.activeMonsterAreas.size() > 0) {

                if (this.nextCombat > 0) { // Try to limit how often you have to fight somewhat..
                    nextCombat -= Gdx.graphics.getDeltaTime();
                } else {
                    for (MonsterArea area : activeMonsterAreas) {
                        // check if player is inside it
                        if (area.isInside((int) posx, (int) posy)) {

                            // roll a dice to find out if the player should be attacked.
                            float num = (float) Math.random();

                            //if(Math.random()*100>90)
                            //System.out.println(num+" v.s. "+area.encounterChance);

                            if (num < area.encounterChance) {
                                // we have a winner..
                                nextCombat = 10f; // aprox 10 seconds to next fight?
                                this.loadCombat(area);
                                return; // TODO: not sure if this is a good idea or bad
                                // either return or break..
                            }

                        }

                    }
                }
            }
        } else if (this.levelLoadGraceTime > 0) {
            this.levelLoadGraceTime -= Gdx.graphics.getDeltaTime();
        }

        if (Gdx.input.isKeyPressed(Keys.B)) {
            System.out.println("position: x=" + posx + ", y=" + posy + ", time=" + timeTracker.getTime()
                    + ", cam:[" + camera.position.x + "," + camera.position.y + "].");
        }

        if (Gdx.input.isKeyPressed(Keys.D)) {
            this.debug = !this.debug;
            System.out.println("debug :" + (this.debug ? "On" : "Off"));
            if (debug)
                this.moveSpeed += 0.02f;
            else
                this.moveSpeed -= 0.02f;
        }

        // Keep the camera inside the level.. Maybe too aggressive?
        if (camera.position.y <= h / 2 + this.camMinY)
            camera.position.y = h / 2 + 1 + this.camMinY;
        else if (camera.position.y >= this.camMaxY - h / 2)
            camera.position.y = this.camMaxY - h / 2 - 1;

        if (camera.position.x <= w / 2 + this.camMinX)
            camera.position.x = w / 2 + 1 + this.camMinX;
        else if (camera.position.x >= this.camMaxX - w / 2)
            camera.position.x = this.camMaxX - w / 2 - 1;

        camera.update();

        if (stillTime > 0)
            stillTime -= Gdx.graphics.getDeltaTime();

        int frame = (int) Math.ceil(currentWalkFrame) + 0;
        if (up == true) {
            lastDirection = 0;
            leoricSprite.setRegion(64 * frame, 0, 64, 64);
            //princess = new Sprite(texture2, 0, 64*2, 64, 0);
        } else if (down == true) {
            lastDirection = 1;
            leoricSprite.setRegion(64 * frame, 64 * 2, 64, 64);
            //princess = new Sprite(texture2, 0, 64*2, 64, 64);
        } else if (left == true) {
            lastDirection = 3;
            leoricSprite.setRegion(64 * frame, 64 * 1, 64, 64);
            //princess = new Sprite(texture2, 0, 64*2, 64, 128);
        } else if (right == true) {
            leoricSprite.setRegion(64 * frame, 64 * 3, 64, 64);
            lastDirection = 2;
            //princess = new Sprite(texture2, 0, 64*2, 64, 128+64);
        }

        if (left || right) {
            currentWalkFrame = (float) (currentWalkFrame >= 7 - 0.20 ? 0 : currentWalkFrame + 0.10);
            stillTime = 0.1f;
        } else if (up || down || left || right) {
            currentWalkFrame = (float) (currentWalkFrame >= 8 - 0.10 ? 1 : currentWalkFrame + 0.10);
            stillTime = 0.1f;
        } else if (stillTime <= 0) { // stop the animation.
            currentWalkFrame = 0;
            switch (lastDirection) {
            case 0:
                //north
                leoricSprite.setRegion(0, 0, 64, 64);
                break;
            case 2:
                //east
                leoricSprite.setRegion(0, 64 * 3, 64, 64);
                break;
            case 3:
                //west
                leoricSprite.setRegion(0, 64 * 1, 64, 64);
                break;
            default:
                //south
                leoricSprite.setRegion(0, 64 * 2, 64, 64);
                break;

            }
        }
    }

    boolean waiting = false; //TODO: move this? guess not

    if (waitTime > 0) {
        waiting = true;
        waitTime -= Gdx.graphics.getDeltaTime();
    }
    if (gameMode == MODE_FIGHT && this.currentCombat.waitingForPlayerCommand)
        waiting = true;

    if (gameMode == MODE_VICTORY) {
        // "After Combat" screen
        if (currentCombat != null) {
            // clean up!
            //for(Sprite s : drawSprites){
            //s.getTexture().dispose();
            //}
            drawSprites.clear();

            //TODO: display some info about the fight..
            //TODO: give items and stuffs
            party.addExperience(currentCombat.setup.exp);

            currentCombat.cleanUp();
            currentCombat = null;
            waitTime = 4f;
            waiting = true;

            this.backgroundTexture = new Texture(Gdx.files.internal("data/victory.png"));
            this.background = new Sprite(backgroundTexture, 0, 0, 480, 320);

        }

        if (!waiting || this.debug) {
            waiting = false;
            waitTime = 0;
            this.returnFromCombat();
            return; // TODO: not sure if this is a good idea or bad
        }
    }

    else if (gameMode == MODE_GAMEOVER) {
        // Game over
        //TODO: write something 'nice' to the screen?
        this.backgroundTexture = new Texture(Gdx.files.internal("data/gameover.png"));
        this.background = new Sprite(backgroundTexture, 0, 0, 480, 320);
        this.drawSprites.clear();

    }

    else if (gameMode == MODE_FIGHT) {

        // Re-position all creatures..
        for (int i = 0; i < currentCombat.getLiveCombatants().size(); i++) {
            Combatant current = currentCombat.getLiveCombatants().get(i);

            switch (current.getTerminalState()) {
            case Combat.STATE_STONE:
                current.getSprite().setColor(Color.GRAY);
                // render as grey (as stone)
                break;
            case Combat.STATE_POISONED:
                current.getSprite().setColor(Color.GREEN);
                // render as green
                break;
            case Combat.STATE_FURY:
                current.getSprite().setColor(Color.RED);
                // render as red
                break;
            case Combat.STATE_WEAKNESS:
                current.getSprite().setColor(Color.YELLOW);
                // render as pale yellow
                break;
            case Combat.STATE_DOOM:
                current.getSprite().setColor(Color.BLACK);
                // render as dark
                break;
            default:
                current.getSprite().setColor(Color.WHITE);
                break;
            }
        }

        // carry out player commands
        if (this.currentCombat.waitingForPlayerCommand && this.finishedChoosing == true) {

            if (this.selectedCombatOption.subGroup == false && this.selectedCombatOption.hardCoded) {
                // player chose a hardcoded option.
                if (this.selectedCombatOption == ZombieLord.defend) {
                    // TODO: defend if possible
                    // For now, we just wait a turn when defending (so its near useless).
                    this.currentCombat.resetActionTimer(this.combatOptionCaster);

                    waiting = true;
                    waitTime = 0.3f;
                    this.currentCombat.waitingForPlayerCommand = false;
                    this.selectedCombatOption = null;
                    this.currentCombatOptions = null;
                    this.combatOptionCaster = null;
                    this.finishedTargeting = false;
                    this.finishedChoosing = false;
                    this.validTargets = null;
                    this.selectedTarget = null;
                } else if (this.selectedCombatOption == ZombieLord.escape) {
                    if (Math.random() < this.currentCombat.getEscapeChance()) {
                        // escape!
                        this.returnFromCombat();
                        return;
                    } else {
                        waiting = true;
                        waitTime = 0.3f;
                        this.currentCombat.waitingForPlayerCommand = false;
                        this.selectedCombatOption = null;
                        this.currentCombatOptions = null;
                        this.combatOptionCaster = null;
                        this.finishedTargeting = false;
                        this.finishedChoosing = false;
                        this.validTargets = null;
                        this.selectedTarget = null;
                    }
                } else if (this.selectedCombatOption == ZombieLord.item) {
                    // have to pull up a submenu with all combat items.
                    this.currentCombatOptions = new LinkedList<CombatOption>();
                    Inventory inventory = party.getInventory();
                    LinkedList<Item> items = inventory.getCombatItems();
                    for (Item i : items) {
                        this.currentCombatOptions.add(new CombatOption(i));
                    }

                    this.selectedCombatOption = this.currentCombatOptions.getFirst();
                    this.finishedChoosing = false;
                    System.out.println("subgroup");

                    // TODO: make combatoptions for each combat item (+ count)
                    // then serve to player just like with magics
                }
            } else if (this.selectedCombatOption.subGroup == false) {
                // player has selected an option which we can carry out.. so lets!

                if (!this.finishedTargeting && this.selectedTarget == null) {
                    // TODO: well?

                    if (this.selectedCombatOption.item == null) {
                        // Not trying to use an item
                        CombatAction action = this.selectedCombatOption.associatedActions.getFirst();

                        this.validTargets = this.currentCombat.getValidTargets(action, this.combatOptionCaster);
                        // NOTE: for attacks that target 'all *' or 'random *', this is also fine and handled elsewhere.
                        this.selectedTarget = validTargets.getFirst();

                        this.targeting = new Targeting(action.targetType, validTargets, this.combatOptionCaster,
                                action.offensive);

                    } else {
                        // Trying to use an item
                        // targeting for items is a little strange i guess..
                        if (this.selectedCombatOption.item instanceof ConsumeableItem) {
                            ConsumeableItem item = (ConsumeableItem) this.selectedCombatOption.item;
                            CombatAction action = item.getEffect();

                            this.validTargets = new LinkedList<Combatant>();
                            for (Combatant c : this.currentCombat.getLiveCombatants())
                                this.validTargets.add(c);
                            if (item.offensive) {
                                // target first enemy..
                                this.selectedTarget = this.currentCombat.getLiveMonsters().getFirst();
                            } else {
                                // target self
                                this.selectedTarget = this.combatOptionCaster;
                            }
                            System.out.println("item");

                            this.targeting = new Targeting(action.targetType, validTargets,
                                    this.combatOptionCaster, item.offensive);

                        } else {
                            // TODO: non-consumable items in combat?
                            System.err.println(
                                    "[ERROR] Non consumeable item in combat? Have to write the code first then! 1");
                        }
                    }
                }

                else if (this.finishedTargeting) {
                    if (this.selectedCombatOption.item != null) {
                        // player wants to use an item
                        if (this.selectedCombatOption.item instanceof ConsumeableItem) {
                            ConsumeableItem i = (ConsumeableItem) this.selectedCombatOption.item;
                            CurrentAction myAction = new CurrentAction(i.getEffect(), this.combatOptionCaster,
                                    this.targeting);
                            LinkedList<Combatant> affected = currentCombat.applyAction(myAction);

                            myAction.caster.setMoveAhead(true);

                            if (myAction.action.effect != null && affected != null) {

                                for (Combatant c : affected) {
                                    Sprite effect = new Sprite(myAction.action.effect);
                                    effect.setX(c.getSprite().getX() + 16);
                                    effect.setY(c.getSprite().getY() + 16);
                                    this.combatEffects.add(effect);
                                }
                            }

                            // take the item
                            party.getInventory().removeItem(i, (byte) 1);

                            this.currentCombat.resetActionTimer(this.combatOptionCaster);

                            waiting = true;
                            waitTime = 2;
                            this.currentCombat.waitingForPlayerCommand = false;
                            this.selectedCombatOption = null;
                            this.currentCombatOptions = null;
                            this.combatOptionCaster = null;
                            this.finishedTargeting = false;
                            this.finishedChoosing = false;
                            this.validTargets = null;
                            this.selectedTarget = null;

                        } else {
                            System.err.println(
                                    "[ERROR] Non consumeable item in combat? Have to write the code first then! 2");
                        }
                    } else {
                        CurrentAction myAction = new CurrentAction(
                                this.selectedCombatOption.associatedActions.getFirst(), this.combatOptionCaster,
                                this.targeting);

                        LinkedList<Combatant> affected = currentCombat.applyAction(myAction);

                        if (myAction.action != null && affected != null) {
                            // Move player against monster to represent the attack

                            if (myAction.caster == Tolinai) { // TODO: simple hack to get sound..
                                ZombieLord.playSound("data/sound/woodenstickattack.wav", 1f);
                            }
                            if (myAction.caster == Leoric) { // TODO: simple hack to get sound..
                                ZombieLord.playSound("data/sound/cut.wav", 1f);
                            }

                            announce(myAction.action.name);
                            myAction.caster.setMoveAhead(true);

                            if (myAction.action.effect != null && affected != null) {

                                for (Combatant c : affected) {
                                    Sprite effect = new Sprite(myAction.action.effect);
                                    effect.setX(c.getSprite().getX() + 16);
                                    effect.setY(c.getSprite().getY() + 16);
                                    this.combatEffects.add(effect);
                                }
                            }
                        }
                        if (this.debug) {
                            // time to stop this nonsense!
                            for (Monster m : currentCombat.getLiveMonsters()) {
                                m.health = 0;
                            }
                        }

                        this.currentCombat.resetActionTimer(this.combatOptionCaster);

                        waiting = true;
                        waitTime = 2;
                        this.currentCombat.waitingForPlayerCommand = false;
                        this.selectedCombatOption = null;
                        this.currentCombatOptions = null;
                        this.combatOptionCaster = null;
                        this.finishedTargeting = false;
                        this.finishedChoosing = false;
                        this.validTargets = null;
                        this.selectedTarget = null;
                    }
                }
            } else {
                // this action has a subgroup.. player needs to choose from these also
                LinkedList<CombatAction> actions = this.selectedCombatOption.associatedActions;
                this.currentCombatOptions = new LinkedList<CombatOption>();
                for (CombatAction act : actions)
                    this.currentCombatOptions.add(new CombatOption(act.name, act));

                this.selectedCombatOption = this.currentCombatOptions.getFirst();
                this.finishedChoosing = false;
                System.out.println("subgroup");

            }

        }

        for (Combatant c : this.currentCombat.getCombatants()) {
            if (c.health <= 0) {
                // dead..
                if (c instanceof PartyMember) {
                    // TODO: some effect here
                } else if (c instanceof Monster) {
                    Monster m = (Monster) c;

                    if (m.alpha == Monster.ALPHA_START) {
                        Color red = Color.RED;
                        m.getSprite().setColor(red);
                    }
                    if (m.alpha > 0f) {
                        m.alpha -= m.fadeSpeed * Gdx.graphics.getDeltaTime();
                    }
                    if (m.alpha < 0) {
                        m.alpha = 0;
                    }
                }
            }
        }

        //check if battle is over.
        if (!waiting) {
            byte state = currentCombat.getBattleState();

            for (int i = 0; i < currentCombat.getLiveCombatants().size(); i++) {
                currentCombat.getLiveCombatants().get(i).setMoveAhead(false);
            }
            this.combatEffects.clear();

            if (state == 1) {
                // player has won
                // check if all monsters are done fading out..
                boolean fadingDone = true;
                for (Combatant c : currentCombat.getCombatants())
                    if (c instanceof Monster && ((Monster) c).alpha != 0)
                        fadingDone = false;

                if (fadingDone) { // WIN
                    waiting = true;
                    System.out.println("VICTORY! :>");
                    //TODO: happy trumpet
                    gameMode = MODE_VICTORY;
                    this.combatEffects.clear();
                }
                // else, wait for fading to finish..

            } else if (state == 2) {
                // player has lost
                this.gameOver();
            }

            Monster readyMonster = currentCombat.getFirstReadiedMonster();
            if (readyMonster != null && currentCombat.getLivePlayers().size() > 0) {

                CurrentAction myAction = readyMonster.getMonsterAction(party, currentCombat);

                LinkedList<Combatant> affected = currentCombat.applyAction(myAction);

                if (myAction.action != null) {
                    // Move monster against player to represent the attack

                    announce(myAction.action.name);
                    myAction.caster.setMoveAhead(true);

                    if (myAction.action.effect != null && affected != null) {

                        if (myAction.action == BITE) { // TODO: simple hack to get sound..
                            ZombieLord.playSound("data/sound/zombiebite.wav", 1f);
                        }
                        if (myAction.action == PUNCH) { // TODO: simple hack to get sound..
                            ZombieLord.playSound("data/sound/woodenstickattack.wav", 1f);
                        }

                        for (Combatant c : affected) {
                            Sprite effect = new Sprite(myAction.action.effect);
                            effect.setX(c.getSprite().getX() + 16);
                            effect.setY(c.getSprite().getY() + 16);
                            this.combatEffects.add(effect);
                        }
                    }

                }

                readyMonster.actionTimer = readyMonster.getBaseDelay() * (1.5f * Math.random() + 0.5f);// TODO: randomize better?

                waiting = true;
                waitTime = 2;
                // Only 1 attacker per turn.
            }
            if (!waiting && currentCombat.getLiveMonsters().size() > 0) {
                PartyMember readyMember = currentCombat.getFirstReadiedPlayer();
                if (readyMember != null) {

                    // Find the options..

                    // find out which 'global groups are available..
                    boolean haveItem = currentCombat.isItemAllowed();
                    boolean canEscape = currentCombat.isEscapeAllowed();
                    boolean canDefend = false; // TODO: maybe have some setting to allow some of the characters to defend..

                    CombatAction attack = null;

                    LinkedList<CombatAction> magic = new LinkedList<CombatAction>();

                    LinkedList<CombatAction> summons = new LinkedList<CombatAction>();

                    for (CombatAction ca : readyMember.getCombatActions()) {

                        if (ca.category == ZombieLord.OFFENSIVE_MAGIC
                                || ca.category == ZombieLord.DEFENSIVE_MAGIC)
                            magic.add(ca);
                        else if (ca.category == ZombieLord.ATTACK)
                            attack = ca;
                        else if (ca.category == ZombieLord.SUMMON)
                            summons.add(ca);
                    }

                    this.currentCombatOptions = new LinkedList<CombatOption>();
                    this.selectedCombatOption = null;
                    if (attack != null)
                        currentCombatOptions.add(new CombatOption("Attack", attack));
                    if (canDefend)
                        currentCombatOptions.add(ZombieLord.defend);
                    if (magic.size() > 0)
                        currentCombatOptions.add(new CombatOption("Magic", magic));
                    if (summons.size() > 0)
                        currentCombatOptions.add(new CombatOption("Summon", summons));
                    if (haveItem)
                        currentCombatOptions.add(ZombieLord.item);
                    if (canEscape)
                        currentCombatOptions.add(ZombieLord.escape);

                    this.selectedCombatOption = this.currentCombatOptions.getFirst();
                    this.finishedChoosing = false;
                    this.combatOptionCaster = readyMember;

                    this.currentCombat.waitingForPlayerCommand = true;

                    this.selectedTarget = null;

                    this.finishedTargeting = false;
                    this.validTargets = null;
                    this.targeting = null;
                }
            }
        }

        leoricSprite.setRegion(0, 64 * 3, 64, 64);
        if (!waiting) {
            currentCombat.tick(Gdx.graphics.getDeltaTime() * 5 * 2);
        }
    }

    if (this.gameMode == MODE_ZOMBIE_DEFENSE || this.gameMode == MODE_FIGHT) {
        camera.position.x = w / 2f;
        camera.position.y = h / 2f;
        camera.update();
    }

    //background = new Sprite(backgroundTexture, (int)(posx-w), (int)(posy-h), (int)(posx+w), (int)(posy+h));

    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    batch.setProjectionMatrix(camera.combined);
    batch.begin();

    background.draw(batch);

    if (this.gameMode == MODE_MOVE || this.gameMode == MODE_DIALOG) {
        // draw level objects
        if (this.levelObjects != null) {
            for (LevelObject object : this.levelObjects) {
                object.draw(batch);
            }
        }
    }

    for (Sprite s : drawSprites)
        s.draw(batch);

    if (gameMode == MODE_FIGHT) {

        this.battleWindow.draw(batch);
        this.drawCombatUISprites(batch);
        //LinkedList<Sprite> uiElements = this.getCombatUISprites();
        //for(Sprite s : uiElements)
        //   s.draw(batch);
    }

    if (animations.size() > 0) {
        ListIterator<TemporaryAnimation> lit = animations.listIterator();
        while (lit.hasNext()) {
            TemporaryAnimation ta = lit.next();

            if (ta.timeLeft <= 0) {
                lit.remove();
                continue;
            }

            ta.sprite.setPosition(ta.x, ta.y);
            ta.sprite.draw(batch);
            ta.timeLeft -= Gdx.graphics.getDeltaTime();
        }
    }

    if (animatedMissiles.size() > 0) {
        ListIterator<AnimatedMissile> it = animatedMissiles.listIterator();
        while (it.hasNext()) {
            AnimatedMissile missile = it.next();

            if (missile.hasArrived()) {
                // delete it..
                missile.sprite = null;
                it.remove();
                continue;
            }
            // TODO: use box2d to move the missiles instead?
            float xChange = 0;
            float yChange = 0;

            float reqX = missile.sprite.getX() - missile.toX;
            float reqY = missile.sprite.getY() - missile.toY;

            if (reqY == 0)
                reqY = 0.001f;

            float xyRate = Math.abs(reqX) / Math.abs(reqY);

            xChange = xyRate * missile.speed;
            yChange = 1 * missile.speed;

            if (reqX > 0)
                xChange *= -1;

            if (reqY > 0)
                yChange *= -1;

            missile.sprite.setX(missile.sprite.getX() + xChange);
            missile.sprite.setY(missile.sprite.getY() + yChange);

            missile.sprite.draw(batch);

        }
    }

    if (gameMode == MODE_ZOMBIE_DEFENSE) {

        // draw monies and helps
        //fontBatch.begin();

        font.setColor(Color.WHITE);
        font.draw(batch, "Money: " + this.zombieDefense.money + ", Life: " + this.zombieDefense.getHealthLeft()
                + ", Wave: " + this.zombieDefense.getCurrentWaveNumber() + ".", 3, 18);

        //fontBatch.end();

        // draw all the attackers..
        this.tickZombieDefense(Gdx.graphics.getDeltaTime());
        for (Attacker atk : this.zombieDefense.attackers) {
            atk.draw(batch, Gdx.graphics.getDeltaTime());
            barHp.draw(batch, atk.getX() * 32 + 8, atk.getY() * 32,
                    (float) ((atk.health + 0.0) / atk.healthMax) * 20, 3);
        }
        for (Defender def : this.zombieDefense.defenders) {
            def.draw(batch, Gdx.graphics.getDeltaTime());
            barHp.draw(batch, def.getX() * 32 + 8, def.getY() * 32,
                    (float) ((def.health + 0.0) / def.healthMax) * 20, 3);
        }
        this.zombieDefense.cursor.draw(batch);

    }

    if (gameMode == MODE_MOVE && this.foreground != null) // drawing foreground last = ontop of everything else
        foreground.draw(batch);

    if (gameMode == MODE_FIGHT) {

        for (Combatant monst : this.currentCombat.getCombatants()) {
            if (monst instanceof Monster) {
                Monster m = (Monster) monst;
                // draw the monster with correct alpha..
                // thus we can fade out dead monsters
                m.getSprite().draw(batch, m.alpha);
            }
        }

        // draw battle effects last.. unless you dont want them ontop anymore..
        for (Sprite effect : this.combatEffects)
            effect.draw(batch);
    }

    batch.end();

    if (!floatingNumbers.isEmpty()) {
        ListIterator<FloatingNumber> lit = floatingNumbers.listIterator();
        fontBatch.begin();
        while (lit.hasNext()) {
            FloatingNumber f = lit.next();
            // draw, then tick, then maybe delete
            Color myColor = new Color(f.color);

            // TODO: fade when timeleft is close to zero
            if (f.timeLeft < 1)
                myColor.a = f.timeLeft;

            font.setColor(myColor);
            font.draw(fontBatch, "" + f.number, (int) f.posx, (int) f.posy);
            f.tick(Gdx.graphics.getDeltaTime());
            font.setColor(Color.WHITE);
            if (f.deleteNow)
                lit.remove();
        }
        fontBatch.end();
    }

    if (announcement != null) {
        if (announcementTimeout > 0) {
            fontBatch.begin();
            announcementBackground.draw(fontBatch, w / 2 - announcement.length() * 6 - 4, h - 24 - 13,
                    announcement.length() * 13, 20 + 2);
            font.setColor(Color.WHITE);
            font.draw(fontBatch, announcement, w / 2 - announcement.length() * 6, h - 24);
            announcementTimeout -= Gdx.graphics.getDeltaTime();
            fontBatch.end();
        }
    }

    if (gameMode == MODE_FIGHT && this.currentCombat.waitingForPlayerCommand) {
        fontBatch.begin();
        if (this.finishedChoosing && !this.finishedTargeting) {
            // NOTE, for 'all * and random *' selectedTarget is wrong, but. we know how to draw those i guess..

            LinkedList<Combatant> targets = targeting.getCurrentTargets();

            //one hand for each target
            for (Combatant c : targets) {
                Sprite cursor = new Sprite(this.selectionHand, 0, 0, 32, 32);
                cursor.setX(c.getSprite().getX());
                cursor.setY(c.getSprite().getY());
                cursor.draw(fontBatch);
            }
        }

        int offset = 16;
        int curOffset = 0;
        for (CombatOption opt : this.currentCombatOptions) {

            font.setColor(Color.WHITE);

            if (this.currentCombat.canUse(opt, this.combatOptionCaster)) {
                if (this.selectedCombatOption == opt)
                    font.setColor(Color.YELLOW);
                else
                    font.setColor(Color.WHITE);
            } else {
                if (this.selectedCombatOption == opt)
                    font.setColor(Color.RED);
                else
                    font.setColor(Color.GRAY);
            }

            String t = opt.name;
            if (opt.item != null)
                t = party.getInventory().getItemCount(opt.item) + "x " + opt.name;

            font.draw(fontBatch, t, w / 4, h / 2 - curOffset);
            curOffset += offset;
        }
        fontBatch.end();
        font.setColor(Color.WHITE);
    }

    if (gameMode == MODE_DIALOG && this.curSpeaker != null) {
        fontBatch.begin();
        // Ongoing dialog, draw the talkstuffs
        // TODO: draw current speakers portrait?

        int slength = -1;
        for (int i = 0; i < this.curSentence.length; i++) {
            slength += this.curSentence[i].length() + 1;
            //System.out.println("_"+this.curSentence[i]+"_");
        }
        int length = this.curSpeaker.length() + 2 + slength;
        float cposx = w / 2;
        float cposy = h / 3;

        if (this.curSpeaker.equals("Leoric")) {
            Sprite face = new Sprite(Leoric.getFace());
            //face.scale(-0.4f);
            face.setPosition(5, cposy + 32 + 32);
            face.draw(fontBatch);
        } else if (this.curSpeaker.equals("Tolinai")) {
            Sprite face = new Sprite(Tolinai.getFace());
            //face.scale(-0.4f);
            face.setPosition(5, cposy + 32 + 32);
            face.draw(fontBatch);
        }

        if (length > 32) {
            // needs to be split
            //int remain = length;
            //int num = 0;
            //int start = 0;
            int startWord = 0;
            int maxLength = 0;
            int remainWords = this.curSentence.length;
            LinkedList<StringBuilder> sbl = new LinkedList<StringBuilder>();

            while (remainWords > 0) {
                /*int printed = Math.min(32, remain);
                        
                int first = start;
                int lastMinusOne = start+printed;*/
                StringBuilder sb = new StringBuilder();

                int numLetters = 0;
                int numWords = 0;
                for (int i = startWord; i < this.curSentence.length; i++) {
                    if (numLetters + this.curSentence[i].length()
                            + (startWord == 0 ? this.curSpeaker.length() : 1) > 32) {
                        break;
                    } else {
                        if (i != 0 && numWords != 0)
                            sb.append(" ");
                        sb.append(this.curSentence[i]);
                        numLetters = sb.length();
                        numWords++;
                    }
                }

                sbl.add(sb);

                /*remain -= printed;
                start += printed;*/
                remainWords -= numWords;
                startWord += numWords;

                if (numLetters > maxLength)
                    maxLength = numLetters;

            }

            dialogBackground.draw(fontBatch, 0,
                    cposy + h / 2 - h / 3 - 16 - (16 * (int) Math.floor(length / 32)), 32 * 13 + 5,
                    20 + (16 * (length / 32)) + 2);
            int tickerLimit = (int) this.dialogTicker;
            for (int i = 0; i < sbl.size(); i++) {
                if (tickerLimit <= 0) {
                    break;
                }
                String mystr = sbl.get(i).toString();
                if (mystr.length() > tickerLimit) {
                    // delete overflowing text
                    StringBuilder tmp = new StringBuilder();
                    for (int j = 0; j < tickerLimit; j++) {
                        tmp.append(mystr.charAt(j));
                    }
                    mystr = tmp.toString();
                    tickerLimit = 0;
                }
                tickerLimit -= mystr.length();
                font.draw(fontBatch, (i == 0 ? this.curSpeaker + ": " : "") + mystr,
                        cposx - w / 2 + (i == 0 ? 0 : 30), cposy + h / 2 - h / 3 - (i * 16));
            }
        } else {
            // print everything in one go
            StringBuilder all = new StringBuilder();
            for (int i = 0; i < this.curSentence.length; i++) {
                if (i > 0) {
                    all.append(" ");
                }
                all.append(curSentence[i]);
            }
            dialogBackground.draw(fontBatch, 0, cposy + h / 2 - h / 3 - 16, length * 13, 20 + 2);
            int tickerLimit = (int) this.dialogTicker;
            String mystr = all.toString();
            if (mystr.length() > tickerLimit) {
                // delete overflowing text
                StringBuilder tmp = new StringBuilder();
                for (int j = 0; j < tickerLimit; j++) {
                    tmp.append(mystr.charAt(j));
                }
                mystr = tmp.toString();
            }
            font.draw(fontBatch, this.curSpeaker + ": " + mystr, cposx - w / 2, cposy + h / 2 - h / 3);
        }
        fontBatch.end();

    } else if (this.menu != null) {
        fontBatch.begin();
        menu.draw(fontBatch);
        fontBatch.end();
    }

    if (debug && world != null && debugRenderer != null)
        debugRenderer.render(world,
                camera.combined.scale(PIXELS_PER_METER, PIXELS_PER_METER, PIXELS_PER_METER));
}