Java Code Examples for com.badlogic.gdx.math.MathUtils#ceil()
The following examples show how to use
com.badlogic.gdx.math.MathUtils#ceil() .
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: IceStorm.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
private IActionResult calcResult(Creature creature, Grid2D.Coordinate cell) { Vector2 position = tmp.set(cell.x(), cell.y()); ObjectIntMap<Creature> targets = new ObjectIntMap<Creature>(); for (int i = cell.x() - MathUtils.ceil(radius); i <= cell.x() + radius; i++) { for (int j = cell.y() - MathUtils.ceil(radius); j <= cell.y() + radius; j++) { if (position.dst(i, j) <= radius) { WorldObject object = creature.world.get(i, j); if (object instanceof Creature && ((Creature) object).get(Attribute.canBeSelected) && !((Creature) object).get(Attribute.frozen)) { targets.put((Creature) object, i == cell.x() && j == cell.y() ? epicenterTurns : turns); } } } } return new IceStormResult(owner, creature, cell, targets); }
Example 2
Source File: CreatureAction.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
protected final Array<Grid2D.Coordinate> coordinates(Creature creature, float radius, ICondition<Grid2D.Coordinate> condition) { int checkRadius = MathUtils.ceil(radius); float radius2 = radius * radius; Vector2 position = tmpVector.set(creature.getX(), creature.getY()); Array<Grid2D.Coordinate> result = new Array<Grid2D.Coordinate>(); for (int i = creature.getX() - checkRadius; i <= creature.getX() + checkRadius; i++) { for (int j = creature.getY() - checkRadius; j <= creature.getY() + checkRadius; j++) { if (position.dst2(i, j) > radius2) continue; Grid2D.Coordinate coordinate = Grid2D.obtain(i, j); if (condition.isSatisfied(coordinate)) { result.add(coordinate); } else { Grid2D.free(coordinate); } } } return result; }
Example 3
Source File: MoveResult.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
public static Array<Grid2D.Coordinate> fillAvailableCoordinates(Array<Grid2D.Coordinate> coordinates, Creature creature) { World world = creature.world; if (world == null) return coordinates; if (!creature.get(Attribute.canMove)) { coordinates.add(new Grid2D.Coordinate(creature.getX(), creature.getY())); return coordinates; } int r = MathUtils.ceil(creature.description.profession.moveRadius); float r2 = creature.description.profession.moveRadius * creature.description.profession.moveRadius; for (int x = creature.getX() - r; x <= creature.getX() + r; x++) { for (int y = creature.getY() - r; y <= creature.getY() + r; y++) { if ((x == creature.getX() && y == creature.getY() || world.canStepTo(x, y)) && tmp.set(x, y).dst2(creature.getX(), creature.getY()) <= r2) { coordinates.add(new Grid2D.Coordinate(x, y)); } } } return coordinates; }
Example 4
Source File: Scene2dFollowFlowFieldTest.java From gdx-ai with Apache License 2.0 | 6 votes |
public RandomFlowField2DWithRepulsors (float width, float height, int resolution, Array<SteeringActor> obstacles) { this.resolution = resolution; this.columns = MathUtils.ceil(width / resolution); this.rows = MathUtils.ceil(height / resolution); this.field = new Vector2[columns][rows]; for (int i = 0; i < columns; i++) { ROWS: for (int j = 0; j < rows; j++) { for (int k = 0; k < obstacles.size; k++) { SteeringActor obstacle = obstacles.get(k); if (obstacle.getPosition().dst(resolution * (i + .5f), resolution * (j + .5f)) < obstacle.getBoundingRadius() + 40) { field[i][j] = new Vector2(resolution * (i + .5f), resolution * (j + .5f)).sub(obstacle.getPosition()).nor(); continue ROWS; } } field[i][j] = new Vector2(MathUtils.random(-1f, 1f), MathUtils.random(-1f, 1f)).nor(); } } }
Example 5
Source File: VectorField.java From talos with Apache License 2.0 | 5 votes |
public Vector2 getValue(Vector2 pos, Vector2 result) { float x = (((pos.x - fieldPos.x) / scale) * 0.5f + 0.5f) * xSize; float y = (((pos.y - fieldPos.y) / scale) * 0.5f + 0.5f) * ySize; int z = 0; if(MathUtils.floor(x) < 0 || MathUtils.ceil(x) > xSize - 1 || MathUtils.floor(y) < 0 || MathUtils.ceil(y) > ySize - 1) { result.set(0, 0); return result; } if(MathUtils.floor(x) > xSize - 1 || MathUtils.ceil(x) < 0 || MathUtils.floor(y) > ySize - 1 || MathUtils.ceil(y) < 0) { result.set(0, 0); return result; } Vector3 v11 = field[MathUtils.floor(x)][MathUtils.floor(y)][z]; Vector3 v12 = field[MathUtils.floor(x)][MathUtils.ceil(y)][z]; Vector3 v22 = field[MathUtils.ceil(x)][MathUtils.ceil(y)][z]; Vector3 v21 = field[MathUtils.ceil(x)][MathUtils.floor(y)][z]; float resX = blerp(v11.x, v12.x, v22.x, v21.x, x-(int)x, y-(int)y); float resY = blerp(v11.y, v12.y, v22.y, v21.y, x-(int)x, y-(int)y); result.set(resX*1f, resY*1f); return result; }
Example 6
Source File: Firestorm.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
private IActionResult calcResult(Creature creature, Grid2D.Coordinate cell) { Vector2 position = tmp.set(cell.x(), cell.y()); Array<Creature> underAttack = new Array<Creature>(); Array<Creature> killed = new Array<Creature>(); ObjectIntMap<Creature> expResults = new ObjectIntMap<Creature>(); for (int i = cell.x() - MathUtils.ceil(radius); i <= cell.x() + radius; i++) { for (int j = cell.y() - MathUtils.ceil(radius); j <= cell.y() + radius; j++) { if (position.dst(i, j) <= radius) { WorldObject object = creature.world.get(i, j); if (object instanceof Creature && ((Creature) object).get(Attribute.canBeSelected)) { underAttack.add((Creature) object); } } } } for (Creature c : underAttack) { int attackLevel = (c.getX() == cell.x() && c.getY() == cell.y()) ? this.epicenterAttackLevel : this.attackLevel; int defenceLevel = c.get(Attribute.defenceFor(attackType)); if (attackLevel > defenceLevel) { killed.add(c); if (creature.inRelation(Creature.CreatureRelation.enemy, c)) { expResults.getAndIncrement(creature, 0, ExpHelper.expForKill(creature, c)); } } else { if (creature.inRelation(Creature.CreatureRelation.enemy, c)) { expResults.put(c, ExpHelper.expForDefence(creature, c)); } else { expResults.put(c, ExpHelper.MIN_EXP); } } } return new FirestormResult(creature, owner, underAttack, killed, expResults, cell); }
Example 7
Source File: Teleport.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public static Array<Grid2D.Coordinate> gatherCoordinates(Creature creature, float radius) { Vector2 position = tmp.set(creature.getX(), creature.getY()); Array<Grid2D.Coordinate> available = new Array<Grid2D.Coordinate>(); for (int i = creature.getX() - MathUtils.ceil(radius); i <= creature.getX() + MathUtils.ceil(radius); i++) { for (int j = creature.getY() - MathUtils.ceil(radius); j <= creature.getY() + MathUtils.ceil(radius); j++) { boolean sameCoordinate = i == creature.getX() && j == creature.getY(); boolean canStep = creature.world.canStepTo(i, j); boolean inRadius = position.dst(i, j) <= radius; if (inRadius && (sameCoordinate || canStep)) available.add(new Grid2D.Coordinate(i, j)); } } return available; }
Example 8
Source File: BlockingWindow.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@Override public void act(float delta) { super.act(delta); colorOffset += delta / colorTime; float colorListBlend = colorOffset /** (float) colors.size*/; int from = MathUtils.floor(colorListBlend); int to = MathUtils.ceil(colorListBlend); Color fromColor = colors.get(from % colors.size); Color toColor = colors.get(to % colors.size); setColor(blend(fromColor, toColor, colorListBlend - from)); scaleOffset += delta / disappearTime; setScale(1 - scaleOffset % 1f); }
Example 9
Source File: TimeScorer.java From Klooni1010 with GNU General Public License v3.0 | 4 votes |
private int nanosToSeconds(long nano) { return MathUtils.ceil((float) (nano * NANOS_TO_SECONDS)); }
Example 10
Source File: MathHelper.java From dice-heroes with GNU General Public License v3.0 | 4 votes |
public static float snapToHighest(float value, float snap) { if (snap == 0) return value; return MathUtils.ceil(value / snap) * snap; }
Example 11
Source File: DirectionalLight.java From box2dlights with Apache License 2.0 | 4 votes |
@Override void update () { if (staticLight && !dirty) return; dirty = false; final float width = (rayHandler.x2 - rayHandler.x1); final float height = (rayHandler.y2 - rayHandler.y1); final float sizeOfScreen = width > height ? width : height; float xAxelOffSet = sizeOfScreen * cos; float yAxelOffSet = sizeOfScreen * sin; // preventing length <0 assertion error on box2d. if ((xAxelOffSet * xAxelOffSet < 0.1f) && (yAxelOffSet * yAxelOffSet < 0.1f)) { xAxelOffSet = 1; yAxelOffSet = 1; } final float widthOffSet = sizeOfScreen * -sin; final float heightOffSet = sizeOfScreen * cos; float x = (rayHandler.x1 + rayHandler.x2) * 0.5f - widthOffSet; float y = (rayHandler.y1 + rayHandler.y2) * 0.5f - heightOffSet; final float portionX = 2f * widthOffSet / (rayNum - 1); x = (MathUtils.floor(x / (portionX * 2))) * portionX * 2; final float portionY = 2f * heightOffSet / (rayNum - 1); y = (MathUtils.ceil(y / (portionY * 2))) * portionY * 2; for (int i = 0; i < rayNum; i++) { final float steppedX = i * portionX + x; final float steppedY = i * portionY + y; m_index = i; start[i].x = steppedX - xAxelOffSet; start[i].y = steppedY - yAxelOffSet; mx[i] = end[i].x = steppedX + xAxelOffSet; my[i] = end[i].y = steppedY + yAxelOffSet; if (rayHandler.world != null && !xray) { rayHandler.world.rayCast(ray, start[i], end[i]); } } // update light mesh // ray starting point int size = 0; final int arraySize = rayNum; for (int i = 0; i < arraySize; i++) { segments[size++] = start[i].x; segments[size++] = start[i].y; segments[size++] = colorF; segments[size++] = 1f; segments[size++] = mx[i]; segments[size++] = my[i]; segments[size++] = colorF; segments[size++] = 1f; } lightMesh.setVertices(segments, 0, size); if (!soft || xray) return; size = 0; for (int i = 0; i < arraySize; i++) { segments[size++] = mx[i]; segments[size++] = my[i]; segments[size++] = colorF; segments[size++] = 1f; segments[size++] = mx[i] + softShadowLength * cos; segments[size++] = my[i] + softShadowLength * sin; segments[size++] = zeroColorBits; segments[size++] = 1f; } softShadowMesh.setVertices(segments, 0, size); }