Search in sources :

Example 6 with GameEntity

use of ilargia.egdx.logicbricks.gen.game.GameEntity in project Entitas-Java by Rubentxu.

the class CreateNearSensorSystem method execute.

@Override
protected void execute(List<SensorEntity> entities) {
    for (SensorEntity e : entities) {
        GameEntity gameEntity = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
        RigidBody rigidBody = gameEntity.getRigidBody();
        NearSensor nearSensor = e.getNearSensor();
        if (nearSensor.distance > 0) {
            FixtureDef nearFixture = bodyBuilder.fixtureDefBuilder().circleShape(nearSensor.distance).sensor().build();
            rigidBody.body.createFixture(nearFixture).setUserData("NearSensor");
            if (nearSensor.resetDistance > nearSensor.distance) {
                FixtureDef nearResetFixture = bodyBuilder.fixtureDefBuilder().circleShape(nearSensor.resetDistance).sensor().build();
                rigidBody.body.createFixture(nearResetFixture).setUserData("ResetNearSensor");
            }
        }
    }
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) FixtureDef(com.badlogic.gdx.physics.box2d.FixtureDef) NearSensor(ilargia.egdx.logicbricks.component.sensor.NearSensor)

Example 7 with GameEntity

use of ilargia.egdx.logicbricks.gen.game.GameEntity in project Entitas-Java by Rubentxu.

the class Box method create.

@Override
public GameEntity create(Engine engine, Entitas entitas) {
    BodyBuilder bodyBuilder = engine.getManager(PhysicsManagerGDX.class).getBodyBuilder();
    float width = MathUtils.random(0.4f, 1);
    float height = MathUtils.random(0.4f, 1f);
    GameEntity entity = entitas.game.createEntity().setInteractive(true).addRigidBody(bodyBuilder.fixture(bodyBuilder.fixtureDefBuilder.boxShape(width, height).friction(0.5f).density(1f)).type(BodyDef.BodyType.DynamicBody).build()).addTextureView(new TextureRegion(assetsManager.getTexture(box2)), new Bounds(width, height), false, false, 1, 0, Color.WHITE);
    entitas.actuator.createEntity().addRadialGravityActuator(9, 5, 2).addLink(entity.getCreationIndex(), "RadialGravityActuator", true);
    return entity;
}
Also used : PhysicsManagerGDX(ilargia.egdx.impl.managers.PhysicsManagerGDX) GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Bounds(ilargia.egdx.logicbricks.data.Bounds) BodyBuilder(ilargia.egdx.util.BodyBuilder)

Example 8 with GameEntity

use of ilargia.egdx.logicbricks.gen.game.GameEntity in project Entitas-Java by Rubentxu.

the class Mariano method create.

@Override
public GameEntity create(Engine engine, Entitas entitas) {
    PhysicsManagerGDX physics = engine.getManager(PhysicsManagerGDX.class);
    BodyBuilder bodyBuilder = physics.getBodyBuilder();
    TextureAtlas textureAtlas = assetsManager.getTextureAtlas(atlas);
    ParticleEffect dustEffect = assetsManager.get(effect, ParticleEffect.class);
    Array<TextureAtlas.AtlasRegion> heroWalking = textureAtlas.findRegions("Andando");
    Array<TextureAtlas.AtlasRegion> heroJump = textureAtlas.findRegions("Saltando");
    Array<TextureAtlas.AtlasRegion> heroFall = textureAtlas.findRegions("Cayendo");
    Array<TextureAtlas.AtlasRegion> heroIdle = textureAtlas.findRegions("Parado");
    Map<String, Animation<TextureRegion>> animationStates = EntitasCollections.createMap(String.class, Animation.class);
    animationStates.put("walking", new Animation(0.02f, heroWalking, Animation.PlayMode.LOOP));
    animationStates.put("jump", new Animation(0.02f * 7, heroJump, Animation.PlayMode.NORMAL));
    animationStates.put("fall", new Animation(0.02f * 5, heroFall, Animation.PlayMode.NORMAL));
    animationStates.put("idle", new Animation(0.02f * 4, heroIdle, Animation.PlayMode.LOOP));
    Body bodyPlayer = bodyBuilder.fixture(bodyBuilder.fixtureDefBuilder().boxShape(0.35f, 1).density(1)).type(BodyDef.BodyType.DynamicBody).fixedRotation().position(0, 5).mass(1).build();
    GameEntity entity = entitas.game.createEntity();
    entity.addRigidBody(bodyPlayer).addAnimations(animationStates, animationStates.get("idle"), 0).addTags("Mariano").setInteractive(true).addTextureView(null, new Bounds(0.9f, 1.15f), false, false, 1, 1, Color.WHITE).addInputController((inputManager, context) -> {
        boolean isGround = false;
        SensorEntity sensor = Indexed.getSensorsEntity(entity, "CollisionGround");
        if (sensor.getCollisionSensor().collisionSignal)
            isGround = true;
        Vector2 impulse = new Vector2();
        if (inputManager.isKeyDown(Input.Keys.D)) {
            impulse.x = 2;
            if (isGround)
                entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("walking");
            entity.getTextureView().flipX = false;
        } else if (inputManager.isKeyDown(Input.Keys.A)) {
            impulse.x = -2;
            if (isGround)
                entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("walking");
            entity.getTextureView().flipX = true;
        }
        if (inputManager.isKeyDown(Input.Keys.W)) {
            if (isGround)
                impulse.y = 4;
            entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("jump");
        }
        Vector2 vel = bodyPlayer.getLinearVelocity();
        if (!inputManager.isKeyDown(Input.Keys.A) && !inputManager.isKeyDown(Input.Keys.D) && isGround) {
            bodyPlayer.setLinearVelocity(new Vector2(0, vel.y));
            entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("idle");
        }
        if (Math.abs(vel.x) > 7) {
            vel.x = Math.signum(vel.x) * 7;
            bodyPlayer.setLinearVelocity(new Vector2(vel.x, vel.y));
        }
        if (!isGround && vel.y < 0) {
            entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("fall");
        }
        bodyPlayer.applyLinearImpulse(impulse, bodyPlayer.getWorldCenter(), false);
    });
    entitas.sensor.createEntity().addCollisionSensor("Ground").addLink(entity.getCreationIndex(), "CollisionGround");
    entitas.actuator.createEntity().addCameraActuator(((EngineGDX) engine).getCamera(), (short) 0.3f, 0.08f, 6, 1, "Mariano").addLink(entity.getCreationIndex(), "CameraActuator", true);
    entitas.actuator.createEntity().addParticleEffectActuator(dustEffect, true, -1, -1).addLink(entity.getCreationIndex(), "EffectActuator", true);
    return entity;
}
Also used : Bounds(ilargia.egdx.logicbricks.data.Bounds) EngineGDX(ilargia.egdx.impl.EngineGDX) BodyBuilder(ilargia.egdx.util.BodyBuilder) PhysicsManagerGDX(ilargia.egdx.impl.managers.PhysicsManagerGDX) ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect) GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Animation(com.badlogic.gdx.graphics.g2d.Animation) Body(com.badlogic.gdx.physics.box2d.Body)

