Search in sources :

Example 1 with GameEntity

use of com.ilargia.games.logicbrick.gen.game.GameEntity 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 GameEntity

use of com.ilargia.games.logicbrick.gen.game.GameEntity 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 GameEntity

use of com.ilargia.games.logicbrick.gen.game.GameEntity in project Entitas-Java by Rubentxu.

the class ProcessInputSystem method execute.

@Override
protected void execute(List<InputEntity> entities) {
    InputEntity inputEntity = entities.get(0);
    Input input = inputEntity.getInput();
    Set<GameEntity> interactives = EntityIndexExtension.getEntitiesWithPosition(entitas.game, input.x, input.y).stream().filter(e -> e.isInteractive()).collect(Collectors.toSet());
    for (GameEntity e : interactives) {
        e.setDestroy(true);
    }
}
Also used : Collector(com.ilargia.games.entitas.collector.Collector) List(java.util.List) GameEntity(com.ilargia.games.logicbrick.gen.game.GameEntity) Input(com.ilargia.games.logicbrick.component.input.Input) IContext(com.ilargia.games.entitas.api.IContext) InputEntity(com.ilargia.games.logicbrick.gen.input.InputEntity) InputMatcher(com.ilargia.games.logicbrick.gen.input.InputMatcher) Set(java.util.Set) EntityIndexExtension(com.ilargia.games.entitas.EntityIndexExtension) Entitas(com.ilargia.games.entitas.core.Entitas) InputContext(com.ilargia.games.logicbrick.gen.input.InputContext) Collectors(java.util.stream.Collectors) GameEntity(com.ilargia.games.logicbrick.gen.game.GameEntity) Input(com.ilargia.games.logicbrick.component.input.Input) InputEntity(com.ilargia.games.logicbrick.gen.input.InputEntity)

Example 4 with GameEntity

use of com.ilargia.games.logicbrick.gen.game.GameEntity in project Entitas-Java by Rubentxu.

the class RemoveViewSystem method execute.

@Override
protected void execute(List<GameEntity> entities) {
    for (GameEntity e : entities) {
        destroyView(e.getTextureView());
        e.removeTextureView();
    }
}
Also used : GameEntity(com.ilargia.games.logicbrick.gen.game.GameEntity)

Example 5 with GameEntity

use of com.ilargia.games.logicbrick.gen.game.GameEntity 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)

Aggregations

GameEntity (com.ilargia.games.logicbrick.gen.game.GameEntity)5 Position (com.ilargia.games.logicbrick.component.game.Position)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 EntityIndexExtension (com.ilargia.games.entitas.EntityIndexExtension)1 IContext (com.ilargia.games.entitas.api.IContext)1 Collector (com.ilargia.games.entitas.collector.Collector)1 Entitas (com.ilargia.games.entitas.core.Entitas)1 FixtureDefBuilder (com.ilargia.games.entitas.egdx.base.util.FixtureDefBuilder)1 EntityIndex (com.ilargia.games.entitas.index.EntityIndex)1 Input (com.ilargia.games.logicbrick.component.input.Input)1 InputContext (com.ilargia.games.logicbrick.gen.input.InputContext)1 InputEntity (com.ilargia.games.logicbrick.gen.input.InputEntity)1 InputMatcher (com.ilargia.games.logicbrick.gen.input.InputMatcher)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1