Java Code Examples for com.badlogic.gdx.math.MathUtils

The following examples show how to use com.badlogic.gdx.math.MathUtils. These examples are extracted from open source projects. 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 Project: Unlucky   Source File: Moveset.java    License: MIT License 6 votes vote down vote up
/**
 * Returns a Move array with 4 unique moves from a boss's movepool
 *
 * @param bossId
 * @return
 */
private Move[] getBossMoves(int bossId) {
    Array<Move> pool = rm.bossMoves.get(bossId);
    Move[] ret = new Move[4];
    int index;
    for (int i = 0; i < ret.length; i++) {
        index = MathUtils.random(pool.size - 1);
        Move randMove = pool.get(index);
        Move temp = null;

        if (randMove.type < 2)
            temp = new Move(randMove.type, randMove.name, randMove.minDamage, randMove.maxDamage);
        else if (randMove.type == 2)
            temp = new Move(randMove.name, randMove.minDamage, randMove.crit);
        else if (randMove.type == 3)
            temp = new Move(randMove.name, randMove.minHeal, randMove.maxHeal, randMove.dmgReduction);

        ret[i] = temp;
        //pool.removeIndex(index);
    }

    return ret;
}
 
Example 2
Source Project: Cubes   Source File: ClientSaveManager.java    License: MIT License 6 votes vote down vote up
public static Save createSave(String name, String generatorID, Gamemode gamemode, String seedString) {
  if (name != null) name = name.trim();
  if (name == null || name.isEmpty()) name = "world-" + Integer.toHexString(MathUtils.random.nextInt());
  FileHandle folder = getSavesFolder();
  FileHandle handle = folder.child(name);
  handle.mkdirs();
  Compatibility.get().nomedia(handle);
  Save s = new Save(name, handle);

  SaveOptions options = new SaveOptions();
  options.setWorldSeed(seedString);
  options.worldType = generatorID;
  options.worldGamemode = gamemode;
  s.setSaveOptions(options);

  return s;
}
 
Example 3
Source Project: Radix   Source File: Player.java    License: MIT License 6 votes vote down vote up
public int getBlockInHead(IWorld world) {
    int x = MathUtils.floor(getPosition().getX());
    int z = MathUtils.floor(getPosition().getZ());
    int y = MathUtils.floor(getPosition().getY() + HEIGHT);
    IChunk chunk = world.getChunk(x, z);
    if (chunk != null) {
        if (y >= world.getHeight()) return 0;
        try {
            return chunk.getBlockId(x & (world.getChunkSize() - 1), y, z & (world.getChunkSize() - 1));
        } catch (BlockStorage.CoordinatesOutOfBoundsException e) {
            e.printStackTrace();
            return 0;
        }
    } else {
        return 0;
    }
}
 
Example 4
Source Project: vis-ui   Source File: ExtendedColorPicker.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void updateValuesFromCurrentColor () {
	int[] hsv = ColorUtils.RGBtoHSV(color);
	int ch = hsv[0];
	int cs = hsv[1];
	int cv = hsv[2];

	int cr = MathUtils.round(color.r * 255.0f);
	int cg = MathUtils.round(color.g * 255.0f);
	int cb = MathUtils.round(color.b * 255.0f);
	int ca = MathUtils.round(color.a * 255.0f);

	hBar.setValue(ch);
	sBar.setValue(cs);
	vBar.setValue(cv);

	rBar.setValue(cr);
	gBar.setValue(cg);
	bBar.setValue(cb);

	aBar.setValue(ca);

	verticalBar.setValue(hBar.getValue());
	palette.setValue(sBar.getValue(), vBar.getValue());
}
 
Example 5
Source Project: libgdx-demo-pax-britannica   Source File: Targeting.java    License: MIT License 6 votes vote down vote up
/**
 * return a random ship of the desired type that's in range
 */
private static Ship getTypeInRange(Ship source, Array<Ship> ships, float range) {
	Array<Ship> shipsInRange = new Array<Ship>();
	float range_squared = range * range;

	for (int i = 0; i < ships.size; i++) {
		Ship ship = ships.get(i);
		float currentDistance = source.collisionCenter.dst(ship.collisionCenter);

		if (ship.alive && source.id != ship.id && onScreen(ship.collisionCenter) && (currentDistance < range_squared)) {
			shipsInRange.add(ship);
		}
	}

	if (shipsInRange.size > 0) {
		return shipsInRange.get(MathUtils.random(0, shipsInRange.size - 1));
	} else {
		return null;
	}
}
 
