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

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

Introduction

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

Prototype

public Color mul(float r, float g, float b, float a) 

Source Link

Document

Multiplies this Color's color components by the given ones.

Usage

From source file:de.gebatzens.meteva.LevelState.java

License:Open Source License

@Override
public void render() {
    background.renderBackground();//from   ww  w  . ja  va 2s .  c  o m

    for (GameObject g : bgobjects)
        g.render();
    /*
     * for(GameObject g : objects) if(g instanceof BlackHole) g.render();
     */
    for (GameObject g : objects)
        if (g instanceof Meteor)
            g.render();
    /*
     * for(GameObject g : objects) if(g instanceof LaserSchuss) g.render();
     */
    for (GameObject g : objects)
        if (!(g instanceof Meteor/*
                                 * || g instanceof BlackHole || g instanceof
                                 * LaserSchuss
                                 */))
            g.render();

    if (spaceship != null)
        spaceship.render();

    for (GameObject g : vgobjects)
        g.render();

    GScout.batch.setColor(Color.WHITE);

    int width = Gdx.graphics.getWidth();
    int height = Gdx.graphics.getHeight();
    int fs = (int) Math.round(width * 0.03);
    // int fsub = Math.round(width / 400f);
    int balkenRand = (int) (width * 0.004);

    GScout.survivant.setColor(new Color(0x3b / 255f, 0xa3 / 255f, 0xd7 / (float) 0xff, 1));
    GScout.setFontSize(fs);
    GScout.drawText("" + points, (float) (width * 0.015), (float) (height * 0.96), true);

    double laserPer = spaceship == null ? 0f : (spaceship.miningLaser);
    Color color = new Color((float) (1.0 - laserPer), (float) laserPer, 0, 1);

    GScout.batch.setColor(color);
    GScout.batch.draw(laserBg, (float) (width * 0.170), (float) (height * 0.869), (int) (width * 0.04),
            (int) (width * 0.06));
    GScout.batch.setColor(Color.WHITE);
    GScout.batch.draw(lasertex, (float) (width * 0.175), (float) (height * 0.875), (int) (width * 0.03),
            (int) (lasertex.getRegionHeight() * ((width * 0.03) / (float) lasertex.getRegionWidth())));
    GScout.batch.setColor(new Color(0.4f, 0.4f, 0.4f, 1));
    GScout.batch.draw(GScout.whiteTexture, (float) (width * 0.22), (float) (height * 0.885),
            balkenRand * 2 + (int) (width * 0.25 * laserPer), (int) (width * 0.04));
    GScout.batch.setColor(color);
    GScout.batch.draw(GScout.whiteTexture, (float) (width * 0.22 + balkenRand),
            (float) (height * 0.885 + balkenRand), (int) (width * 0.25 * laserPer),
            (int) (width * 0.04) - balkenRand * 2);
    GScout.batch.setColor(new Color((1f - (float) laserPer) * 0.6f, (float) laserPer * 0.6f, 0, 1));
    String text = (int) (laserPer * 100.0) + "";
    GScout.setFontSize(fs * 0.8);
    TextBounds bounds = GScout.survivant.getBounds(text);
    GScout.fontShader.setUniformi("border", 0);
    GScout.survivant.setColor(color.mul(0.5f, 0.5f, 052f, 1).clamp());
    GScout.drawText(text, (float) (width * 0.35 - bounds.width / 2f), (float) (height * 0.95), false);

    float lebenPer = spaceship == null ? 0f : (spaceship.leben / 100f);
    color = new Color(1f - lebenPer, lebenPer, 0, 1);

    GScout.batch.setColor(lebenPer, 0, 0, 1);
    GScout.batch.draw(lebentex, (float) (width * 0.505), (float) (height * 0.87), (int) (width * 0.06),
            (int) (width * 0.06));

    GScout.batch.setColor(color);

    GScout.batch.setColor(new Color(0.4f, 0.4f, 0.4f, 1));
    GScout.batch.draw(GScout.whiteTexture, (float) (width * 0.58), (float) (height * 0.885),
            balkenRand * 2 + (int) (width * 0.25 * lebenPer), (int) (width * 0.04));
    GScout.batch.setColor(color);
    GScout.batch.draw(GScout.whiteTexture, (float) (width * 0.58 + balkenRand),
            (float) (height * 0.885 + balkenRand), (int) (width * 0.25 * lebenPer),
            (int) (width * 0.04) - balkenRand * 2);
    GScout.batch.setColor(new Color((1f - lebenPer) * 0.6f, lebenPer * 0.6f, 0, 1));
    GScout.survivant.setColor(color.mul(0.5f, 0.5f, 0.5f, 1).clamp());
    text = (int) (lebenPer * 100f) + "";
    GScout.setFontSize(fs * 0.8);
    bounds = GScout.survivant.getBounds(text);
    GScout.drawText(text, (float) (0.71 * width - bounds.width / 2f), (float) (height * 0.95), false);

    GScout.batch.setColor(Color.WHITE);

    GScout.batch.draw(pause ? weitertex : pausetex, Gdx.graphics.getWidth() * 0.875f,
            Gdx.graphics.getHeight() * 0.875f, (int) (Gdx.graphics.getWidth() * 0.05f),
            (int) (pausetex.getRegionHeight() * (Gdx.graphics.getWidth() * 0.05f / pausetex.getRegionWidth())));

    if (pause) {
        String s = GScout.getString("pause_string");
        GScout.setFontSize(Gdx.graphics.getWidth() * 0.1f);
        bounds = GScout.survivant.getBounds(s);
        GScout.survivant.setColor(Color.WHITE);
        GScout.drawText(s, Gdx.graphics.getWidth() / 2f - bounds.width * 0.4f, Gdx.graphics.getHeight() * 0.75f,
                true);
        pauseRestart.render();
        pauseMain.render();
    }

    if (gameover) {
        String s = GScout.getString("game_over_string");
        GScout.setFontSize(Gdx.graphics.getWidth() * 0.1f);
        bounds = GScout.survivant.getBounds(s);
        GScout.survivant.setColor(new Color(1f, 0, 0, 1f - (gameoverTimeout / 4f)));
        GScout.drawText(s, Gdx.graphics.getWidth() / 2f - bounds.width / 2f, Gdx.graphics.getHeight() * 0.65f,
                true);
        GScout.batch.setColor(Color.WHITE);
    }

}

