Search in sources :

Example 1 with ActuatorEntity

use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity in project Entitas-Java by Rubentxu.

the class CreateRadialGravityActuatorSystem method execute.

@Override
protected void execute(List<ActuatorEntity> actuatorEntities) {
    for (ActuatorEntity e : actuatorEntities) {
        RadialGravityActuator actuator = e.getRadialGravityActuator();
        GameEntity owner = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
        entitas.sensor.createEntity().addNearSensor("", actuator.radius, 0).addLink("RadialGravitySensor", owner.getCreationIndex());
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) RadialGravityActuator(ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator) ActuatorEntity(ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)

Example 2 with ActuatorEntity

use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity in project Entitas-Java by Rubentxu.

the class Indexed method initialize.

public static void initialize(Entitas entitas) {
    _entitas = entitas;
    index = new KeyIndex(-1, null);
    // GameEntity contains Sensors entities
    _entitas.sensor.addEntityIndex(new PrimaryEntityIndex<SensorEntity, KeyIndex>(Indexed.SensorsEntityIndex, ((e, c) -> {
        if (c != null) {
            ilargia.egdx.logicbricks.component.sensor.Link link = (ilargia.egdx.logicbricks.component.sensor.Link) c;
            return new KeyIndex(link.ownerEntity, link.sensorReference);
        }
        return new KeyIndex(e.getLink().ownerEntity, e.getLink().sensorReference);
    }), _entitas.sensor.getGroup(SensorMatcher.Link())));
    // GameEntity contains Actuator entities
    _entitas.actuator.addEntityIndex(new PrimaryEntityIndex<ActuatorEntity, KeyIndex>(Indexed.ActuatorsEntityIndex, ((e, c) -> {
        if (c != null) {
            Link link = (Link) c;
            return new KeyIndex(link.ownerEntity, link.actuatorReference);
        }
        return new KeyIndex(e.getLink().ownerEntity, e.getLink().actuatorReference);
    }), _entitas.actuator.getGroup(ActuatorMatcher.Link())));
    // Interactive GameEntity index
    _entitas.game.addEntityIndex(new PrimaryEntityIndex<GameEntity, Integer>(Indexed.InteractiveEntityIndex, ((e, c) -> e.getCreationIndex()), _entitas.game.getGroup(GameMatcher.Interactive())));
    // Tags GameEntity index
    _entitas.game.addEntityIndex(new EntityIndex<GameEntity, String>(Indexed.TagEntityIndex, _entitas.game.getGroup(Matcher.AllOf(GameMatcher.Tags(), GameMatcher.Interactive())), ((e, c) -> e.getTags().values.toArray(new String[0]))));
    // Sensors context GameEntities
    _entitas.game.addEntityIndex(new EntityIndex<GameEntity, Integer>(Indexed.GameEntitiesInSensorIndex, _entitas.game.getGroup(GameMatcher.Interactive()), ((e, c) -> new Integer[0])));
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) Link(ilargia.egdx.logicbricks.component.actuator.Link) ActuatorEntity(ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)

Example 3 with ActuatorEntity

use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity in project Entitas-Java by Rubentxu.

the class TextureRendererSystem method render.

@Override
public void render() {
    batch.setProjectionMatrix(cam.combined);
    batch.begin();
    for (GameEntity e : groupTextureView.getEntities()) {
        TextureView view = e.getTextureView();
        Body body = e.getRigidBody().body;
        processTextureFlip(view);
        batch.setColor(1f, 1f, 1f, 1f);
        if (view.opacity < 1)
            batch.setColor(1f, 1f, 1f, view.opacity);
        batch.draw(view.texture, body.getPosition().x - view.bounds.extentsX, body.getPosition().y - view.bounds.extentsY, view.bounds.extentsX, view.bounds.extentsY, view.bounds.extentsX * 2, view.bounds.extentsY * 2, 1, 1, MathUtils.radiansToDegrees * body.getTransform().getRotation());
    }
    for (ActuatorEntity e : groupEffect.getEntities()) {
        if (e.getLink().isOpen) {
            ParticleEffectActuator effectActuator = e.getParticleEffectActuator();
            effectActuator.particleEffect.draw(batch);
        }
    }
    batch.end();
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) ParticleEffectActuator(ilargia.egdx.logicbricks.component.actuator.ParticleEffectActuator) TextureView(ilargia.egdx.logicbricks.component.game.TextureView) Body(com.badlogic.gdx.physics.box2d.Body) ActuatorEntity(ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)

Example 4 with ActuatorEntity

use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity in project Entitas-Java by Rubentxu.

the class ActuatorSystem method execute.

@Override
public void execute(float deltaTime) {
    for (ActuatorEntity e : groupTexture.getEntities()) {
        if (e.getLink().isOpen) {
            TextureActuator textureActuator = e.getTextureActuator();
            textureActuator.actuator.execute(e.getLink().ownerEntity);
        }
    }
    for (ActuatorEntity e : groupVelocity.getEntities()) {
        if (e.getLink().isOpen) {
            VelocityActuator velocityActuator = e.getVelocityActuator();
            velocityActuator.actuator.execute(e.getLink().ownerEntity);
        }
    }
    for (ActuatorEntity e : groupCamera.getEntities()) {
        if (e.getLink().isOpen) {
            CameraActuator cameraActuator = e.getCameraActuator();
            cameraActuator.actuator.execute(e.getLink().ownerEntity);
        }
    }
    for (ActuatorEntity e : groupEffect.getEntities()) {
        if (e.getLink().isOpen) {
            ParticleEffectActuator effectActuator = e.getParticleEffectActuator();
            effectActuator.actuator.execute(e.getLink().ownerEntity);
        }
    }
}
Also used : ParticleEffectActuator(ilargia.egdx.logicbricks.component.actuator.ParticleEffectActuator) CameraActuator(ilargia.egdx.logicbricks.component.actuator.CameraActuator) TextureActuator(ilargia.egdx.logicbricks.component.actuator.TextureActuator) ActuatorEntity(ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity) VelocityActuator(ilargia.egdx.logicbricks.component.actuator.VelocityActuator)

Example 5 with ActuatorEntity

use of ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity 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);
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) RadialGravityActuator(ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator) ActuatorEntity(ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)

Aggregations

ActuatorEntity (ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)5 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)4 ParticleEffectActuator (ilargia.egdx.logicbricks.component.actuator.ParticleEffectActuator)2 RadialGravityActuator (ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator)2 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)2 Vector2 (com.badlogic.gdx.math.Vector2)1 Body (com.badlogic.gdx.physics.box2d.Body)1 CameraActuator (ilargia.egdx.logicbricks.component.actuator.CameraActuator)1 Link (ilargia.egdx.logicbricks.component.actuator.Link)1 TextureActuator (ilargia.egdx.logicbricks.component.actuator.TextureActuator)1 VelocityActuator (ilargia.egdx.logicbricks.component.actuator.VelocityActuator)1 TextureView (ilargia.egdx.logicbricks.component.game.TextureView)1