Example 6
Source Project: FruitCatcher   Source File: FallingObject.java    License: Apache License 2.0 6 votes vote down vote up
public FallingObject(ImageProvider imageProvider, TextureRegion [] textureRegions,
					 FallingObjectState state) {
    rect = new Rectangle();
    rect.width = width;
    rect.height = height;
    
    this.textureRegions = textureRegions;
    this.state = state;
    
    if(state.getPosX() < 0 || state.getPosY() < 0) {
    	rect.x = MathUtils.random(0, imageProvider.getScreenWidth()-width);
    	rect.y = imageProvider.getScreenHeight();
    }
    else {
    	rect.x = state.getPosX();
    	rect.y = state.getPosY();
    }
    
    state.setPosX((int) rect.x);
    state.setPosY((int) rect.y);
}
 
Example 7
Source Project: ud406   Source File: Enemy.java    License: MIT License 6 votes vote down vote up
public void update(float delta) {
    switch (direction) {
        case LEFT:
            position.x -= Constants.ENEMY_MOVEMENT_SPEED * delta;
            break;
        case RIGHT:
            position.x += Constants.ENEMY_MOVEMENT_SPEED * delta;
    }

    if (position.x < platform.left) {
        position.x = platform.left;
        direction = Direction.RIGHT;
    } else if (position.x > platform.right) {
        position.x = platform.right;
        direction = Direction.LEFT;
    }

    final float elapsedTime = Utils.secondsSince(startTime);
    final float bobMultiplier = 1 + MathUtils.sin(MathUtils.PI2 * (bobOffset + elapsedTime / Constants.ENEMY_BOB_PERIOD));
    position.y = platform.top + Constants.ENEMY_CENTER.y + Constants.ENEMY_BOB_AMPLITUDE * bobMultiplier;
}
 
Example 8
Source Project: riiablo   Source File: ReliablePacketController.java    License: Apache License 2.0 6 votes vote down vote up
private void updateSentBandwidth() {
  int baseSequence = (sentPackets.getSequence() - config.sentPacketBufferSize + 1 + Packet.USHORT_MAX_VALUE) & Packet.USHORT_MAX_VALUE;

  int bytesSent = 0;
  float startTime = Float.MAX_VALUE;
  float finishTime = 0f;
  int numSamples = config.sentPacketBufferSize / 2;
  for (int i = 0; i < numSamples; i++) {
    int sequence = (baseSequence + i) & Packet.USHORT_MAX_VALUE;
    SentPacketData sentPacketData = sentPackets.find(sequence);
    if (sentPacketData == null) continue;
    bytesSent += sentPacketData.packetSize;
    startTime = Math.min(startTime, sentPacketData.time);
    finishTime = Math.max(finishTime, sentPacketData.time);
  }

  if (startTime != Float.MAX_VALUE && finishTime != 0f) {
    float sentBandwidth = bytesSent / (finishTime - startTime) * 8f / 1000f;
    if (MathUtils.isEqual(this.sentBandwidth, sentBandwidth, TOLERANCE)) {
      this.sentBandwidth += (sentBandwidth - this.sentBandwidth) * config.bandwidthSmoothingFactor;
    } else {
      this.sentBandwidth = sentBandwidth;
    }
  }
}
 
Example 9
Source Project: gdx-vr   Source File: TypeTransformer.java    License: Apache License 2.0 6 votes vote down vote up
public static EyeParams transform(Viewport viewport) {
	int eye = viewport == VirtualReality.head.getLeftEye() ? 0 : 1;
	EyeParams eyeParams = new EyeParams(eye);

	eyeParams.getViewport().setViewport(viewport.getScreenX(), viewport.getScreenY(), MathUtils.nextPowerOfTwo(viewport.getScreenWidth()),
			MathUtils.nextPowerOfTwo(viewport.getScreenHeight()));

	float fov = ((PerspectiveCamera) viewport.getCamera()).fieldOfView;
	eyeParams.getFov().setLeft(fov);
	eyeParams.getFov().setRight(fov);
	eyeParams.getFov().setTop(fov);
	eyeParams.getFov().setBottom(fov);

	for (int i = 0; i < 16; i++) {
		eyeParams.getTransform().getEyeView()[i] = viewport.getCamera().view.val[i];
	}

	for (int i = 0; i < 16; i++) {
		eyeParams.getTransform().getPerspective()[i] = viewport.getCamera().projection.val[i];
	}

	return eyeParams;
}
 
