Search in sources :

Example 1 with Position

use of com.ilargia.games.logicbrick.component.game.Position in project Entitas-Java by Rubentxu.

the class EntityIndexExtension method addEntityIndices.

public static void addEntityIndices(Entitas contexts) {
    EntityIndex<GameEntity, Integer> positionIndex = new EntityIndex(contexts.game.getGroup(GameMatcher.Position()), (e, c) -> {
        Position positionComponent = (Position) c;
        return positionComponent != null ? (positionComponent.x << shiftX) + positionComponent.y : (((GameEntity) e).getPosition().x << shiftX) + ((GameEntity) e).getPosition().y;
    });
    contexts.game.addEntityIndex(PositionKey, positionIndex);
}
Also used : GameEntity(com.ilargia.games.logicbrick.gen.game.GameEntity) Position(com.ilargia.games.logicbrick.component.game.Position) EntityIndex(com.ilargia.games.entitas.index.EntityIndex)

Example 2 with Position

use of com.ilargia.games.logicbrick.component.game.Position in project Entitas-Java by Rubentxu.

the class AnimatePositionSystem method execute.

@Override
public void execute(List<GameEntity> entities) {
    for (GameEntity e : entities) {
        Position pos = e.getPosition();
        //e.getTextureView().body.setTransform(new Vector2(0, -12), new Vector2(pos.x, pos.y - 1), true);
        moveFocused(new Vector2(pos.x, pos.y - 1), e.getTextureView().body);
    }
}
Also used : GameEntity(com.ilargia.games.logicbrick.gen.game.GameEntity) Position(com.ilargia.games.logicbrick.component.game.Position) Vector2(com.badlogic.gdx.math.Vector2)

Example 3 with Position

use of com.ilargia.games.logicbrick.component.game.Position in project Entitas-Java by Rubentxu.

the class GameEntity method addPosition.

public GameEntity addPosition(int x, int y) {
    Position component = (Position) recoverComponent(GameComponentsLookup.Position);
    if (component == null) {
        component = new Position(x, y);
    } else {
        component.x = x;
        ;
        component.y = y;
    }
    addComponent(GameComponentsLookup.Position, component);
    return this;
}
Also used : Position(com.ilargia.games.logicbrick.component.game.Position)

Example 4 with Position

use of com.ilargia.games.logicbrick.component.game.Position in project Entitas-Java by Rubentxu.

the class AddViewSystem method execute.

@Override
public void execute(List<GameEntity> entities) {
    for (GameEntity e : entities) {
        Texture texture = assetsManager.getTexture(String.format("assets/textures/%1$s.png", e.getAsset().name));
        Body body = bodyBuilder.fixture(new FixtureDefBuilder().boxShape(0.5f, 0.5f)).type(BodyDef.BodyType.KinematicBody).build();
        TextureRegion textureRegion = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight());
        e.addTextureView(e.getAsset().name, textureRegion, body);
        //
        if (e.hasPosition()) {
            Position pos = e.getPosition();
            body.setTransform(new Vector2(pos.x, pos.y + 1), 0);
        }
    }
}
Also used : GameEntity(com.ilargia.games.logicbrick.gen.game.GameEntity) FixtureDefBuilder(com.ilargia.games.entitas.egdx.base.util.FixtureDefBuilder) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Position(com.ilargia.games.logicbrick.component.game.Position) Vector2(com.badlogic.gdx.math.Vector2) Texture(com.badlogic.gdx.graphics.Texture) Body(com.badlogic.gdx.physics.box2d.Body)

Example 5 with Position

use of com.ilargia.games.logicbrick.component.game.Position in project Entitas-Java by Rubentxu.

the class GameEntity method replacePosition.

public GameEntity replacePosition(int x, int y) {
    Position component = (Position) recoverComponent(GameComponentsLookup.Position);
    if (component == null) {
        component = new Position(x, y);
    } else {
        component.x = x;
        ;
        component.y = y;
    }
    replaceComponent(GameComponentsLookup.Position, component);
    return this;
}
Also used : Position(com.ilargia.games.logicbrick.component.game.Position)

Aggregations

Position (com.ilargia.games.logicbrick.component.game.Position)5 GameEntity (com.ilargia.games.logicbrick.gen.game.GameEntity)3 Vector2 (com.badlogic.gdx.math.Vector2)2 Texture (com.badlogic.gdx.graphics.Texture)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Body (com.badlogic.gdx.physics.box2d.Body)1 FixtureDefBuilder (com.ilargia.games.entitas.egdx.base.util.FixtureDefBuilder)1 EntityIndex (com.ilargia.games.entitas.index.EntityIndex)1