List of usage examples for com.badlogic.gdx.graphics Color Color
public Color(float r, float g, float b, float a)
From source file:se.danielj.slashatthegame.Game.java
License:GNU General Public License
@Override public void create() { SpriteManager.init();// w w w . j a v a2s.c o m FontManager.init(); SoundEffectsManager.init(); MusicManager.init(); Gdx.input.setCatchBackKey(true); if (world != null) { disposeSystems(world); } world = new World(); world.setManager(new GroupManager()); box2dWorld = new com.badlogic.gdx.physics.box2d.World(new Vector2(0, -3), true); stage = new Stage(960, 540, false); if (tweenManager == null) { tweenManager = new TweenManager(); } inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(stage); inputMultiplexer.addProcessor(this); Gdx.input.setInputProcessor(inputMultiplexer); final LabelStyle labelStyle = new LabelStyle(); labelStyle.font = FontManager.getNormalFont(); labelStyle.fontColor = new Color(0, 0, 0, 1); if (level == 0) { final Song song = new Song(MusicManager.getSong(MusicManager.THEME)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 2f).target(1f).ease(Quart.INOUT)).start(tweenManager); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("logo")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("logo")); final Button button = new Button(style); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.getListenerActor().setTouchable(Touchable.disabled); level = 1; create(); Timeline.createSequence() .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(0f).ease(Quart.INOUT)) .push(Tween.set(song, SongAccessor.STOP)).start(tweenManager); return false; } }); button.setBounds(0, 0, stage.getWidth(), stage.getHeight()); stage.addActor(button); logic = new Logic() { @Override public void render() { timer += Gdx.graphics.getDeltaTime(); tweenManager.update(Gdx.graphics.getDeltaTime()); stage.draw(); stage.act(world.getDelta()); } }; } else if (level == 1) { Progress.init(); world.setSystem(new SpriteRenderSystem()); world.setSystem(new EffectSystem()); world.setSystem(new TableSystem()); world.setSystem(new PhysicsSystem(box2dWorld)); world.initialize(); EntityCreator.createRoomT(world).addToWorld(); EntityCreator.createTableT(world).addToWorld(); EntityCreator.createTommieT(world).addToWorld(); final Entity glow = EntityCreator.createGlow(world, 132, 6); glow.addToWorld(); glow.disable(); timer = 0; health = 3; progressSpeed = -2; progressing = false; won = false; final Song song = new Song(MusicManager.getSong(MusicManager.TOMMIE)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(1f).ease(Quart.INOUT)).start(tweenManager); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("button")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("button_pressed")); final Button button = new Button(style); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.getListenerActor().setTouchable(Touchable.disabled); progressing = true; progressSpeed = -progressSpeed; if (health == 3 && Math.abs(progressSpeed) == 2.0) { glow.enable(); } return false; } }); button.setBounds(10, 10, 170, 170); stage.addActor(button); style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("tommie_button_green")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("tommie_button_red")); final Button speedButton = new Button(style); speedButton.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (glow.isActive()) { glow.disable(); } if (Math.abs(progressSpeed) == 10.0) { progressSpeed /= 5; } else { progressSpeed *= 5; } return false; } }); speedButton.setBounds(805, 40, 70, 70); stage.addActor(speedButton); logic = new Logic() { @Override public void render() { world.setDelta(Gdx.graphics.getDeltaTime()); world.process(); tweenManager.update(world.getDelta()); stage.draw(); stage.act(world.getDelta()); if (progressing) { Progress.setProgress(Progress.getProgress() + progressSpeed * world.getDelta()); if (progressSpeed > 0 && Progress.getProgress() > 4) { button.setTouchable(Touchable.enabled); button.setChecked(false); progressing = false; } else if (progressSpeed < 0 && Progress.getProgress() < 1) { button.setTouchable(Touchable.enabled); button.setChecked(false); progressing = false; } if (!progressing && Math.abs(progressSpeed) == 10.0) { --health; if (health <= 0 && progressSpeed > 0) { Progress.setProgress(Progress.getProgress() + 1); blowUp(); button.setTouchable(Touchable.disabled); button.setChecked(true); won = true; Label label = new Label("Tommie has been defeated!", labelStyle); stage.addActor(label); movingLabel(label); SoundEffectsManager.explode(); } } } if (won) { timer += world.getDelta(); if (timer > 5) { level = 2; create(); Timeline.createSequence() .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(0f).ease(Quart.INOUT)) .push(Tween.set(song, SongAccessor.STOP)).start(tweenManager); // disposeSystems(world); } } } }; Label label = new Label("Meet the evil Tommie", labelStyle); stage.addActor(label); movingLabel(label); } else if (level == 2) { world.setSystem(new PeopleSystem()); world.setSystem(new SpriteRenderSystem()); world.setSystem(new EffectSystem()); world.setSystem(new LightSystem()); world.setSystem(new PhysicsSystem(box2dWorld)); world.initialize(); EntityCreator.createScene(world).addToWorld(); EntityCreator.createJezper(world).addToWorld(); EntityCreator.createPeople1(world).addToWorld(); EntityCreator.createPeople2(world).addToWorld(); EntityCreator.createPeople3(world).addToWorld(); EntityCreator.createLight1(world).addToWorld(); EntityCreator.createLight2(world).addToWorld(); EntityCreator.createLight3(world).addToWorld(); EntityCreator.createWorld(box2dWorld); EntityCreator.createBall(world, box2dWorld, 15, 60).addToWorld(); EntityCreator.createBall(world, box2dWorld, 50, 75).addToWorld(); EntityCreator.createBall(world, box2dWorld, 100, 80).addToWorld(); EntityCreator.createBall(world, box2dWorld, 150, 75).addToWorld(); timer = 0; won = false; health = 0; Progress.setProgress(0); final Song song = new Song(MusicManager.getSong(MusicManager.JEZPER)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(1f).ease(Quart.INOUT)).start(tweenManager); ButtonStyle style = new ButtonStyle(); style.up = new TextureRegionDrawable(SpriteManager.getSprite("button")); style.checked = new TextureRegionDrawable(SpriteManager.getSprite("button_pressed")); final Button button = new Button(style); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.getListenerActor().setTouchable(Touchable.disabled); EntityCreator.createFire(world, 90, 40).addToWorld(); EntityCreator.createFire(world, 60, 40).addToWorld(); won = true; timer = 0; SoundEffectsManager.explode(); Label label = new Label("Jezper has been defeated!", labelStyle); stage.addActor(label); movingLabel(label); Iterator<Body> bodies = box2dWorld.getBodies(); while (bodies.hasNext()) { Body body = bodies.next(); if (body.getUserData() instanceof Entity) { List<JointEdge> joints = body.getJointList(); for (int i = 0; i < joints.size(); ++i) { box2dWorld.destroyJoint(joints.get(0).joint); } } } box2dWorld.setContactListener(new ContactListener() { @Override public void beginContact(Contact contact) { if (health < 10) { Vector2 p = contact.getFixtureA().getBody().getPosition(); Body a = contact.getFixtureA().getBody(); Body b = contact.getFixtureB().getBody(); Body body = null; if (a.getUserData() instanceof Entity) { body = a; } if (b.getUserData() instanceof Entity) { // Entity B collided with wall if (body == null) { p = b.getPosition(); EntityCreator.createFire(world, p.x * 10, p.y * 10).addToWorld(); // A collided with B } else { EntityCreator .createFire(world, (a.getPosition().x + b.getPosition().x) * 10 / 2, (a.getPosition().y + b.getPosition().y) * 10 / 2) .addToWorld(); } } else { // A collided with wall p = a.getPosition(); EntityCreator.createFire(world, p.x * 10, p.y * 10).addToWorld(); } SoundEffectsManager.explode(); ++health; } } @Override public void endContact(Contact contact) { } @Override public void preSolve(Contact contact, Manifold oldManifold) { } @Override public void postSolve(Contact contact, ContactImpulse impulse) { } }); return false; } }); button.setBounds(10, 10, 170, 170); button.setTouchable(Touchable.disabled); button.setChecked(true); stage.addActor(button); Label label = new Label("Meet the evil Jezper", labelStyle); stage.addActor(label); movingLabel(label); logic = new Logic() { @Override public void render() { world.setDelta(Gdx.graphics.getDeltaTime()); world.process(); tweenManager.update(world.getDelta()); stage.draw(); stage.act(world.getDelta()); timer += world.getDelta(); if (won) { if (timer > 8) { level = 3; create(); Timeline.createSequence() .push(Tween.to(song, SongAccessor.VOLUME, 3f).target(0f).ease(Quart.INOUT)) .push(Tween.set(song, SongAccessor.STOP)).start(tweenManager); // disposeSystems(world); } } else { // wait 3 seconds until enabling the button Progress.setProgress(Progress.getProgress() + world.getDelta()); if (timer > 3 && button.getTouchable() == Touchable.disabled) { button.setTouchable(Touchable.enabled); button.setChecked(false); } } } }; } else if (level == 3) { final LabelStyle creditsLabelStyle = new LabelStyle(); creditsLabelStyle.font = FontManager.getCreditsFont(); creditsLabelStyle.fontColor = new Color(0, 0, 0, 1); final Label label = new Label( "Congratulations! You have defeated the Slashat crew!\nThe people of earth have been saved and can once again\nlive in peace and harmony\n\n\n\nCredits\n\nMade by, programming & graphics:\n Daniel \"MaTachi\" Jonsson, http://danielj.se\n\nJava libraries:\n LibGDX, Artemis & Tween Engine\nSoftware used:\n Eclipse, GIMP & Aseprite on Ubuntu\nFonts:\n Rase GPL & EptKazoo\nMusic:\n Theme Music by Alexandr Zhelanov\n Dissonant Waltz by Yubatake\n Below The Shift by Clearside\nSound effect:\n Explode by Michel Baradari\n\n\nThanks Slashat for all years of podcast!\n\n\nDisclaimer: This game is just something silly and shouldn't\nbe taken seriously. I have no connection with Slashat\nother than being a fan and a longtime listener. :)\nIf I had had more time I would have made levels for\nMagnus and Johan too.", creditsLabelStyle); stage.addActor(label); Song song = new Song(MusicManager.getSong(MusicManager.THEME)); Tween.registerAccessor(Song.class, new SongAccessor()); Timeline.createSequence().push(Tween.set(song, SongAccessor.PLAY)) .push(Tween.set(song, SongAccessor.VOLUME).target(0)) .push(Tween.to(song, SongAccessor.VOLUME, 2f).target(1.0f).ease(Quart.INOUT)) .start(tweenManager); logic = new Logic() { float timer = 0; @Override public void render() { timer += Gdx.graphics.getDeltaTime(); label.setPosition(20, 40 * timer - 1540); tweenManager.update(Gdx.graphics.getDeltaTime()); stage.draw(); stage.act(world.getDelta()); } }; } }
From source file:seventh.client.gfx.effects.particle_system.ParticleData.java
License:Open Source License
public ParticleData(int maxParticles) { this.maxParticles = maxParticles; this.numberOfAliveParticles = 0; this.pos = new Vector2f[maxParticles]; this.vel = new Vector2f[maxParticles]; this.isAlive = new boolean[maxParticles]; this.timeToLive = new Timer[maxParticles]; this.scale = new float[maxParticles]; this.rotation = new float[maxParticles]; this.speed = new float[maxParticles]; this.color = new Color[maxParticles]; this.sprite = new Sprite[maxParticles]; for (int i = 0; i < maxParticles; i++) { this.pos[i] = new Vector2f(); this.vel[i] = new Vector2f(); this.timeToLive[i] = new Timer(false, 0); this.color[i] = new Color(1, 1, 1, 1); this.sprite[i] = new Sprite(); this.scale[i] = 1.0f; }/*from www.jav a 2s. c o m*/ }
From source file:spaceisnear.game.ui.console.InGameLog.java
private static Color getColorOfLevel(LogString str) { LogLevel level = str.getLevel();//from w w w. j ava2 s. com switch (level) { case DEBUG: return Color.GRAY; case TALKING: return Color.BLACK; case BROADCASTING: return new Color(0, 0.5f, 0, 1); case WARNING: return Color.RED; case OOC: return Color.BLUE; case PRIVATE: return Color.MAGENTA; default: return Color.GRAY; } }
From source file:spine.Skeleton.java
License:Open Source License
public Skeleton(SkeletonData data) { if (data == null) throw new IllegalArgumentException("data cannot be null."); this.data = data; bones = new Array(data.bones.size); for (BoneData boneData : data.bones) { Bone parent = boneData.parent == null ? null : bones.get(data.bones.indexOf(boneData.parent, true)); bones.add(new Bone(boneData, this, parent)); }//from w w w .j a v a 2s .c o m slots = new Array(data.slots.size); drawOrder = new Array(data.slots.size); for (SlotData slotData : data.slots) { Bone bone = bones.get(data.bones.indexOf(slotData.boneData, true)); Slot slot = new Slot(slotData, bone); slots.add(slot); drawOrder.add(slot); } ikConstraints = new Array(data.ikConstraints.size); for (IkConstraintData ikConstraintData : data.ikConstraints) ikConstraints.add(new IkConstraint(ikConstraintData, this)); transformConstraints = new Array(data.transformConstraints.size); for (TransformConstraintData transformConstraintData : data.transformConstraints) transformConstraints.add(new TransformConstraint(transformConstraintData, this)); color = new Color(1, 1, 1, 1); updateCache(); }
From source file:stu.tnt.gdx.widget.StyleAtlas.java
License:Apache License
protected Json getJsonLoader(final FileHandle skinFile) { final Skin skin = this; final Json json = new Json() { public <T> T readValue(Class<T> type, Class elementType, JsonValue jsonData) { // If the JSON is a string but the type is not, look up the // actual value by name. if (jsonData.isString() && !ClassReflection.isAssignableFrom(CharSequence.class, type)) return get(jsonData.asString(), type); return super.readValue(type, elementType, jsonData); }/*from w ww. j ava 2 s. com*/ }; json.setTypeName(null); json.setUsePrototypes(false); /* ------------------------------------------------ */ json.setSerializer(Skin.class, new ReadOnlySerializer<Skin>() { public Skin read(Json json, JsonValue typeToValueMap, Class ignored) { for (JsonValue valueMap = typeToValueMap.child(); valueMap != null; valueMap = valueMap.next()) { try { readNamedObjects(json, ClassReflection.forName(valueMap.name()), valueMap); } catch (ReflectionException ex) { throw new SerializationException(ex); } } return skin; } private void readNamedObjects(Json json, Class type, JsonValue valueMap) { Class addType = type == TintedDrawable.class ? Drawable.class : type; for (JsonValue valueEntry = valueMap.child(); valueEntry != null; valueEntry = valueEntry.next()) { Object object = json.readValue(type, valueEntry); if (object == null) continue; try { add(valueEntry.name(), object, addType); } catch (Exception ex) { throw new SerializationException( "Error reading " + ClassReflection.getSimpleName(type) + ": " + valueEntry.name(), ex); } } } }); json.setSerializer(BitmapFont.class, new ReadOnlySerializer<BitmapFont>() { public BitmapFont read(Json json, JsonValue jsonData, Class type) { String path = json.readValue("file", String.class, jsonData); FileHandle fontFile = skinFile.parent().child(path); if (!fontFile.exists()) fontFile = Gdx.files.internal(path); if (!fontFile.exists()) throw new SerializationException("Font file not found: " + fontFile); // Use a region with the same name as the font, else use // a PNG file in the same directory as the FNT file. String regionName = fontFile.nameWithoutExtension(); try { TextureRegion region = skin.optional(regionName, TextureRegion.class); if (region != null) return new BitmapFont(fontFile, region, false); else { FileHandle imageFile = fontFile.parent().child(regionName + ".png"); if (imageFile.exists()) return new BitmapFont(fontFile, imageFile, false); else return new BitmapFont(fontFile, false); } } catch (RuntimeException ex) { throw new SerializationException("Error loading bitmap font: " + fontFile, ex); } } }); json.setSerializer(Color.class, new ReadOnlySerializer<Color>() { public Color read(Json json, JsonValue jsonData, Class type) { if (jsonData.isString()) return get(jsonData.asString(), Color.class); String hex = json.readValue("hex", String.class, (String) null, jsonData); if (hex != null) return Color.valueOf(hex); float r = json.readValue("r", float.class, 0f, jsonData); float g = json.readValue("g", float.class, 0f, jsonData); float b = json.readValue("b", float.class, 0f, jsonData); float a = json.readValue("a", float.class, 1f, jsonData); return new Color(r, g, b, a); } }); json.setSerializer(TintedDrawable.class, new ReadOnlySerializer() { public Object read(Json json, JsonValue jsonData, Class type) { String name = json.readValue("name", String.class, jsonData); Color color = json.readValue("color", Color.class, jsonData); return newDrawable(name, color); } }); /* ------------------------------------------------ */ json.setSerializer(Attributes.class, new ReadOnlySerializer<Attributes>() { @Override public Attributes read(Json json, JsonValue jsonData, Class type) { float startX = json.readValue("startX", float.class, (float) 0, jsonData); float startY = json.readValue("startY", float.class, (float) 0, jsonData); float dstX = json.readValue("x", float.class, jsonData); float dstY = json.readValue("y", float.class, jsonData); float width = json.readValue("width", float.class, jsonData); float height = json.readValue("height", float.class, jsonData); Attributes attr = new Attributes(); attr.startX = startX; attr.startY = startY; attr.x = dstX; attr.y = dstY; attr.width = width; attr.height = height; return attr; } }); /* ------------------------------------------------ */ json.setSerializer(ScalingSet.class, new ReadOnlySerializer<ScalingSet>() { @Override public ScalingSet read(Json json, JsonValue jsonData, Class type) { float layoutx = json.readValue("layoutx", float.class, jsonData); float layouty = json.readValue("layouty", float.class, jsonData); float layoutwidth = json.readValue("layoutwidth", float.class, jsonData); float layoutheight = json.readValue("layoutheight", float.class, jsonData); float whratio = json.readValue("whratio", float.class, jsonData); float hwratio = json.readValue("hwratio", float.class, jsonData); return new ScalingSet().set(layoutx, layouty, layoutwidth, layoutheight, whratio, hwratio); } }); /* ------------------------------------------------ */ json.setSerializer(Vector2.class, new ReadOnlySerializer<Vector2>() { @Override public Vector2 read(Json json, JsonValue jsonData, Class type) { return new Vector2(json.readValue("x", float.class, jsonData), json.readValue("y", float.class, jsonData)); } }); return json; }
From source file:ta.firegreen.creation.creator.java
License:Apache License
public void setSelectedTriangles(Collection<Triangle3D> triangles) { unsetSelectedTriangle();/* www .j av a2 s . co m*/ trianglesSelected.copyFeatures(mesh); for (Triangle3D t : triangles) { Triangle3D newT = trianglesSelected.addTriangle(); newT.copy(t); newT.setColor1(new Color(0.5f, 0.5f, 0.6f, 0.4f)); newT.setColor2(new Color(0.5f, 0.5f, 0.6f, 0.4f)); newT.setColor3(new Color(0.5f, 0.5f, 0.6f, 0.4f)); } }
From source file:ta.firegreen.creation.creator.java
License:Apache License
public void setSelectedTriangles(Triangle3D[] triangles) { unsetSelectedTriangle();/* ww w. ja v a 2s .com*/ trianglesSelected.copyFeatures(mesh); for (Triangle3D t : triangles) { Triangle3D newT = trianglesSelected.addTriangle(); newT.copy(t); newT.setColor1(new Color(0.5f, 0.5f, 0.6f, 0.1f)); newT.setColor2(new Color(0.5f, 0.5f, 0.6f, 0.1f)); newT.setColor3(new Color(0.5f, 0.5f, 0.6f, 0.1f)); } }
From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameEntityCreator.java
License:Apache License
@Override public void createAllEntities() { EntityParameters parameters;/*from w w w . j a v a 2s . com*/ Entity monkey; groupManager = world.getManager(GroupManager.class); // Create and set the lighting. parameters = new EntityParameters(); parameters.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f)); parameters.environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(0, 0, -1))); parameters.shader = shader; addRobotArm(parameters); // Add bombs. parameters.markerCode = 89; addBomb(parameters, bomb_type_t.COMBINATION); parameters.markerCode = 90; addBomb(parameters, bomb_type_t.INCLINATION); parameters.markerCode = 91; addBomb(parameters, bomb_type_t.WIRES); // Add doors. parameters.nextAnimation = AnimationSystem.NO_ANIMATION; parameters.loopAnimation = false; parameters.markerCode = 89; addDoor(parameters); parameters.markerCode = 90; addDoor(parameters); parameters.markerCode = 91; addDoor(parameters); // Add the monkey. monkey = world.createEntity(); monkey.addComponent(new RenderModelComponent(monkeyModel)); monkey.addComponent(new GeometryComponent()); monkey.addComponent(new MarkerCodeComponent(1023)); monkey.addComponent(new VisibilityComponent()); monkey.addComponent(new ShaderComponent(shader)); monkey.addComponent(new EnvironmentComponent(parameters.environment)); monkey.addToWorld(); entities.add(monkey); // Create the player. if (player == null) { player = world.createEntity(); player.addComponent(new BombGamePlayerComponent(3)); groupManager.add(player, PlayerComponentBase.PLAYER_GROUP); player.addToWorld(); } else { player.getComponent(BombGamePlayerComponent.class).reset(); } entitiesCreated = true; }
From source file:view.JWorldRenderer.java
public void DrawDebug() { debugRenderer.setProjectionMatrix(cam.combined); debugRenderer.begin(ShapeType.Line); for (Iterator it = world.GetBlocks().iterator(); it.hasNext();) { JBlock block = (JBlock) it.next(); Rectangle rect = block.GetBounds(); float x1 = block.GetPos().x + rect.x; float y1 = block.GetPos().y + rect.y; debugRenderer.setColor(new Color(1, 0, 0, 1)); debugRenderer.rect(x1, y1, rect.width, rect.height); }// w w w. j a v a 2 s . c om JBall _ball = world.GetBall(); Rectangle rect = _ball.GetBounds(); float x1 = _ball.GetPos().x + rect.x; float y1 = _ball.GetPos().y + rect.y; debugRenderer.setColor(new Color(0, 1, 0, 1)); debugRenderer.rect(x1, y1, rect.width, rect.height); debugRenderer.end(); }