use of com.badlogic.gdx.math.Vector2 in project Entitas-Java by Rubentxu.
the class CreateRadarSensorSystem method execute.
@Override
protected void execute(List<SensorEntity> entities) {
Vector2[] vertices = new Vector2[8];
vertices[0] = new Vector2();
for (SensorEntity e : entities) {
GameEntity gameEntity = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
RigidBody rigidBody = gameEntity.getRigidBody();
RadarSensor radarSensor = e.getRadarSensor();
if (radarSensor.angle < 180) {
for (int i = 0; i < 7; i++) {
float angle = (float) (i / 6.0 * radarSensor.angle) - (radarSensor.angle / 2) + (radarSensor.axis2D.ordinal() * 90);
vertices[i + 1] = new Vector2(radarSensor.distance * MathUtils.cosDeg(angle), radarSensor.distance * MathUtils.sinDeg(angle));
}
FixtureDef radarFixture = bodyBuilder.fixtureDefBuilder().polygonShape(vertices).sensor().build();
rigidBody.body.createFixture(radarFixture).setUserData("RadarSensor");
}
}
}
use of com.badlogic.gdx.math.Vector2 in project Entitas-Java by Rubentxu.
the class RadialGravityActuatorSystem method execute.
@Override
public void execute(float deltaTime) {
for (ActuatorEntity e : group.getEntities()) {
RadialGravityActuator actuator = e.getRadialGravityActuator();
GameEntity owner = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
Vector2 planet_position = owner.getRigidBody().body.getWorldCenter();
SensorEntity gravitySensor = Indexed.getSensorsEntity(e.getLink().ownerEntity, "RadialGravitySensor");
for (int index : gravitySensor.getNearSensor().distanceContactList) {
GameEntity gameEntity = Indexed.getInteractiveEntity(index);
body = gameEntity.getRigidBody().body;
debris_position = body.getWorldCenter();
planet_distance.set(0, 0);
planet_distance.add(debris_position);
planet_distance.sub(planet_position);
force = -(float) ((actuator.gravity * body.getMass()) / planet_distance.len());
if (planet_distance.len() < actuator.radius * actuator.gravityFactor) {
planet_distance.scl(force);
body.applyForceToCenter(planet_distance, true);
float desiredAngle = MathUtils.atan2(-body.getLinearVelocity().x, body.getLinearVelocity().y);
while (desiredAngle < -180 * MathUtils.degreesToRadians) desiredAngle += 360 * MathUtils.degreesToRadians;
while (desiredAngle > 180 * MathUtils.degreesToRadians) desiredAngle -= 360 * MathUtils.degreesToRadians;
body.applyTorque(desiredAngle < 0 ? planet_distance.nor().len() / 2 : -planet_distance.nor().len() / 2, true);
}
}
}
}
use of com.badlogic.gdx.math.Vector2 in project Entitas-Java by Rubentxu.
the class InputManagerGDX method update.
@Override
public void update(float deltaTime) {
//for every keystate, set pressed and released to false.
for (int i = 0; i < 256; i++) {
KeyState k = inputStateData.keyStates[i];
k.pressed = false;
k.released = false;
}
for (int i = 0; i < inputStateData.pointerStates.length; i++) {
PointerState<Vector2, Vector3> t = inputStateData.pointerStates[i];
if (t.down && !t.pressed)
t.clickTime += deltaTime;
t.pressed = false;
t.released = false;
t.displacement.x = 0;
t.displacement.y = 0;
}
if (entitas.actuator.hasDragActuator() && jointDef == null) {
this.dragActuator = entitas.actuator.getDragActuator();
jointDef = new MouseJointDef();
jointDef.bodyA = Indexed.getInteractiveEntity(dragActuator.targetEntity).getRigidBody().body;
jointDef.collideConnected = dragActuator.collideConnected;
jointDef.maxForce = dragActuator.maxForce;
}
for (GameController controller : controllers) {
controller.update(this, entitas);
}
}
use of com.badlogic.gdx.math.Vector2 in project Entitas-Java by Rubentxu.
the class PlatformExamples method createScene.
@Override
public void createScene(Engine engine, Entitas entitas) {
AssetsManagerGDX assetsManager = engine.getManager(AssetsManagerGDX.class);
assetsManager.loadTexture("assets/imagenes/fondos/fondo.jpg");
assetsManager.loadTexture("assets/imagenes/fondos/nubes.png");
assetsManager.loadTexture("assets/imagenes/fondos/arboles.png");
assetsManager.finishLoading();
// entitas.scene.createEntity()
// .addParallaxLayer(new TextureRegion(assetsManager.getTexture("assets/imagenes/fondos/fondo.jpg"))
// , new Vector2(0.7f,0f),new Vector2(0, 1),new Vector2(0, 0));
entitas.scene.createEntity().addParallaxLayer(new TextureRegion(assetsManager.getTexture("assets/imagenes/fondos/nubes.png")), new Vector2(0.5f, 1.0f), new Vector2(0, 10), new Vector2(0, 0));
entitas.scene.createEntity().addParallaxLayer(new TextureRegion(assetsManager.getTexture("assets/imagenes/fondos/arboles.png")), new Vector2(0.9f, 0), new Vector2(0, -0.4f), new Vector2(0, 0));
// entitas.scene.createEntity()
// .addCPointLight(55, Color.GOLD, 45, new Vector2(10,4));
// entitas.scene.createEntity()
// .addCChainLight(25, Color.FOREST, 180, 145, new float[]{-5, 0, 0, 0, 0, 0,30,12});
// entitas.scene.createEntity()
// .addCDirectionalLight(84, Color.SKY, 270);
entitas.scene.createEntity().addCConeLight(35, Color.GREEN, 40, new Vector2(16, 13), 250, 60);
SceneManagerGDX sceneManager = engine.getManager(SceneManagerGDX.class);
GameEntity ground = sceneManager.createEntity("Ground");
ground.getRigidBody().body.setTransform(10, 1, 0);
GameEntity mariano = sceneManager.createEntity("Mariano");
mariano.getRigidBody().body.setTransform(10, 6, 0);
GameEntity box1 = sceneManager.createEntity("Box");
box1.addTags("Box");
box1.getRigidBody().body.setTransform(20, 7, 0);
GameEntity box2 = sceneManager.createEntity("Box");
box2.addTags("Box2");
box2.getRigidBody().body.setTransform(25, 7, 0);
entitas.actuator.setDragActuator(ground.getCreationIndex(), false, 1000);
}
use of com.badlogic.gdx.math.Vector2 in project nhglib by VoidZombie.
the class InputHandler method processPointerInput.
private void processPointerInput(Integer pointer, NhgInput input) {
if (config != null) {
Vector2 axis = VectorPool.getVector2();
PointerInputConfiguration conf = config.getPointerConfiguration(input.getName());
switch(conf.getPointerSourceType()) {
case POINTER_DELTA_XY:
axis.set(Gdx.input.getDeltaX(pointer), Gdx.input.getDeltaY(pointer));
axis.scl(conf.getHorizontalSensitivity(), conf.getVerticalSensitivity());
break;
case POINTER_XY:
axis.set(Gdx.input.getX(pointer), Gdx.input.getY(pointer));
break;
}
InputSource inputSource = input.getInputSource();
inputSource.setName(input.getName());
inputSource.setValue(axis);
}
}
Aggregations