本文整理汇总了Java中com.badlogic.gdx.math.MathUtils.random方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.random方法的具体用法?Java MathUtils.random怎么用?Java MathUtils.random使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.math.MathUtils
的用法示例。
在下文中一共展示了MathUtils.random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: calculateShake
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
private boolean calculateShake(float delta) {
if (shake_duration > 0) {
LayerCamera cam = getCam();
float current_strength = (shake_strength / cam.getZoom())
* ((shake_duration - shake_elapsed) / shake_duration);
float x = (MathUtils.random() - .5f) * 2 * current_strength;
float y = (MathUtils.random() - .5f) * 2 * current_strength;
cam.setPosition(obj_check.x-x,obj_check.y-y);
if (shake_elapsed >= shake_duration) {
shake_duration = 0;
shake_strength = 0;
shake_elapsed = 0;
obj_check.set(prev_pos.x, prev_pos.y);
prev_pos.set(Float.NaN, Float.NaN);
}
shake_elapsed += delta;
return true;
}
return false;
}
示例3: part4
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
public void part4() {
if (flag4) {
flag4 = false;
existTime = 0;
moveBasic.velocity.set(0, 0);
moveBasic.acc.set(0, 0);
Entity.postUpdate.add(() -> { GameHelper.clearEnemyBullets(); });
}
if (existTime > 60) {
for (int i=0; i<2; i++)
{
final int c = MathUtils.random(3);
final Entity proj = BaseProjectile.Create(transform.position.cpy(), BulletType.FormCircleS, color4s[c]);
final ImageRenderer renderer = proj.GetComponent(ImageRenderer.class);
proj.AddComponent(new EnemyJudgeCircle(5));
proj.AddComponent(new LambdaComponent(() -> {
renderer.image.setColor(1, 1, 1, alpha4s[c]);
}, 5));
proj.AddComponent(new MoveBasic(new Vector2(1, 0).rotate(MathUtils.random(360f)).scl(MathUtils.random(2f, 7f))));
}
}
if (existTime % 20 == 0) {
for (int i=0; i<4; i++)
alpha4s[i] = MathUtils.randomBoolean() || alpha4s[i] < 0.4f ? 0.88f : 0.12f;
}
}
示例4: nextInterval
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
final void nextInterval(){
switch(type) {
case ORDER_DELAY_LOOP:
if(++currentiInterval >= intervals.length){
currentiInterval = 0;
}
break;
case RANDOM:
currentiInterval = MathUtils.random(intervals.length - 1);
break;
}
}
示例5: updateNextTime
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
/**ʹnextTimeָ����ȷ��ʱ�� */
public final void updateNextTime() {
long interval = MathUtils.random(start, end);
nextTime = BaseTimer.getEngineTime() + interval; // + intervals[currentiInterval];
// nextTime = System.currentTimeMillis() + intervals[currentiInterval];
}
示例6: updateWorldVertices
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
public float[] updateWorldVertices (Slot slot, boolean premultipliedAlpha) {
if (regions == null) throw new IllegalStateException("Regions have not been set: " + this);
int frameIndex = (int)(slot.getAttachmentTime() / frameTime);
switch (mode) {
case forward:
frameIndex = Math.min(regions.length - 1, frameIndex);
break;
case forwardLoop:
frameIndex = frameIndex % regions.length;
break;
case pingPong:
frameIndex = frameIndex % (regions.length << 1);
if (frameIndex >= regions.length) frameIndex = regions.length - 1 - (frameIndex - regions.length);
break;
case random:
frameIndex = MathUtils.random(regions.length - 1);
break;
case backward:
frameIndex = Math.max(regions.length - frameIndex - 1, 0);
break;
case backwardLoop:
frameIndex = frameIndex % regions.length;
frameIndex = regions.length - frameIndex - 1;
break;
}
setRegion(regions[frameIndex]);
return super.updateWorldVertices(slot, premultipliedAlpha);
}
示例7: update
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
public void update(float delta) {
int tilesToUpdate = (int) (percentTilesUpdatedPerSecond * width*height * delta);
for(int i = 0; i < tilesToUpdate; i++) {
int x = MathUtils.random(width-1);
int y = MathUtils.random(height-1);
tiles[x][y].update(delta);
}
//System.out.println("entities tracked: " + entities);
// update entities
Entity[] entities = this.entities.toArray(new Entity[this.entities.size()]);
for(Entity e: entities)
e.update(delta);
/*synchronized (entitiesToAdd) {
for (Entity e : entitiesToAdd) {
for (Level level : levels)
level.entities.remove(e);
entities.add(e);
e.addedToLevel(this);
}
entitiesToAdd.clear();
}
synchronized (entitiesToRemove) {
for (Entity e : entitiesToRemove)
entities.remove(e);
entitiesToRemove.clear();
}*/
}
示例8: process
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
@Override
public void process(CellDecorator c, float delta) {
final float temperature = c.mask().temperature;
if ( temperature > 0 && MathUtils.random(100) < temperature ) {
c.setNextType(PlanetCell.CellType.WATER);
}
}
示例9: generateRandomBytes
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
private byte[] generateRandomBytes(int length) {
byte[] ret = new byte[length];
for (int i = 0; i < length; i++) {
ret[i] = (byte) MathUtils.random(Byte.MIN_VALUE, Byte.MAX_VALUE);
}
return ret;
}
示例10: getRandomEffect
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
public IEffect getRandomEffect() {
if (effects.size == 0) return null;
int random = MathUtils.random(0, effects.size - 1);
try {
return effects.get(random).newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: WeakEnemy
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
public WeakEnemy(int choiceToMove, float xOffset, float yOffset)
{
health = 4;
this.choiceToMove = choiceToMove;
posX = xOffset;
posY = Gdx.graphics.getHeight() + 50 + yOffset;
texture = AssetLoader.assetManager.get("weakenemy.png", Texture.class);
sprite = new Sprite(texture);
sprite.setOriginCenter();
sprite.setRotation(180);
sprite.setPosition(posX, posY);
delayWithAttack = MathUtils.random(70f)+ 50f;
delay = delayWithAttack;
switch(choiceToMove)
{
case 0:
posX = -30 + xOffset;
bulletType = BulletType.ROCKET;
break;
case 1:
posX = Gdx.graphics.getWidth() + 30 + xOffset;
bulletType = BulletType.ION;
break;
case 2:
posX = Gdx.graphics.getWidth() / 2 + xOffset;
bulletType = BulletType.ROCKET;
break;
case 3:
posX = Gdx.graphics.getWidth() / 2 + xOffset;
bulletType = BulletType.ION;
break;
}
}
示例12: push
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
private void push (T insertKey, int index1, T key1, int index2, T key2, int index3, T key3) {
T[] keyTable = this.keyTable;
int mask = this.mask;
// Push keys until an empty bucket is found.
T evictedKey;
int i = 0, pushIterations = this.pushIterations;
do {
// Replace the key and value for one of the hashes.
switch (MathUtils.random(2)) {
case 0:
evictedKey = key1;
keyTable[index1] = insertKey;
break;
case 1:
evictedKey = key2;
keyTable[index2] = insertKey;
break;
default:
evictedKey = key3;
keyTable[index3] = insertKey;
break;
}
// If the evicted key hashes to an empty bucket, put it there and stop.
int hashCode = evictedKey.hashCode();
index1 = hashCode & mask;
key1 = keyTable[index1];
if (key1 == null) {
keyTable[index1] = evictedKey;
if (size++ >= threshold) resize(capacity << 1);
return;
}
index2 = hash2(hashCode);
key2 = keyTable[index2];
if (key2 == null) {
keyTable[index2] = evictedKey;
if (size++ >= threshold) resize(capacity << 1);
return;
}
index3 = hash3(hashCode);
key3 = keyTable[index3];
if (key3 == null) {
keyTable[index3] = evictedKey;
if (size++ >= threshold) resize(capacity << 1);
return;
}
if (++i == pushIterations) break;
insertKey = evictedKey;
} while (true);
addStash(evictedKey);
}
示例13: init
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
private void init() {
// Music
musicManager = playState.getGSM().getGame().getMusicManager();
musicManager.addMusic(bossMusic, bossMusicName);
// sound
soundManager = playState.getGSM().getGame().getSoundManager();
soundManager.addSound(bossSoundFilePath, bossSoundName);
soundManager.addSound(bossSpawnSoundFilePath, bossSpawnSoundName);
// Start Graphics
filePath = "data/spaceships/samushipboss.png";
frameLengthTime = 1f / 2f;
enemyBossSprite = new Animator(3, 4, filePath, 3, 4, frameLengthTime);
// Set Wing Booleans
isLeftWingDead = false;
isRightWingDead = false;
isMiddleInvincible = true;
isDead = false;
bossBulletDamage = -20;
randomAttackCooldown = MathUtils.random(200, 800);
randomAttackCooldownLeft = MathUtils.random(400, 1000);
randomAttackCooldownRight = MathUtils.random(400, 1000);
// HP
leftWingHealth = 1500;
rightWingHealth = 1500;
healthbar = 3000;
// Dimension Size
width = 196;
height = 107;
// Hit Boxes | 0 = left, 1 = center, 2 = right
// We should probably store the values of these numbers in an array for the
// extra dimensions next time so we can efficiently loop it
// Might need to find a better algorithm for this
bossHitBoxes = new Rectangle[3];
bossHitBoxes[0] = new Rectangle(x, y, 48, height);
bossHitBoxes[1] = new Rectangle(x + 49, y + 27, 98, 75);
bossHitBoxes[2] = new Rectangle(x + 148, y, 48, height);
// Start Timer
timeSinceBattleBegan = TimeUtils.millis();
bulletCooldownLeft = TimeUtils.millis();
bulletCooldownRight = TimeUtils.millis();
leftWingExplosionTimer = TimeUtils.millis();
rightWingExplosionTimer = TimeUtils.millis();
bossDeathExplosionTimer = TimeUtils.millis();
// Graphics Explosion Counter
rightWingExplosionCounter = 0;
leftWingExplosionCounter = 0;
bossDeathExplosionCounter = 0;
}
示例14: resetPosition
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
void resetPosition() {
position.y = 0;
position.x = MathUtils.random(Gdx.graphics.getWidth());
}
示例15: triggerSprinkler
import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
private void triggerSprinkler(E e) {
for (int i = 0; i < MathUtils.random(1, 2); i++) {
sand(e.posX() + MathUtils.random(0, e.boundsMaxx()), e.posY(), -90 + MathUtils.random(-2, 2), MathUtils.random(10, 40));
}
}