List of usage examples for com.badlogic.gdx.graphics Color Color
public Color(float r, float g, float b, float a)
From source file:com.holotrash.lazerdeath2.lazerdeath2.java
License:Open Source License
private void makeRangeHighlight(Unit unit) { highlightTiles.clear();// www. j a v a2 s. com HashSet<Coord> tileCoords; for (int i = 0; i < unit.ap() + 1; i++) { tileCoords = gm.unitMoveCoords(unit, i); if (unit.isDude()) { hlColor1 = new Color(0.0f, 0.0f, 1.0f, 0.5f / i); //hlColor2 = new Color(0.0f,0.0f,1.0f,0.2f); } else { hlColor1 = new Color(1.0f, 0.0f, 0.0f, 0.5f / i); //hlColor2 = new Color(1.0f,0.0f,0.0f,0.2f); } for (Coord coord : tileCoords) { if (!highlightTiles.containsKey(coord)) highlightTiles.put(coord, new HighlightTile(coord, hlColor1)); } } }
From source file:com.holotrash.lazerdeath2.lazerdeath2.java
License:Open Source License
private void makeAttackHighlight(Unit unit) { this.highlightTiles.clear(); this.playerAttacking = true; HashSet<Unit> tileUnits = gm.tileMath.unitsWithinAttackRange(unit); hlColor1 = new Color(0.0f, 0.0f, 1.0f, 0.5f); hlColor2 = new Color(1.0f, 0.0f, 0.0f, 0.5f); for (Unit u : tileUnits) { if (u.isDude()) { highlightTiles.put(u.position(), new HighlightTile(u.position(), hlColor1)); } else {/* www.j a va 2s . co m*/ highlightTiles.put(u.position(), new HighlightTile(u.position(), hlColor2)); } } }
From source file:com.idp.engine.ui.graphics.actors.listview.ScrollBar.java
public ScrollBar(ListView parent) { if (parent == null) throw new NullPointerException(); this.listView = parent; this.thickness = 2; this.offset = 4; this.tex = new IdpColorPixmap(); tex.setColor(Color.WHITE);/* w w w .j ava 2s .c o m*/ this.fadeDuration = 0.2f; this.fadeDelay = 0.5f; this.normalAlpha = 0.8f; setColor(new Color(0.4f, 0.4f, 0.4f, normalAlpha)); }
From source file:com.iLoong.launcher.min3d.ObjLoader.java
License:Open Source License
/** * Loads a mesh from the given string in Wavefront OBJ format * /*from www . j ava 2 s . c o m*/ * @param obj * The string * @param flipV * whether to flip the v texture coordinate or not * @param useIndices * whether to create an array of indices or not * @return The Mesh */ public static Mesh loadObjFromString(String obj, boolean flipV, boolean useIndices, float offsetX, float offsetY, float offsetZ, float scaleX, float scaleY, float scaleZ) { String[] lines = obj.split("\n"); float[] vertices = new float[lines.length * 3]; float[] normals = new float[lines.length * 3]; float[] uv = new float[lines.length * 3]; int numVertices = 0; int numNormals = 0; int numUV = 0; int numFaces = 0; int[] facesVerts = new int[lines.length * 3]; int[] facesNormals = new int[lines.length * 3]; int[] facesUV = new int[lines.length * 3]; int vertexIndex = 0; int normalIndex = 0; int uvIndex = 0; int faceIndex = 0; Color default_color = new Color(1.0f, 1.0f, 1.0f, 1.0f); for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line.startsWith("v ")) { String[] tokens = line.split("[ ]+"); float vertex_x = Float.parseFloat(tokens[1]); float vertex_y = Float.parseFloat(tokens[2]); float vertex_z = Float.parseFloat(tokens[3]); if (scaleX != 1f) { vertex_x = vertex_x * scaleX; } if (scaleY != 1f) { vertex_y = vertex_y * scaleY; } if (scaleZ != 1f) { vertex_z = vertex_z * scaleZ; } vertices[vertexIndex] = vertex_x + offsetX; vertices[vertexIndex + 1] = vertex_y + offsetY; vertices[vertexIndex + 2] = vertex_z + offsetZ; vertexIndex += 3; numVertices++; continue; } if (line.startsWith("vn ")) { String[] tokens = line.split("[ ]+"); normals[normalIndex] = Float.parseFloat(tokens[1]); normals[normalIndex + 1] = Float.parseFloat(tokens[2]); normals[normalIndex + 2] = Float.parseFloat(tokens[3]); normalIndex += 3; numNormals++; continue; } if (line.startsWith("vt")) { String[] tokens = line.split("[ ]+"); uv[uvIndex] = Float.parseFloat(tokens[1]); uv[uvIndex + 1] = flipV ? 1 - Float.parseFloat(tokens[2]) : Float.parseFloat(tokens[2]); uvIndex += 2; numUV++; continue; } if (line.startsWith("f ")) { String[] tokens = line.split("[ ]+"); if (tokens.length == 5) { String[] parts = tokens[1].split("/"); facesVerts[faceIndex] = getIndex(parts[0], numVertices); if (parts.length > 2) facesNormals[faceIndex] = getIndex(parts[2], numNormals); if (parts.length > 1) facesUV[faceIndex] = getIndex(parts[1], numUV); faceIndex++; parts = tokens[2].split("/"); facesVerts[faceIndex] = getIndex(parts[0], numVertices); if (parts.length > 2) facesNormals[faceIndex] = getIndex(parts[2], numNormals); if (parts.length > 1) facesUV[faceIndex] = getIndex(parts[1], numUV); faceIndex++; parts = tokens[4].split("/"); facesVerts[faceIndex] = getIndex(parts[0], numVertices); if (parts.length > 2) facesNormals[faceIndex] = getIndex(parts[2], numNormals); if (parts.length > 1) facesUV[faceIndex] = getIndex(parts[1], numUV); faceIndex++; numFaces++; parts = tokens[2].split("/"); facesVerts[faceIndex] = getIndex(parts[0], numVertices); if (parts.length > 2) facesNormals[faceIndex] = getIndex(parts[2], numNormals); if (parts.length > 1) facesUV[faceIndex] = getIndex(parts[1], numUV); faceIndex++; parts = tokens[3].split("/"); facesVerts[faceIndex] = getIndex(parts[0], numVertices); if (parts.length > 2) facesNormals[faceIndex] = getIndex(parts[2], numNormals); if (parts.length > 1) facesUV[faceIndex] = getIndex(parts[1], numUV); faceIndex++; parts = tokens[4].split("/"); facesVerts[faceIndex] = getIndex(parts[0], numVertices); if (parts.length > 2) facesNormals[faceIndex] = getIndex(parts[2], numNormals); if (parts.length > 1) facesUV[faceIndex] = getIndex(parts[1], numUV); faceIndex++; numFaces++; } else { String[] parts = tokens[1].split("/"); facesVerts[faceIndex] = getIndex(parts[0], numVertices); if (parts.length > 2) facesNormals[faceIndex] = getIndex(parts[2], numNormals); if (parts.length > 1) facesUV[faceIndex] = getIndex(parts[1], numUV); faceIndex++; parts = tokens[2].split("/"); facesVerts[faceIndex] = getIndex(parts[0], numVertices); if (parts.length > 2) facesNormals[faceIndex] = getIndex(parts[2], numNormals); if (parts.length > 1) facesUV[faceIndex] = getIndex(parts[1], numUV); faceIndex++; parts = tokens[3].split("/"); facesVerts[faceIndex] = getIndex(parts[0], numVertices); if (parts.length > 2) facesNormals[faceIndex] = getIndex(parts[2], numNormals); if (parts.length > 1) facesUV[faceIndex] = getIndex(parts[1], numUV); faceIndex++; numFaces++; } continue; } } Mesh mesh = null; ArrayList<VertexAttribute> attributes = new ArrayList<VertexAttribute>(); attributes.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE)); attributes.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE)); if (numNormals > 0) attributes.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); if (numUV > 0) attributes .add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); if (useIndices) { int attrCount = 4 + (numNormals > 0 ? 3 : 0) + (numUV > 0 ? 2 : 0); int normOffset = 4; int uvOffset = 4 + (numNormals > 0 ? 3 : 0); float verts[] = new float[numVertices * attrCount]; for (int i = 0; i < numVertices; i++) { verts[i * attrCount] = vertices[i * 3]; verts[i * attrCount + 1] = vertices[i * 3 + 1]; verts[i * attrCount + 2] = vertices[i * 3 + 2]; verts[i * attrCount + 3] = default_color.toFloatBits(); } for (int i = 0; i < numFaces * 3; i++) { int vertexIdx = facesVerts[i]; if (numNormals > 0) { int normalIdx = facesNormals[i] * 3; verts[vertexIdx * attrCount + normOffset] = normals[normalIdx]; verts[vertexIdx * attrCount + normOffset + 1] = normals[normalIdx + 1]; verts[vertexIdx * attrCount + normOffset + 2] = normals[normalIdx + 2]; } if (numUV > 0) { int uvIdx = facesUV[i] * 2; verts[vertexIdx * attrCount + uvOffset] = uv[uvIdx]; verts[vertexIdx * attrCount + uvOffset + 1] = uv[uvIdx + 1]; } } short[] indices = new short[numFaces * 3]; for (int i = 0; i < indices.length; i++) indices[i] = (short) facesVerts[i]; mesh = new Mesh(null, true, verts.length, indices.length, attributes.toArray(new VertexAttribute[attributes.size()])); mesh.setVertices(verts); mesh.setIndices(indices); } else { float[] verts = new float[(numFaces * 3) * (4 + (numNormals > 0 ? 3 : 0) + (numUV > 0 ? 2 : 0))]; for (int i = 0, vi = 0; i < numFaces * 3; i++) { int vertexIdx = facesVerts[i] * 3; verts[vi++] = vertices[vertexIdx]; verts[vi++] = vertices[vertexIdx + 1]; verts[vi++] = vertices[vertexIdx + 2]; verts[vi++] = default_color.toFloatBits(); if (numNormals > 0) { int normalIdx = facesNormals[i] * 3; verts[vi++] = normals[normalIdx]; verts[vi++] = normals[normalIdx + 1]; verts[vi++] = normals[normalIdx + 2]; } if (numUV > 0) { int uvIdx = facesUV[i] * 2; verts[vi++] = uv[uvIdx]; verts[vi++] = uv[uvIdx + 1]; } } mesh = new Mesh(null, true, numFaces * 3, 0, attributes.toArray(new VertexAttribute[attributes.size()])); mesh.setVertices(verts); } return mesh; }
From source file:com.izacc.ability.District.java
@Override public void render(float delta) { shapeRenderer.setColor(new Color(1.0f, 1.0f, 102.0f / 255.0f, 0.15f)); shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.circle(x, y, r);// w w w . j av a2 s . c om shapeRenderer.end(); }
From source file:com.izacc.enemy.Enemy.java
public void render(float delta) { shapeRenderer.setColor(new Color(color, color, color, alpha)); shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.circle(x, y, r);/*w ww . ja v a2 s.com*/ shapeRenderer.end(); }
From source file:com.jmstudios.pointandhit.BulletManager.java
License:Open Source License
public BulletManager(float shootCoolDownTime, TargetManager targetManager, UserPointer userPointer) { this.shootCoolDownTime = shootCoolDownTime; this.shootCoolDownTimeLeft = 0; this.targetManager = targetManager; this.userPointer = userPointer; // Textures/* w w w. j a va2s . c o m*/ scoreSprites = new Texture[4]; for (int i = 1, j = 0; j < 4; i += i == 3 ? 2 : 1, j++) { scoreSprites[j] = new Texture(Gdx.files.internal("+" + i + "points.png")); } int shootAnimationsNeeded = (int) Math.ceil((animationTime + textTime) / shootCoolDownTime); this.ammountShootAnimations = shootAnimationsNeeded; Color bulletColor = new Color(0.76f, 0.58f, 0.11f, 1f); this.shootAnimations = new ShootAnimation[shootAnimationsNeeded]; for (int i = 0; i < shootAnimationsNeeded; i++) { shootAnimations[i] = new ShootAnimation(0.2f, 1f, bulletColor, userPointer.getRadius(), targetManager, scoreSprites); } }
From source file:com.jmstudios.pointandhit.GameScreen.java
License:Open Source License
public void setupMenus() { Texture buttonsTex = game.buttons;/*from ww w .j a v a 2 s.c o m*/ // Game running menu gameRunningStage = new Stage(); TextureRegion pauseButtonTex = new TextureRegion(buttonsTex, 512, 256, 128, 128); pauseButton = new ImageButton(new TextureRegionDrawable(pauseButtonTex)); pauseButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { pauseGame(); } }); Table pauseButtonTable = new Table(); pauseButtonTable.setPosition(screenSize.x - (pauseButton.getWidth() * scale), screenSize.y - (pauseButton.getHeight() * scale)); pauseButtonTable.add(pauseButton).size(pauseButton.getWidth() * scale); gameRunningStage.addActor(pauseButtonTable); // Set up font textFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt")); textFont.setColor(Color.WHITE); textFont.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); textFont.setScale(scale); // Set up transparent shader Pixmap onePixTransparent = new Pixmap(1, 1, Pixmap.Format.RGBA8888); onePixTransparent.setColor(new Color(0, 0, 0, 0.6f)); onePixTransparent.fill(); transparentShader = new Texture(onePixTransparent); // Set up buttons TextureRegion resumeTex = new TextureRegion(buttonsTex, 0, 0, 256, 256), retryTex = new TextureRegion(buttonsTex, 256, 0, 256, 256), menuTex = new TextureRegion(buttonsTex, 512, 0, 256, 256); TextureRegionDrawable resumeDrawable = new TextureRegionDrawable(resumeTex), retryDrawable = new TextureRegionDrawable(retryTex), menuDrawable = new TextureRegionDrawable(menuTex); resumeButton = new ImageButton(resumeDrawable); retryButton = new ImageButton(retryDrawable); menuButton = new ImageButton(menuDrawable); // Click listeners resumeButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { gameState = GameState.Running; giveFocus(); } }); retryButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { retry(); } }); menuButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { goToMainMenu(); } }); // Set up pauseTable float padding = 20 * scale; this.pauseStage = new Stage(); Table wholePauseTable = new Table(); wholePauseTable.setFillParent(true); pauseTable = new Table(); pauseTable.defaults().pad(padding).padTop(padding * 3).padBottom(padding * 3); // Different screen sizes pauseTable.add(resumeButton).size(resumeButton.getWidth() * scale); pauseTable.add(retryButton).size(retryButton.getWidth() * scale); pauseTable.add(menuButton).size(menuButton.getWidth() * scale); wholePauseTable.add(pauseTable).fill(10, 1f); pauseStage.addActor(wholePauseTable); // Set up game over menu gameOverStage = new Stage(); gameOverTable = new Table(); gameOverStage.addActor(gameOverTable); // Labels Label.LabelStyle scoreLabelStyle = new Label.LabelStyle(textFont, Color.WHITE); Label.LabelStyle gameOverLabelStyle = new Label.LabelStyle(scoreFont, Color.WHITE); gameOverText = new Label("Game over", gameOverLabelStyle); scoreTextLabel = new Label("Score: ", scoreLabelStyle); highScoreTextLabel = new Label("Highscore: ", scoreLabelStyle); scoreLabel = new Label("null", gameOverLabelStyle); highScoreLabel = new Label("null", scoreLabelStyle); // Buttons gameOverRetryButton = new ImageButton(retryDrawable); gameOverMenuButton = new ImageButton(menuDrawable); gameOverRetryButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { retry(); } }); gameOverMenuButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { goToMainMenu(); } }); gameOverButtonsTable = new Table(); gameOverButtonsTable.defaults().pad(padding * 2); gameOverButtonsTable.add(gameOverRetryButton).left().size(gameOverRetryButton.getWidth() * scale); gameOverButtonsTable.add(gameOverMenuButton).right().size(gameOverMenuButton.getHeight() * scale); gameOverTable.setFillParent(true); gameOverTable.setDebug(false); gameOverTable.defaults().pad(padding * 2); gameOverTable.add(gameOverText).colspan(3).center(); gameOverTable.row(); gameOverTable.add(scoreLabel).colspan(3).center().pad(8 * padding); gameOverTable.row(); gameOverTable.add(highScoreLabel).colspan(3).center().padTop(0).padBottom(padding * 4); gameOverTable.row(); gameOverTable.add(gameOverButtonsTable).center().fill(10f, 1f).padTop(padding * 8); }
From source file:com.jmstudios.pointandhit.OptionsScreen.java
License:Open Source License
public OptionsScreen(final OneShotGame game) { this.game = game; this.scale = game.scale; Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // Font//from ww w . j ava2 s. com textFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt")); textFont.setScale(scale); BitmapFont titleFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_large.fnt")); titleFont.setScale(scale); // Checkbox style Texture checkBoxes = new Texture(Gdx.files.internal("buttons/radiobutton.png")); TextureRegionDrawable checkBoxUnchecked = new TextureRegionDrawable( new TextureRegion(checkBoxes, 0, 0, 64, 64)); TextureRegionDrawable checkBoxChecked = new TextureRegionDrawable( new TextureRegion(checkBoxes, 64, 0, 64, 64)); checkBoxStyle = new CheckBox.CheckBoxStyle(checkBoxUnchecked, checkBoxChecked, textFont, Color.WHITE); CheckBox verySensitive = newRadioButton("Very sensitive"), sensitive = newRadioButton("Sensitive"), normal = newRadioButton("Normal"), forgiving = newRadioButton("Forgiving"), veryForgiving = newRadioButton("Very forgiving"), invertControls = newRadioButton("Invert the controls"); sensitivityGroup = new ButtonGroup<CheckBox>(verySensitive, sensitive, normal, forgiving, veryForgiving, invertControls); int startSetting = game.preferences.getInteger("sensitivity", 2); sensitivityGroup.uncheckAll(); sensitivityGroup.getButtons().get(startSetting).setChecked(true); float padding = 20 * scale; // Title Table titleTable = new Table(); titleTable.align(Align.topLeft); Pixmap backgroundPixmap = new Pixmap(1, 1, Format.RGBA8888); backgroundPixmap.setColor(new Color(0.9f, 0.35f, 0.1f, 1)); backgroundPixmap.fill(); titleTable.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(backgroundPixmap)))); Label.LabelStyle titleLabelStyle = new Label.LabelStyle(titleFont, Color.WHITE); Label titleLabel = new Label("Control sensitivity", titleLabelStyle); titleLabel.setWrap(true); titleLabel.setWidth(screenSize.x - padding * 2); titleLabel.setAlignment(Align.center); titleTable.add(titleLabel).align(Align.topLeft).pad(2 * padding).width(screenSize.x - padding * 2); // Checkboxes optionsTable = new Table(); optionsTable.align(Align.topLeft); optionsTable.defaults().align(Align.topLeft).pad(padding).padBottom(0).padLeft(2 * padding); optionsTable.row(); optionsTable.add(verySensitive); optionsTable.row(); optionsTable.add(sensitive); optionsTable.row(); optionsTable.add(normal); optionsTable.row(); optionsTable.add(forgiving); optionsTable.row(); optionsTable.add(veryForgiving); optionsTable.row(); optionsTable.add(invertControls); optionsTable.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { int newSensitivity = sensitivityGroup.getCheckedIndex(); if (newSensitivity == -1) newSensitivity = 2; game.preferences.putInteger("sensitivity", newSensitivity); game.preferences.flush(); } }); mainTable = new Table(); mainTable.setFillParent(true); mainTable.align(Align.top); mainTable.add(titleTable).pad(0).padBottom(padding * 4).fill(10, 1).align(Align.topLeft); mainTable.row(); mainTable.add(optionsTable).align(Align.left); mainStage = new Stage(); mainStage.addActor(mainTable); // Input inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(mainStage); inputMultiplexer.addProcessor(this); }
From source file:com.jmstudios.pointandhit.TargetManager.java
License:Open Source License
public TargetManager(float targetLifeTime, int targetRadius, Vector2 screenSize, UserPointer userPointer, GameScreen screen) {/*from ww w . j a v a2 s . c om*/ this.screen = screen; this.targetLifeTime = targetLifeTime; this.targetRadius = targetRadius; this.userPointer = userPointer; this.shoot = false; this.screenX = (int) screenSize.x; this.screenY = (int) screenSize.y; int targetRadiusBound = targetRadius / 2; lowerX = targetRadiusBound; lowerY = targetRadiusBound; higherX = screenX - targetRadiusBound; higherY = screenY - targetRadiusBound; this.randomGenerator = new Random(); spawnNewTarget(); this.bulletManager = new BulletManager(0.4f, this, userPointer); this.loseLifeEffect = new LoseLifeEffect(0.4f, this); // Theme blueTheme = new GameTheme(); blueTheme.background = new Color(0.2f, 0.4f, 0.5f, 1); blueTheme.target = new Color(0.9f, 0.35f, 0.1f, 1); blueTheme.userPointer = Color.WHITE; blueTheme.bullet = Color.LIGHT_GRAY; purpleTheme = new GameTheme(); purpleTheme.background = new Color(0.2f, 0.2f, 0.5f, 1); purpleTheme.target = new Color(0.87f, 0.58f, 0.85f, 1); purpleTheme.userPointer = Color.WHITE; purpleTheme.bullet = Color.LIGHT_GRAY; darkBlueTheme = new GameTheme(); darkBlueTheme.background = new Color(0.235f, 0.235f, 0.39f, 1); darkBlueTheme.target = new Color(0.39f, 0.69f, 0.29f, 1); darkBlueTheme.userPointer = Color.WHITE; darkBlueTheme.bullet = Color.LIGHT_GRAY; brownTheme = new GameTheme(); brownTheme.background = new Color(0.45f, 0.28f, 0.24f, 1); brownTheme.target = new Color(0.51f, 0.75f, 0.81f, 1); brownTheme.userPointer = Color.WHITE; brownTheme.bullet = Color.LIGHT_GRAY; greenTheme = new GameTheme(); greenTheme.background = new Color(0.34f, 0.53f, 0.27f, 1); greenTheme.target = new Color(0.42f, 0.33f, 0.55f, 1); greenTheme.userPointer = Color.WHITE; greenTheme.bullet = Color.LIGHT_GRAY; this.score = 0; this.currentTheme = getTheme(score); this.lifes = 3; }