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

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

Introduction

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

Prototype

public Color(Color color) 

Source Link

Document

Constructs a new color using the given color

Usage

From source file:com.sasluca.lcl.ui.text.UILabel.java

License:Apache License

public UILabel(String font, String text, Color color) {
    p_Font = LCLFontManager.getFont(font);
    if (p_Font instanceof LCLDistanceFieldFont)
        p_Smoothing = 4;//from w w  w.j av  a2  s. co  m
    p_Color = new Color(color);
    p_String = new LCLString(text);
    p_WidthScale = 1;
    p_HeightScale = 1;
}

From source file:com.sasluca.lcl.ui.text.UILabel.java

License:Apache License

@Override
public UILabel setColor(Color newColor) {
    p_Color = new Color(newColor);
    return this;
}

From source file:com.sasluca.lcl.ui.text.UITextArea.java

License:Apache License

public UITextArea(String font, float width, float height, String text, boolean fitText) {
    image = new UISprite("default");
    image.setSize(width, height).setColor(Color.BLUE);

    m_Font = LCLFontManager.getFont(font);
    m_Mask = new LCLMask(0, 0, width, height);
    m_Text = new LCLString(text);
    m_ScaleW = m_ScaleH = 1f;//from www  . j av  a  2s  . c o m
    m_Color = new Color(Color.BLACK);
    m_Masking = true;
    m_FitText = fitText;
    m_Smoothing = 4;
    if (m_FitText)
        fitText();
}

From source file:com.sasluca.lcl.utils.group.LCLGroup.java

License:Apache License

public LCLGroup() {
    m_Objects = new LCLList();
    m_Color = new Color(Color.WHITE);
    m_IsRendering = true;
}

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  w w  w  . ja  v  a 2 s . c  om
    }

    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));
}

From source file:com.thetruthbeyond.gui.objects.controllers.scrollarea.ChoosableScrollArea.java

License:Open Source License

public ChoosableScrollArea(ChoosableScrollAreaConfiguration configuration, FileManager loader,
        Clickable parent) {/*from  w  w w.ja  va2s.c  o  m*/
    super(configuration, loader, parent);

    IS_BLANK_CHOSE_ENABLED = configuration.isBlankChooseEnabled;

    FONT_COLOR = configuration.fontcolor;
    LIGHT_COLOR = new Color(FONT_COLOR).mul(1.40f);

    CHOSE_SOUND = loader.getSound("ButtonHover2");
}

From source file:com.thetruthbeyond.gui.objects.controllers.textfield.decorators.LabeledTextField.java

License:Open Source License

public LabeledTextField(TextField parent, LabeledTextFieldConfiguration configuration) {
    super(parent);

    fontSize = (int) (getH() * configuration.labelSizeParameter);
    labelFont = FontPool.createFont(configuration.labelFontname, fontSize);

    labelColor = new Color(configuration.labelFontColor);

    labelTitle = configuration.labelTitle;

    relativePaddingX = configuration.relativeLabelPaddingX;
    relativePaddingY = configuration.relativeLabelPaddingY;

    align = configuration.align;/*from w w  w  .j a va 2 s  .com*/
    actualizePosition(align);
}

From source file:com.tnf.ptm.common.MapDrawer.java

License:Apache License

public MapDrawer(TextureManager textureManager, float screenHeight) {
    myZoom = MAX_ZOOM / MUL_FACTOR / MUL_FACTOR;
    float minIconRad = MIN_ICON_RAD_PX / screenHeight;
    myIconRad = ICON_RAD < minIconRad ? minIconRad : ICON_RAD;

    myAreaWarnCol = new Color(PtmColor.WHITE);
    myAreaWarnBgCol = new Color(PtmColor.UI_WARN);

    myWarnAreaBg = textureManager.getTexture(MAP_TEX_DIR + "warnBg");
    myAtmTex = textureManager.getTexture(MAP_TEX_DIR + "atm");
    myPlanetTex = textureManager.getTexture(MAP_TEX_DIR + "planet");
    myPlanetCoreTex = textureManager.getTexture(MAP_TEX_DIR + "planetCore");
    myStarTex = textureManager.getTexture(MAP_TEX_DIR + "star");
    myMazeTex = textureManager.getTexture(MAP_TEX_DIR + "maze");
    mySkullBigTex = textureManager.getTexture(MAP_TEX_DIR + "skullBig");
    myBeltTex = textureManager.getTexture(MAP_TEX_DIR + "asteroids");
    myBeaconAttackTex = textureManager.getTexture(MAP_TEX_DIR + "beaconAttack");
    myBeaconMoveTex = textureManager.getTexture(MAP_TEX_DIR + "beaconMove");
    myBeaconFollowTex = textureManager.getTexture(MAP_TEX_DIR + "beaconFollow");
    myWhiteTex = textureManager.getTexture(MAP_TEX_DIR + "whiteTex");
    myLineTex = textureManager.getTexture(MAP_TEX_DIR + "gridLine");

    myIconBg = textureManager.getTexture(TextureManager.HULL_ICONS_DIR + "bg");
    mySkullTex = textureManager.getTexture(TextureManager.HULL_ICONS_DIR + "skull");
    myStarPortTex = textureManager.getTexture(TextureManager.HULL_ICONS_DIR + "starPort");
}

From source file:com.tnf.ptm.entities.item.PtmItemType.java

License:Apache License

public PtmItemType(Color color, PlayableSound pickUpSound, float sz) {
    this.color = color;
    this.sz = sz;
    uiColor = new Color(color);
    uiColor.a = .3f;/*from w w  w.  java 2 s.c  om*/
    this.pickUpSound = pickUpSound;
}

From source file:com.tnf.ptm.gfx.particle.LightSrc.java

License:Apache License

/**
 * doesn't consume relPos//from w w w .j a  v  a 2  s  .  c o  m
 */
public LightSrc(PtmGame game, float sz, boolean hasHalo, float intensity, Vector2 relPos, Color col) {
    TextureAtlas.AtlasRegion tex = game.getTexMan().getTexture("smallGameObjects/particles/lightCircle");
    mySz = sz;
    myCircle = new RectSprite(tex, 0, 0, 0, new Vector2(relPos), DraLevel.PART_BG_0, 0, 0, col, true);
    tex = game.getTexMan().getTexture("smallGameObjects/particles/lightHalo");
    if (hasHalo) {
        Color haloCol = new Color(col);
        PtmColorUtil.changeBrightness(haloCol, .8f);
        myHalo = new RectSprite(tex, 0, 0, 0, new Vector2(relPos), DraLevel.PART_FG_0, 0, 0, haloCol, true);
    } else {
        myHalo = null;
    }
    myIntensity = intensity;
    myFadeTime = DEFAULT_FADE_TIME;
}