Example 10
Source Project: ud405   Source File: Icicles.java    License: MIT License 6 votes vote down vote up
public void update(float delta) {
    if (MathUtils.random() < delta * Constants.ICICLE_SPAWNS_PER_SECOND) {
        Vector2 newIciclePosition = new Vector2(
                MathUtils.random() * viewport.getWorldWidth(),
                viewport.getWorldHeight()
        );
        Icicle newIcicle = new Icicle(newIciclePosition);
        icicleList.add(newIcicle);
    }

    for (Icicle icicle : icicleList) {
        icicle.update(delta);
    }

    icicleList.begin();
    for (int i = 0; i < icicleList.size; i++) {
        if (icicleList.get(i).position.y < -Constants.ICICLES_HEIGHT) {
            // TODO: Increment count of icicles dodged

            icicleList.removeIndex(i);
        }
    }
    icicleList.end();
}
 
Example 11
Source Project: ud405   Source File: CircularMotion.java    License: MIT License 6 votes vote down vote up
@Override
    public void render() {
        viewport.apply();

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        renderer.setProjectionMatrix(viewport.getCamera().combined);
        renderer.begin(ShapeType.Filled);

        float elapsedNanoseconds = TimeUtils.nanoTime() - initialTime;
        float elapsedSeconds = MathUtils.nanoToSec * elapsedNanoseconds;
        float elapsedPeriods = elapsedSeconds / PERIOD;
        float cyclePosition = elapsedPeriods % 1;

        float x = WORLD_SIZE / 2 + MOVEMENT_RADIUS * MathUtils.cos(MathUtils.PI2 * cyclePosition);
        float y = WORLD_SIZE / 2 + MOVEMENT_RADIUS * MathUtils.sin(MathUtils.PI2 * cyclePosition);

        renderer.circle(x, y, CIRCLE_RADIUS);

        // Uncomment the next line to see the sort of beautiful things you can create with simple movement
//         drawFancyCircles(renderer, elapsedPeriods, 20);
        renderer.end();
    }
 
Example 12
Source Project: xibalba   Source File: EntityFactory.java    License: MIT License 6 votes vote down vote up
/**
 * Create entrance entity.
 *
 * @param mapIndex Map to place it on
 * @return The entrance entity
 */
public Entity createEntrance(int mapIndex) {
  Map map = WorldManager.world.getMap(mapIndex);

  int cellX;
  int cellY;

  do {
    cellX = MathUtils.random(0, map.width - 1);
    cellY = MathUtils.random(0, map.height - 1);
  } while (WorldManager.mapHelpers.isBlocked(mapIndex, new Vector2(cellX, cellY))
      && WorldManager.mapHelpers.getWallNeighbours(mapIndex, cellX, cellY) >= 4);

  Vector2 position = new Vector2(cellX, cellY);
  Entity entity = new Entity();
  entity.add(new EntranceComponent());
  entity.add(new PositionComponent(position));

  entity.add(new VisualComponent(
      Main.asciiAtlas.createSprite("1203"), position
  ));

  return entity;
}
 
Example 13
Source Project: Unlucky   Source File: Player.java    License: MIT License 6 votes vote down vote up
/**
 * Increments level and recalculates max exp
 * Sets increase variables to display on screen
 * Recursively accounts for n consecutive level ups from remaining exp
 *
 * @param remainder the amount of exp left after a level up
 */
