Java Code Examples for com.badlogic.gdx.math.MathUtils#randomBoolean()
The following examples show how to use
com.badlogic.gdx.math.MathUtils#randomBoolean() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BranchingUpgradesCard.java From StSLib with MIT License | 5 votes |
default boolean isBranchUpgrade() { UpgradeType upgradeType = getUpgradeType(); if (upgradeType == UpgradeType.RANDOM_UPGRADE) { boolean ret = MathUtils.randomBoolean(chanceForBranchUpgrade()); if (ret) { setUpgradeType(UpgradeType.BRANCH_UPGRADE); } else { setUpgradeType(UpgradeType.NORMAL_UPGRADE); } return ret; } return upgradeType == UpgradeType.BRANCH_UPGRADE; }
Example 2
Source File: PlayerSetup.java From xibalba with MIT License | 5 votes |
private void generateName() { String preceding; String[] names; if (MathUtils.randomBoolean()) { preceding = intToRoman(Calendar.getInstance().get(Calendar.DAY_OF_YEAR)); names = Gdx.files.internal("data/names/male").readString().split("\\r?\\n"); } else { preceding = "IX"; names = Gdx.files.internal("data/names/female").readString().split("\\r?\\n"); } name = preceding + " " + names[MathUtils.random(0, names.length - 1)]; }
Example 3
Source File: PlayerSmokeTrails.java From uracer-kotd with Apache License 2.0 | 5 votes |
@Override public void render (SpriteBatch batch) { if (hasPlayer) { float dfactor = player.driftState.driftStrength; float sfactor = player.carState.currSpeedFactor; fx.setLifeMul(2f); fx.setScaleMul(1f + 20f * dfactor * sfactor); float t = 0.5f * dfactor; fx.baseEmitter.getTransparency().setHighMin(t); fx.baseEmitter.getTransparency().setHighMax(t); float[] colors = fx.baseEmitter.getTint().getColors(); float v = 0.3f; colors[0] = v * dfactor; colors[1] = v * dfactor; colors[2] = v * dfactor; float r = 0.7f; float g = 0.8f; float b = 1f; if (MathUtils.randomBoolean()) { r = 0.7f; } float colorscale = 0.15f + 0.3f * dfactor; r *= colorscale; g *= colorscale; b *= colorscale; colors[0] = r; colors[1] = g; colors[2] = b; position.set(player.state().position); } fx.render(batch, position.x, position.y); }
Example 4
Source File: PackDialogController.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
@Override public void processPackage(PackProcessingNode node) { try { System.out.println("start processing"); Thread.sleep(MathUtils.random(500, 2500)); if (MathUtils.randomBoolean()) throw new RuntimeException(); System.out.println("finish processing"); } catch (InterruptedException e) { Exceptions.throwRuntimeException(e); } }
Example 5
Source File: Level.java From ud406 with MIT License | 5 votes |
public void update(float delta) { // Update GigaGal gigaGal.update(delta, platforms); // BULLET STORM! // TODO: Spawn a bullet in a random direction, at a random position // At a position within some reasonable rectangle // You'll want to complete the spawnBullet() method below first Direction direction; if (MathUtils.randomBoolean()) { direction = Direction.RIGHT; } else { direction = Direction.LEFT; } float x = MathUtils.random(viewport.getWorldWidth()); float y = MathUtils.random(viewport.getWorldHeight()); Vector2 position = new Vector2(x, y); spawnBullet(position, direction); // TODO: Update the bullets for (Bullet bullet : bullets) { bullet.update(delta); } // Update Enemies for (int i = 0; i < enemies.size; i++) { Enemy enemy = enemies.get(i); enemy.update(delta); } }
Example 6
Source File: Dog.java From gdx-ai with Apache License 2.0 | 5 votes |
public Boolean markATree (int i) { if (i == 0) { log("Swoosh...."); return null; } if (MathUtils.randomBoolean()) { log("MUMBLE MUMBLE - Still leaking out"); return Boolean.FALSE; } log("I'm ok now :)"); return Boolean.TRUE; }
Example 7
Source File: Player.java From Unlucky with MIT License | 4 votes |
/** * Handles the player's next movements when standing on a special tile */ public void handleSpecialTiles() { int cx = (int) (position.x / tileMap.tileSize); int cy = (int) (position.y / tileMap.tileSize); Tile currentTile = tileMap.getTile(cx, cy); if (currentTile.isSpecial()) am.currentAnimation.stop(); if (canMove()) { // Player goes forwards or backwards from the tile in the direction they entered if (currentTile.isChange()) { if (!settings.muteSfx) rm.movement.play(settings.sfxVolume); boolean k = MathUtils.randomBoolean(); switch (prevDir) { case 0: // down if (k) changeDirection(1); else changeDirection(0); break; case 1: // up if (k) changeDirection(0); else changeDirection(1); break; case 2: // right if (k) changeDirection(3); else changeDirection(2); break; case 3: // left if (k) changeDirection(2); else changeDirection(3); break; } } // Player goes 1 tile in a random direction not the direction they entered the tile on else if (currentTile.isInAndOut()) { if (!settings.muteSfx) rm.movement.play(settings.sfxVolume); // output direction (all other directions other than input direction) int odir = MathUtils.random(2); switch (prevDir) { case 0: // down if (odir == 0) changeDirection(3); else if (odir == 1) changeDirection(2); else changeDirection(0); break; case 1: // up if (odir == 0) changeDirection(3); else if (odir == 1) changeDirection(2); else changeDirection(1); break; case 2: // right if (odir == 0) changeDirection(0); else if (odir == 1) changeDirection(1); else changeDirection(2); break; case 3: // left if (odir == 0) changeDirection(0); else if (odir == 1) changeDirection(1); else changeDirection(3); break; } } else if (currentTile.isDown()) { if (!settings.muteSfx) rm.movement.play(settings.sfxVolume); changeDirection(0); } else if (currentTile.isUp()) { if (!settings.muteSfx) rm.movement.play(settings.sfxVolume); changeDirection(1); } else if (currentTile.isRight()) { if (!settings.muteSfx) rm.movement.play(settings.sfxVolume); changeDirection(2); } else if (currentTile.isLeft()) { if (!settings.muteSfx) rm.movement.play(settings.sfxVolume); changeDirection(3); } // trigger dialog event else if (currentTile.isQuestionMark() || currentTile.isExclamationMark()) tileInteraction = true; // trigger teleport event else if (currentTile.isTeleport()) teleporting = true; // ice sliding else if (currentTile.isIce()) { if (!nextTileBlocked(prevDir)) { move(prevDir); am.setAnimation(prevDir); am.stopAnimation(); pauseAnim = true; } } // map completed else if (currentTile.isEnd()) completedMap = true; else pauseAnim = false; } }
Example 8
Source File: BattleUIHandler.java From Unlucky with MIT License | 4 votes |
/** * When the player first encounters the enemy and engages in battle * There's a 1% chance that the enemy doesn't want to fight * * @param enemy */ public void engage(Enemy enemy) { player.setDead(false); moveUI.init(); battleScene.resetPositions(); battleScene.toggle(true); currentState = BattleState.DIALOG; String[] intro; boolean saved = Util.isSuccess(Util.SAVED_FROM_BATTLE); if (enemy.isElite()) player.stats.eliteEncountered++; else if (enemy.isBoss()) player.stats.bossEncountered++; if (enemy.isBoss()) { if (MathUtils.randomBoolean()) { intro = new String[] { "you encountered the boss " + enemy.getId() + "!", "its power is far greater than any regular enemy.", "Passive: " + ((Boss) enemy).getPassiveDescription() }; battleEventHandler.startDialog(intro, BattleEvent.NONE, BattleEvent.PLAYER_TURN); } else { intro = new String[] { "you encountered the boss " + enemy.getId() + "!", "its power is far greater than any regular enemy.", "Passive: " + ((Boss) enemy).getPassiveDescription(), enemy.getId() + " strikes first!" }; battleEventHandler.startDialog(intro, BattleEvent.NONE, BattleEvent.ENEMY_TURN); } } else { if (saved) { intro = new String[]{ "you encountered " + enemy.getId() + "! " + "maybe there's a chance it doesn't want to fight...", "the enemy stares at you and decides to flee the battle." }; battleEventHandler.startDialog(intro, BattleEvent.NONE, BattleEvent.END_BATTLE); } else { // 50-50 chance for first attack from enemy or player if (MathUtils.randomBoolean()) { intro = new String[]{ "you encountered " + enemy.getId() + "! " + "maybe there's a chance it doesn't want to fight...", "the enemy glares at you and decides to engage in battle!" }; battleEventHandler.startDialog(intro, BattleEvent.NONE, BattleEvent.PLAYER_TURN); } else { intro = new String[]{ "you encountered " + enemy.getId() + "! " + "maybe there's a chance it doesn't want to fight...", "the enemy glares at you and decides to engage in battle!", enemy.getId() + " attacks first!" }; battleEventHandler.startDialog(intro, BattleEvent.NONE, BattleEvent.ENEMY_TURN); } } } }
Example 9
Source File: Dog.java From gdx-ai with Apache License 2.0 | 4 votes |
public void bark () { if (MathUtils.randomBoolean()) log("Arf arf"); else log("Woof"); }