Example 9 with GameEntity

use of ilargia.egdx.logicbricks.gen.game.GameEntity in project Entitas-Java by Rubentxu.

the class ActuatorEntity method addParticleEffectActuator.

public ActuatorEntity addParticleEffectActuator(ParticleEffect effect, boolean autoStart, float locaPosX, float locaPosY) {
    ParticleEffectActuator component = (ParticleEffectActuator) recoverComponent(ActuatorComponentsLookup.ParticleEffectActuator);
    if (component == null) {
        component = new ParticleEffectActuator(effect, autoStart, locaPosX, locaPosY);
    } else {
        component.particleEffect = effect;
        component.actuator = (indexOwner) -> {
            GameEntity owner = Indexed.getInteractiveEntity(indexOwner);
            RigidBody rc = owner.getRigidBody();
            Transform transform = rc.body.getTransform();
            effect.setPosition(transform.getPosition().x + locaPosX, transform.getPosition().y + locaPosY);
            effect.update(Gdx.graphics.getDeltaTime());
            if (autoStart && effect.isComplete())
                effect.start();
        };
    }
    addComponent(ActuatorComponentsLookup.ParticleEffectActuator, component);
    return this;
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) ParticleEffectActuator(ilargia.egdx.logicbricks.component.actuator.ParticleEffectActuator) RigidBody(ilargia.egdx.logicbricks.component.game.RigidBody) Transform(com.badlogic.gdx.physics.box2d.Transform)

Example 10 with GameEntity

use of ilargia.egdx.logicbricks.gen.game.GameEntity in project Entitas-Java by Rubentxu.

the class ActuatorEntity method addTextureActuator.

public ActuatorEntity addTextureActuator(Bounds bounds, int opacity, Boolean flipX, Boolean flipY, Color tint) {
    TextureActuator component = (TextureActuator) recoverComponent(ActuatorComponentsLookup.TextureActuator);
    if (component == null) {
        component = new TextureActuator(bounds, opacity, flipX, flipY, tint);
    } else {
        component.actuator = (indexOwner) -> {
            GameEntity owner = Indexed.getInteractiveEntity(indexOwner);
            TextureView view = owner.getTextureView();
            if (bounds != null)
                view.bounds = bounds;
            if (flipX != null)
                view.flipX = flipX;
            if (flipY != null)
                view.flipY = flipY;
            if (opacity != -1)
                view.opacity = opacity;
            if (tint != null)
                view.tint = tint;
        };
    }
    addComponent(ActuatorComponentsLookup.TextureActuator, component);
    return this;
}
Also used : GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) TextureView(ilargia.egdx.logicbricks.component.game.TextureView) TextureActuator(ilargia.egdx.logicbricks.component.actuator.TextureActuator)

Aggregations

GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)27 RigidBody (ilargia.egdx.logicbricks.component.game.RigidBody)9 SensorEntity (ilargia.egdx.logicbricks.gen.sensor.SensorEntity)8 Vector2 (com.badlogic.gdx.math.Vector2)6 Body (com.badlogic.gdx.physics.box2d.Body)5 TextureView (ilargia.egdx.logicbricks.component.game.TextureView)5 Transform (com.badlogic.gdx.physics.box2d.Transform)4 ActuatorEntity (ilargia.egdx.logicbricks.gen.actuator.ActuatorEntity)4 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 Vector3 (com.badlogic.gdx.math.Vector3)3 ParticleEffectActuator (ilargia.egdx.logicbricks.component.actuator.ParticleEffectActuator)3 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)2 PhysicsManagerGDX (ilargia.egdx.impl.managers.PhysicsManagerGDX)2 CameraActuator (ilargia.egdx.logicbricks.component.actuator.CameraActuator)2 RadialGravityActuator (ilargia.egdx.logicbricks.component.actuator.RadialGravityActuator)2 TextureActuator (ilargia.egdx.logicbricks.component.actuator.TextureActuator)2 VelocityActuator (ilargia.egdx.logicbricks.component.actuator.VelocityActuator)2 NearSensor (ilargia.egdx.logicbricks.component.sensor.NearSensor)2 RadarSensor (ilargia.egdx.logicbricks.component.sensor.RadarSensor)2 Bounds (ilargia.egdx.logicbricks.data.Bounds)2