public void levelUp(int remainder) {
    level++;

    hpIncrease += MathUtils.random(Util.PLAYER_MIN_HP_INCREASE, Util.PLAYER_MAX_HP_INCREASE);
    int dmgMean = MathUtils.random(Util.PLAYER_MIN_DMG_INCREASE, Util.PLAYER_MAX_DMG_INCREASE);

    // deviates from mean by 0 to 2
    minDmgIncrease += (dmgMean - MathUtils.random(1));
    maxDmgIncrease += (dmgMean + MathUtils.random(1));
    // accuracy increases by 1% every 10 levels
    accuracyIncrease += level % 10 == 0 ? 1 : 0;
    // smoveCd reduces every 10 levels
    if (smoveCd > 1) smoveCd -= level % 10 == 0 ? 1 : 0;

    int prevMaxExp = maxExp;
    maxExp = Util.calculateMaxExp(level, MathUtils.random(3, 5));
    maxExpIncrease += (maxExp - prevMaxExp);

    // another level up
    if (remainder >= maxExp) {
        levelUp(remainder - maxExp);
    } else {
        exp = remainder;
    }
}
 
Example 14
Source Project: Radix   Source File: Biome.java    License: MIT License 6 votes vote down vote up
private int[] getColor(int elevation, int[][] corners) {
    float adjTemp = MathUtils.clamp(temperature - elevation*0.00166667f, 0, 1);
    float adjRainfall = MathUtils.clamp(rainfall, 0, 1) * adjTemp;

    getColTmp[0] = adjTemp - adjRainfall;
    getColTmp[1] = 1 - temperature;
    getColTmp[2] = rainfall;

    float red = 0, green = 0, blue = 0;
    for(int i = 0; i < 3; i++) {
        red += getColTmp[i] * corners[i][0/*red*/];
        green += getColTmp[i] * corners[i][1/*green*/];
        blue += getColTmp[i] * corners[i][2/*blue*/];
    }

    return new int[]{
            (int)MathUtils.clamp(red, 0, 255),
            (int)MathUtils.clamp(green, 0, 255),
            (int)MathUtils.clamp(blue, 0, 255)
    };
}
 
Example 15
Source Project: dice-heroes   Source File: MoveResult.java    License: GNU General Public License v3.0 6 votes vote down vote up
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 16
Source Project: FruitCatcher   Source File: FallingObjectFactory.java    License: Apache License 2.0 6 votes vote down vote up
public FallingObject getFruit() {
    TextureRegion [] textureRegions = new TextureRegion[1];
    int fruitType = MathUtils.random(0, imageProvider.getFruitsCount() - 1);
    textureRegions[0] =  imageProvider.getFruit(fruitType);
    
    boolean inSeason = FruitType.isInSeason(fruitType, season);
    FallingObjectState state = new FallingObjectState();
    if (inSeason) {
    	state.setType(FallingObjectType.SeasonalFruit);
    }
    else {
    	state.setType(FallingObjectType.Fruit);
    }
    state.setIndex(fruitType);
    return new FallingObject(imageProvider, textureRegions, 
                             state);
}
 
Example 17
Source Project: GdxDemo3D   Source File: WanderSteerer.java    License: Apache License 2.0 6 votes vote down vote up
public WanderSteerer(final SteerableBody steerableBody) {
	super(steerableBody);

	this.wanderSB = new Wander<Vector3>(steerableBody) {
		@Override
		protected SteeringAcceleration<Vector3> calculateRealSteering(SteeringAcceleration<Vector3> steering) {
			super.calculateRealSteering(steering);
			steering.linear.y = 0; // remove any vertical acceleration
			return steering;
		}
	};
	this.wanderSB.setWanderOffset(8) //
		.setWanderOrientation(0) //
		.setWanderRadius(0.5f) //
		.setWanderRate(MathUtils.PI2 * 4);

	this.prioritySteering.add(wanderSB);
}
 
Example 18
Source Project: ud406   Source File: Enemy.java    License: MIT License 6 votes vote down vote up
public void update(float delta) {
    switch (direction) {
        case LEFT:
            position.x -= Constants.ENEMY_MOVEMENT_SPEED * delta;
            break;
        case RIGHT:
            position.x += Constants.ENEMY_MOVEMENT_SPEED * delta;
    }

    if (position.x < platform.left) {
        position.x = platform.left;
        direction = Direction.RIGHT;
    } else if (position.x > platform.right) {
        position.x = platform.right;
        direction = Direction.LEFT;
    }

    final float elapsedTime = Utils.secondsSince(startTime);
    final float bobMultiplier = 1 + MathUtils.sin(MathUtils.PI2 * (bobOffset + elapsedTime / Constants.ENEMY_BOB_PERIOD));
    position.y = platform.top + Constants.ENEMY_CENTER.y + Constants.ENEMY_BOB_AMPLITUDE * bobMultiplier;
}
 