From source file:me.scarlet.undertailor.lua.meta.LuaColorMeta.java

License:Open Source License

public LuaColorMeta() {
    this.metatable = new LuaTable();

    // color:getRGB()
    set("getRGB", asFunction(vargs -> {
        Color color = obj(vargs);
        return varargsOf(valueOf((int) (color.r * 255)), valueOf((int) (color.g * 255)),
                valueOf((int) (color.b * 255)));
    }));/*from   w  w  w.  j a  va 2  s. com*/

    // color:add(color)
    // color:add(r, g, b)
    set("add", asFunction(vargs -> {
        Color color = obj(vargs);
        if (vargs.arg(2).isnumber()) {
            float r = vargs.optint(2, 0) / 255F;
            float g = vargs.optint(3, 0) / 255F;
            float b = vargs.optint(4, 0) / 255F;
            return orNil(color.add(r, g, b, 0));
        } else {
            Color added = convert(vargs.arg(2)).getObject();
            return orNil(color.add(added));
        }
    }));

    // color:multiply(color)
    // color:multiply(r, g, b)
    set("multiply", asFunction(vargs -> {
        Color color = obj(vargs);
        if (vargs.arg(2).isnumber()) {
            float r = vargs.optint(2, 0) / 255F;
            float g = vargs.optint(3, 0) / 255F;
            float b = vargs.optint(4, 0) / 255F;
            return orNil(color.mul(r, g, b, 0));
        } else {
            Color multiplier = convert(vargs.arg(2)).getObject();
            return orNil(color.mul(multiplier));
        }
    }));

    // color:subtract(color)
    // color:subtract(r, g, b)
    set("subtract", asFunction(vargs -> {
        Color color = obj(vargs);
        if (vargs.arg(2).isnumber()) {
            float r = vargs.optint(2, 0) / 255F;
            float g = vargs.optint(3, 0) / 255F;
            float b = vargs.optint(4, 0) / 255F;
            return orNil(color.sub(r, g, b, 0));
        } else {
            Color subtracted = convert(vargs.arg(2)).getObject();
            return orNil(color.sub(subtracted));
        }
    }));

    // color:setRGB(color)
    // color:setRGB(r, g, b)
    set("setRGB", asFunction(vargs -> {
        Color color = obj(vargs);
        if (vargs.arg(2).isnumber()) {
            float r = vargs.optint(2, 0) / 255F;
            float g = vargs.optint(3, 0) / 255F;
            float b = vargs.optint(4, 0) / 255F;
            return orNil(color.set(r, g, b, 1));
        } else {
            Color set = convert(vargs.arg(2)).getObject();
            return orNil(color.set(set));
        }
    }));

    // color:clone()
    set("clone", asFunction(vargs -> {
        return orNil(obj(vargs).cpy());
    }));

    // color:toHex()
    set("toHex", asFunction(vargs -> {
        return valueOf(obj(vargs).toString());
    }));
}