Search in sources :

Example 1 with BodyBuilder

use of ilargia.egdx.util.BodyBuilder in project Entitas-Java by Rubentxu.

the class GameSceneState method loadResources.

@Override
public void loadResources() {
    this.skinManager = engine.getManager(SMGUIManager.class);
    this.assetsManager = engine.getManager(BaseAssetsManager.class);
    guiFactory = new GuiFactory(assetsManager, skin);
    bodyBuilder = new BodyBuilder();
    this.stage = new Stage();
    stage.clear();
    stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
    Gdx.input.setInputProcessor(stage);
    Gdx.app.log("Menu", "LoadResources");
    assetsManager.loadTextureAtlas(SPRITE_ATLAS);
    assetsManager.finishLoading();
}
Also used : Stage(com.badlogic.gdx.scenes.scene2d.Stage) GuiFactory(games.states.game.utils.GuiFactory) SMGUIManager(games.manager.SMGUIManager) BaseAssetsManager(com.ilargia.games.entitas.egdx.base.managers.BaseAssetsManager) BodyBuilder(ilargia.egdx.util.BodyBuilder)

Example 2 with BodyBuilder

use of ilargia.egdx.util.BodyBuilder 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 3 with BodyBuilder

use of ilargia.egdx.util.BodyBuilder 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 4 with BodyBuilder

use of ilargia.egdx.util.BodyBuilder in project Entitas-Java by Rubentxu.

the class GameSceneState method loadResources.

@Override
public void loadResources() {
    this.skinManager = engine.getManager(SMGUIManager.class);
    this.assetsManager = engine.getManager(BaseAssetsManager.class);
    guiFactory = new GuiFactory(assetsManager, skin);
    bodyBuilder = new BodyBuilder();
    this.stage = new Stage();
    stage.clear();
    stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
    Gdx.input.setInputProcessor(stage);
    Gdx.app.log("Menu", "LoadResources");
    assetsManager.loadTextureAtlas(SPRITE_ATLAS);
    assetsManager.finishLoading();
}
Also used : Stage(com.badlogic.gdx.scenes.scene2d.Stage) GuiFactory(games.utils.GuiFactory) SMGUIManager(games.manager.SMGUIManager) BaseAssetsManager(com.ilargia.games.entitas.egdx.base.managers.BaseAssetsManager) BodyBuilder(ilargia.egdx.util.BodyBuilder)

Example 5 with BodyBuilder

use of ilargia.egdx.util.BodyBuilder in project Entitas-Java by Rubentxu.

the class Block method create.

@Override
public GameEntity create(Engine engine, Context<GameEntity> context) {
    BasePhysicsManager physics = engine.getManager(BasePhysicsManager.class);
    BodyBuilder bodyBuilder = physics.getBodyBuilder();
    Body bodyBlock = bodyBuilder.fixture(new FixtureDefBuilder().boxShape(1, 1).friction(0.5f).restitution(0.5f)).type(BodyDef.BodyType.StaticBody).build();
    GameEntity entity = context.createEntity().addRigidBody(bodyBlock).addElement("Platform", "Block");
    return entity;
}
Also used : FixtureDefBuilder(ilargia.egdx.util.FixtureDefBuilder) GameEntity(com.indignado.games.states.game.gen.GameEntity) BasePhysicsManager(com.ilargia.games.entitas.egdx.base.managers.BasePhysicsManager) BodyBuilder(ilargia.egdx.util.BodyBuilder) Body(com.badlogic.gdx.physics.box2d.Body)

Aggregations

BodyBuilder (ilargia.egdx.util.BodyBuilder)10 Body (com.badlogic.gdx.physics.box2d.Body)7 BasePhysicsManager (com.ilargia.games.entitas.egdx.base.managers.BasePhysicsManager)6 GameEntity (com.indignado.games.states.game.gen.GameEntity)6 FixtureDefBuilder (ilargia.egdx.util.FixtureDefBuilder)4 Animation (com.badlogic.gdx.graphics.g2d.Animation)2 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)2 Stage (com.badlogic.gdx.scenes.scene2d.Stage)2 BaseAssetsManager (com.ilargia.games.entitas.egdx.base.managers.BaseAssetsManager)2 GameContext (com.indignado.games.states.game.gen.GameContext)2 SMGUIManager (games.manager.SMGUIManager)2 PhysicsManagerGDX (ilargia.egdx.impl.managers.PhysicsManagerGDX)2 Bounds (ilargia.egdx.logicbricks.data.Bounds)2 GameEntity (ilargia.egdx.logicbricks.gen.game.GameEntity)2 ParticleEffect (com.badlogic.gdx.graphics.g2d.ParticleEffect)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Bounds (com.ilargia.games.logicbrick.data.Bounds)1 Bounds (com.indignado.games.states.game.data.Bounds)1 GuiFactory (games.states.game.utils.GuiFactory)1