Example 19
Source Project: ud406   Source File: Enemy.java    License: MIT License 6 votes vote down vote up
public void update(float delta) {
    switch (direction) {
        case LEFT:
            position.x -= Constants.ENEMY_MOVEMENT_SPEED * delta;
            break;
        case RIGHT:
            position.x += Constants.ENEMY_MOVEMENT_SPEED * delta;
    }

    if (position.x < platform.left) {
        position.x = platform.left;
        direction = Direction.RIGHT;
    } else if (position.x > platform.right) {
        position.x = platform.right;
        direction = Direction.LEFT;
    }

    final float elapsedTime = Utils.secondsSince(startTime);
    final float bobMultiplier = 1 + MathUtils.sin(MathUtils.PI2 * (bobOffset + elapsedTime / Constants.ENEMY_BOB_PERIOD));
    position.y = platform.top + Constants.ENEMY_CENTER.y + Constants.ENEMY_BOB_AMPLITUDE * bobMultiplier;
}
 
Example 20
Source Project: uracer-kotd   Source File: EngineF40.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void shiftUp () {
	if (UseGears) {
		if (gear > 0 && gear < MaxGear) {
			gear++;

			float dist = 2000;
			if (rpm >= dist + 1000) {
				// rpm -= dist;
			} else {
				// rpm = 1000;
			}
		}

		if (gear == 0) {
			gear++;
			// rpm = 1000;
		}

		rpm = MathUtils.clamp(rpm, 1000, 10000);
	}

	gear = MathUtils.clamp(gear, MinGear, MaxGear);
}
 
Example 21
Source Project: dice-heroes   Source File: BlockingWindow.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 22
Source Project: uracer-kotd   Source File: ConeLight.java    License: Apache License 2.0 5 votes vote down vote up
public void setDirection(float direction) {

		this.direction = direction;
		for (int i = 0; i < rayNum; i++) {
			float angle = direction + coneDegree - 2f * coneDegree * i
					/ (rayNum - 1f);
			final float s = sin[i] = MathUtils.sinDeg(angle);
			final float c = cos[i] = MathUtils.cosDeg(angle);
			endX[i] = distance * c;
			endY[i] = distance * s;
		}
		if (staticLight)
			staticUpdate();
	}
 
Example 23
Source Project: ud405   Source File: Icicles.java    License: MIT License 5 votes vote down vote up
public void update(float delta) {
    // TODO: Replace hard-coded spawn rate with a constant
    if (MathUtils.random() < delta * 5) {
        // TODO: Add a new icicle at the top of the viewport at a random x position
    }

    // TODO: Update each icicle

}
 
Example 24
Source Project: uracer-kotd   Source File: ColorUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Color paletteRYG (float amount, float alpha) {
	float greenRatio = MathUtils.clamp(amount, 0.23f, 1);
	float rbRange = (1 - MathUtils.clamp(greenRatio, 0.761f, 1)) / (1 - 0.761f);

	tmpcolor.r = 0.678f + (0.969f - 0.678f) * rbRange;
	tmpcolor.g = greenRatio;
	tmpcolor.b = 0.118f - (0.118f - 0.114f) * rbRange;
	tmpcolor.a = alpha;
	return tmpcolor;
}
 
Example 25
Source Project: ud406   Source File: Enemy.java    License: MIT License 5 votes vote down vote up
public Enemy(Platform platform) {
    this.platform = platform;
    direction = Direction.RIGHT;
    position = new Vector2(platform.left, platform.top + Constants.ENEMY_CENTER.y);
    startTime = TimeUtils.nanoTime();
    health = Constants.ENEMY_HEALTH;

    // TODO: Initialized it
    randomPhase = MathUtils.random();
}
 
