本文整理汇总了Java中com.badlogic.gdx.math.MathUtils类的典型用法代码示例。如果您正苦于以下问题:Java MathUtils类的具体用法?Java MathUtils怎么用?Java MathUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MathUtils类属于com.badlogic.gdx.math包,在下文中一共展示了MathUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTurretAngle
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
public void setTurretAngle(Entity tower){
AngleComponent angle = Mappers.ANGLE_M.get(tower);
PositionComponent towerPos = Mappers.POSITION_M.get(tower);
TargetComponent target = Mappers.TARGET_M.get(tower);
if (target.getTarget() != null) {
PositionComponent targetPos = Mappers.POSITION_M.get(target.getTarget());
if(targetPos == null) return;
double difX = targetPos.position.x - towerPos.position.x;
double difY = targetPos.position.y - towerPos.position.y;
// set direction
float angleGoal = (float) Math.toDegrees(Math.atan2(difY, difX));
angle.spriteAngle = MathUtils.lerpAngleDeg(angle.spriteAngle, angleGoal,
Gdx.graphics.getDeltaTime() + 0.2f);
}
}
示例2: updateTimer
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
@Override
public boolean updateTimer(){
if(!running){
return false;
}
final long currentTime = BaseTimer.getEngineTime();
if(currentTime > nextTime){
// nextInterval();
//�������
long interval = MathUtils.random(start, end);
// currentiInterval = MathUtils.random(intervals.length - 1);
nextTime = currentTime + interval; // + intervals[currentiInterval];
return true;
}
return false;
}
示例3: draw
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
@Override
public void draw(Batch batch, float parentAlpha) {
if (background != null) {
// draw background
if (size > 1) {
for (int i = 0; i < size; i++) {
y = (i % (size / 3)) + yoff;
x = (i / (size / 3)) + xoff;
x_check = pos_x + (getWidth() * x);
y_check = pos_y + (getHeight() * y);
batch.draw(background, MathUtils.floor(getX() + x_check),MathUtils.floor( getY() + y_check), getWidth(), getHeight());
}
} else {
batch.draw(background, MathUtils.floor(getX() + pos_x), MathUtils.floor(getY() + pos_y), getWidth(), getHeight());
}
}
super.draw(batch, parentAlpha);
}
示例4: drawLayer2
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
@Override
public void drawLayer2(Tile tile){
PowerTurretEntity entity = tile.entity();
if(entity.power >= powerUsed && entity.blockTarget != null && Angles.angleDist(entity.angleTo(entity.blockTarget), entity.rotation) < 10){
Tile targetTile = entity.blockTarget.tile;
Vector2 offset = targetTile.block().getPlaceOffset();
Angles.translation(entity.rotation, 4f);
float x = tile.worldx() + Angles.x(), y = tile.worldy() + Angles.y();
float x2 = entity.blockTarget.x + offset.x, y2 = entity.blockTarget.y + offset.y;
Draw.color(Hue.rgb(138, 244, 138, (MathUtils.sin(Timers.time()) + 1f) / 14f));
Draw.alpha(0.3f);
Draw.thickness(4f);
Draw.line(x, y, x2, y2);
Draw.thickness(2f);
Draw.rect("circle", x2, y2, 7f, 7f);
Draw.alpha(1f);
Draw.thickness(2f);
Draw.line(x, y, x2, y2);
Draw.thickness(1f);
Draw.rect("circle", x2, y2, 5f, 5f);
Draw.reset();
}
}
示例5: setHealth
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
/**
* Setzt die Anzahl der Lebenspunkte direkt.
* Sollte so ehr selten benutzt werden.
*
* @see Player#applyDamage(int)
* @see Player#heal(int)
*
* @param health die neue Anzahl Lebenspunkte
*/
public void setHealth(int health) {
if (health > 100)
health = 100;
if (health < 0 || MathUtils.isZero(health))
{
if (cheatManager.isImmortal())
{
this.health = 100;
return;
}
health = 0;
if (deadCallback != null)
deadCallback.run();
}
this.health = health;
}
示例6: draw
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
public void draw(SpriteBatch batch) {
// If we beat a new record, the cup color will linear interpolate to the high score color
cupColor.lerp(isNewRecord() ? Klooni.theme.highScore : Klooni.theme.currentScore, 0.05f);
batch.setColor(cupColor);
batch.draw(cupTexture, cupArea.x, cupArea.y, cupArea.width, cupArea.height);
int roundShown = MathUtils.round(shownScore);
if (roundShown != currentScore) {
shownScore = Interpolation.linear.apply(shownScore, currentScore, 0.1f);
currentScoreLabel.setText(Integer.toString(MathUtils.round(shownScore)));
}
currentScoreLabel.setColor(Klooni.theme.currentScore);
currentScoreLabel.draw(batch, 1f);
highScoreLabel.setColor(Klooni.theme.highScore);
highScoreLabel.draw(batch, 1f);
}
示例7: ObjectSet
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
/** Creates a new set with the specified initial capacity and load factor. This set will hold initialCapacity items before
* growing the backing table.
* @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */
public ObjectSet (int initialCapacity, float loadFactor) {
if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
initialCapacity = MathUtils.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor));
if (initialCapacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity);
capacity = initialCapacity;
if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor);
this.loadFactor = loadFactor;
threshold = (int)(capacity * loadFactor);
mask = capacity - 1;
hashShift = 31 - Integer.numberOfTrailingZeros(capacity);
stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) * 2);
pushIterations = Math.max(Math.min(capacity, 8), (int)Math.sqrt(capacity) / 8);
keyTable = (T[])new Object[capacity + stashCapacity];
}
示例8: spawnStructure
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
public E spawnStructure(String id, int layer) {
Vector2 location = planetCreationSystem.getSpawnLocation();
E e = E.E()
.pos(location.x, location.y)
.anim(id)
.originX(0.5f)
.originY(0.1f)
.renderLayer(layer)
.angle()
.physics()
.planetbound()
.flammable()
.tint(Tint.TRANSPARENT)
.script(sequence(delay(MathUtils.random(0.1f, 0.4f)), add(new Mass(1.1f)), tween(Tint.TRANSPARENT, Tint.WHITE, 0.2f)))
.orientToGravityIgnoreFloor(true);
if (G.DEBUG_NO_ENTITY_RENDERING) {
e.invisible();
}
return e;
}
示例9: enemyBulletPlayerCollision
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
private void enemyBulletPlayerCollision() {
// Check Collision for enemies hitting the player
for (int i = 0; i < enemyBulletList.size; i++) {
if (enemyBulletList.get(i).getBoundingBox().contains(player.getBoundingBox())
|| player.getBoundingBox().contains(enemyBulletList.get(i).getBoundingBox())) {
// Play Explosion on Player
explosionList.add(new Explosion((player.getX() + MathUtils.random(0, 32)),
player.getY() + MathUtils.random(0, 32), 0, 0, "data/hit_and_explosions/impactHit.png",
"data/audio/sound/Bomb Explosion.wav", "Player Hit", 3, 1, 3, 1, 1f / 40f, playState));
// Reduce Player Health
HealthBar tempHP = (HealthBar) playState.getHUD(0);
tempHP.setHealthLeft(enemyBulletList.get(i).getDamageValue());
// Remove Bullet
enemyBulletList.get(i).dispose();
enemyBulletList.get(i).removeBullets();
}
}
}
示例10: act
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
@Override
public void act(float delta) {
if (getY() + getTextureRegion().getRegionHeight() > Gdx.graphics.getHeight()) {
setY(Gdx.graphics.getHeight() - getTextureRegion().getRegionHeight());
setYspeed(0.0f);
}
if (getY() + getTextureRegion().getRegionHeight() < 0) {
dispose();
}
if (flying) {
float percent = (getYspeed() + 1000) / 800;
percent = MathUtils.clamp(percent, 0.0f, 1.0f);
setRotation(120.0f * percent - 90.0f);
} else {
setRotation(0.0f);
}
}
示例11: handle
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
public void handle() {
if (Gdx.input.isKeyPressed(Input.Keys.W) || Gdx.input.isKeyPressed(Input.Keys.UP)) {
translate(0, 10);
}
if (Gdx.input.isKeyPressed(Input.Keys.A) || Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
translate(-10, 0);
}
if (Gdx.input.isKeyPressed(Input.Keys.S) || Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
translate(0, -10);
}
if (Gdx.input.isKeyPressed(Input.Keys.D) || Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
translate(10, 0);
}
if (Gdx.input.isKeyPressed(Input.Keys.I)) {
zoom -= 0.05;
}
if (Gdx.input.isKeyPressed(Input.Keys.O)) {
zoom += 0.05;
}
zoom = MathUtils.clamp(zoom, 0.5f, 2);
position.x = MathUtils.clamp(position.x, left, right);
position.y = MathUtils.clamp(position.y, bottom, top);
}
示例12: smoothMask
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
private void smoothMask(Planet planet) {
for (int y = 1; y < (SIMULATION_HEIGHT / GRADIENT_SCALE) - 1; y++) {
if (G.INTERLACING_SIMULATION && y % 2 == lace) {
for (int x = 1; x < (SIMULATION_WIDTH / GRADIENT_SCALE) - 1; x++) {
planet.tempMask[y][x].temperature = planet.mask[y][x].temperature;
for (int i = 0; i < 8; i++) {
planet.tempMask[y][x].temperature =
Math.max(
(planet.mask[y + PlanetCell.directions[i][1]][x + PlanetCell.directions[i][0]].temperature) * TEMPERATURE_LOSS,
planet.tempMask[y][x].temperature
);
}
}
}
}
for (int y = 1; y < (SIMULATION_HEIGHT / GRADIENT_SCALE) - 1; y++) {
for (int x = 1; x < (SIMULATION_WIDTH / GRADIENT_SCALE) - 1; x++) {
planet.mask[y][x].temperature = MathUtils.clamp(planet.tempMask[y][x].temperature, -100f, StatusMask.MAX_TEMPERATURE) * 0.95f;
}
}
}
示例13: draw
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
@Override
public void draw(Batch batch) {
vanishElapsed += Gdx.graphics.getDeltaTime();
// vanishElapsed might be < 0 (delay), so clamp to 0
float progress = Math.min(1f,
Math.max(vanishElapsed, 0f) / vanishLifetime);
// If one were to plot the elasticIn function, they would see that the slope increases
// a lot towards the end- a linear interpolation between the last size + the desired
// size at 20% seems to look a lot better.
vanishSize = MathUtils.lerp(
vanishSize,
Interpolation.elasticIn.apply(cell.size, 0, progress),
0.2f
);
float centerOffset = cell.size * 0.5f - vanishSize * 0.5f;
Cell.draw(vanishColor, batch, cell.pos.x + centerOffset, cell.pos.y + centerOffset, vanishSize);
}
示例14: calcAnglePoint
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
public void calcAnglePoint(int degrees, Vector2 out) {
degrees = degrees % 360;
degrees = degrees < 0 ? degrees + 360 : degrees;
if (degrees >= 45 && degrees < 135) {
out.y = 1f;
out.x = out.y / (float) Math.tan(degrees * MathUtils.degreesToRadians);
} else if (degrees >= 135 && degrees < 225) {
out.x = -1f;
out.y = out.x * (float) Math.tan(degrees * MathUtils.degreesToRadians);
} else if (degrees >= 225 && degrees < 315) {
out.y = -1f;
out.x = out.y / (float) Math.tan(degrees * MathUtils.degreesToRadians);
} else {
out.x = 1f;
out.y = out.x * (float) Math.tan(degrees * MathUtils.degreesToRadians);
}
}
示例15: Initialize
import com.badlogic.gdx.math.MathUtils; //导入依赖的package包/类
@Override
public void Initialize(Entity entity) {
Callable<Object> pause = () -> { return null; };
yield.append(pause, 120);
yield.append(() -> {
for (int i=0; i<=1; i++) {
Entity sprite = BaseSprite.Create(new Vector2(135 + i * 300, 730), i, 300 + i * 300);
sprites[i] = sprite;
final Transform tr = sprite.GetComponent(Transform.class);
tr.scale.set(0.5f, 0.5f);
sprite.AddComponent(new LambdaComponent(() -> {
for (int angle=MathUtils.random(360), k=0; k<24; angle+=15, k++)
BaseProjectile.Create(tr.position.cpy(), BulletType.FormCircleLightM, BulletType.ColorYellow,
new EnemyJudgeCircle(13),
new MoveBasic(new Vector2(7.2f, 0).rotate(angle)));
}, 40, 30));
sprite.AddComponent(new MoveFunction(MoveFunctionTarget.VELOCITY, MoveFunctionType.ASSIGNMENT, (time) -> {
return IMoveFunction.vct2_tmp1.set(0, time < 30 ? -8 : 0);
}));
}
});
yield.append(pause, 900);
}