Example 26
Source Project: box2dlights   Source File: Box2dLightTest.java    License: Apache License 2.0 5 votes vote down vote up
void initPointLights() {
	clearLights();
	for (int i = 0; i < BALLSNUM; i++) {
		PointLight light = new PointLight(
				rayHandler, RAYS_PER_BALL, null, LIGHT_DISTANCE, 0f, 0f);
		light.attachToBody(balls.get(i), RADIUS / 2f, RADIUS / 2f);
		light.setColor(
				MathUtils.random(),
				MathUtils.random(),
				MathUtils.random(),
				1f);
		lights.add(light);
	}
}
 
Example 27
Source Project: uracer-kotd   Source File: PlayerSmokeTrails.java    License: Apache License 2.0 5 votes vote down vote up
@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 28
Source Project: gdx-ai   Source File: Scene2dSeekTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void create () {
	super.create();

	character = new SteeringActor(container.badlogicSmall, false);
	target = new SteeringActor(container.target);
	inputProcessor = new Scene2dTargetInputProcessor(target);

	character.setMaxLinearSpeed(250);
	character.setMaxLinearAcceleration(2000);

	final Seek<Vector2> seekSB = new Seek<Vector2>(character, target);
	character.setSteeringBehavior(seekSB);

	testTable.addActor(character);
	testTable.addActor(target);

	character.setPosition(container.stageWidth / 2, container.stageHeight / 2, Align.center);
	target.setPosition(MathUtils.random(container.stageWidth), MathUtils.random(container.stageHeight), Align.center);

	Table detailTable = new Table(container.skin);

	detailTable.row();
	addMaxLinearAccelerationController(detailTable, character, 0, 10000, 20);

	detailTable.row();
	addSeparator(detailTable);

	detailTable.row();
	addMaxLinearSpeedController(detailTable, character);

	detailWindow = createDetailWindow(detailTable);
}
 
Example 29
private void loadWindowParams(LwjglApplicationConfiguration configuration) {
    FileHandle file = new FileHandle(LwjglFiles.externalPath + configuration.preferencesDirectory + "/window_params.xml");
    if (!file.exists()) return;

    DisplayMode displayMode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
    int screenWidth = displayMode.getWidth();
    int screenHeight = displayMode.getHeight();

    Preferences prefs = new LwjglPreferences(file);
    configuration.width = MathUtils.clamp(prefs.getInteger("width", configuration.width), 320, screenWidth);
    configuration.height = MathUtils.clamp(prefs.getInteger("height", configuration.height), 320, screenHeight);
    configuration.x = MathUtils.clamp(prefs.getInteger("x", configuration.x), 0, screenWidth - configuration.width);
    configuration.y = MathUtils.clamp(prefs.getInteger("y", configuration.y), 0, screenHeight - configuration.height);
}
 
Example 30
Source Project: Radix   Source File: RadixClient.java    License: MIT License 5 votes vote down vote up
private void updatePositionRotationAndroid() {
    if(!MathUtils.isZero(rotateTouchpad.getKnobPercentX()) || !MathUtils.isZero(rotateTouchpad.getKnobPercentY())) {
        float rotMult = 200 * Gdx.graphics.getDeltaTime();

        player.getRotation().offset(rotateTouchpad.getKnobPercentY() * rotMult, rotateTouchpad.getKnobPercentX() * rotMult);
        updateSelectedBlock();
        gameRenderer.calculateFrustum();
    }

    if(!MathUtils.isZero(moveTouchpad.getKnobPercentX()) || !MathUtils.isZero(moveTouchpad.getKnobPercentY())) {
        float posMult = 4.5f * Gdx.graphics.getDeltaTime();

        float deltaX = 0;
        float deltaZ = 0;
        float yawSine = MathUtils.sinDeg(player.getRotation().getYaw());
        float yawCosine = MathUtils.cosDeg(player.getRotation().getYaw());
        deltaX += yawSine * moveTouchpad.getKnobPercentY() * posMult;
        deltaZ += -yawCosine * moveTouchpad.getKnobPercentY() * posMult;
        deltaX += yawCosine * moveTouchpad.getKnobPercentX() * posMult;
        deltaZ += yawSine * moveTouchpad.getKnobPercentX() * posMult;

        if(!movementHandler.checkDeltaCollision(player, deltaX, 0, deltaZ)
                && !movementHandler.checkDeltaCollision(player, deltaX, 0, deltaZ)) {
            player.getPosition().offset(deltaX, 0, deltaZ);
            gameRenderer.calculateFrustum();
        }
    }
}