Search in sources :

Example 6 with Entity

use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.

the class GameScene method tick.

@Override
public void tick(float delta) {
    if (campaign.hasFinished()) {
        SceneManager.exit();
        return;
    }
    if (!paused) {
        // Tick, tock - the campaign is just a clock...
        campaign.tick(delta);
        // Prepare views for rendering and level initialization
        if (views == null) {
            final Level level = campaign.getCurrentLevel();
            views = new LinkedList<>();
            for (Player player : campaign.players) {
                if (!(player instanceof LocalPlayer))
                    continue;
                final View view = new View(level);
                view.setTarget(player.createEntity(level).getComponent(Position.class).xy());
                views.add(view);
            }
            // Update viewports
            update(true);
        }
        // Player movement
        int mx = 0, my = 0;
        if (InputManager.isPressed(Key.MOVE_LEFT))
            mx--;
        if (InputManager.isPressed(Key.MOVE_RIGHT))
            mx++;
        if (InputManager.isPressed(Key.MOVE_UP))
            my++;
        if (InputManager.isPressed(Key.MOVE_DOWN))
            my--;
        for (Entity player : campaign.getCurrentLevel().players) {
            Entities.velocity.get(player).add(mx << 2, my << 2);
        }
    }
    // Open the windows to see what's happening!
    getBatch().begin();
    for (View view : views) {
        view.render(this);
    }
    getBatch().end();
    // Just some overlays
    super.tick(delta);
}
Also used : Entity(com.badlogic.ashley.core.Entity) LocalPlayer(net.catacombsnatch.game.player.LocalPlayer) Player(net.catacombsnatch.game.player.Player) LocalPlayer(net.catacombsnatch.game.player.LocalPlayer) Level(net.catacombsnatch.game.world.level.Level) View(net.catacombsnatch.game.world.level.View)

Example 7 with Entity

use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.

the class MiniMap method render.

@Override
public void render(Scene scene) {
    sprite.draw(scene.getBatch());
    vp.set(view.getViewport());
    vp.x += view.offset.x;
    vp.y += view.offset.y;
    for (int x = 0; x < level.width; x++) {
        for (int y = 0; y < level.height; y++) {
            final Entity tile = level.getTile(x, y);
            if (tile == null) {
                continue;
            }
            final MiniMapObject icon = Entities.miniMap.get(tile);
            if (icon != null) {
            // TODO add entity icons
            //        for (Entity tile : level.getTiles()) {
            //            if (tile == null) continue;
            //
            //            float px = sprite.getX() + 7f;
            //            px += 2 * (int)((tile.getPosition().x - (vp.x / Tile.WIDTH) + (vp.width / 2f / Tile.WIDTH)));
            //            float py = sprite.getY() + 7f;
            //            py += 2 * (int)((-tile.getPosition().y + (vp.height / Tile.HEIGHT) - (vp.y / Tile.HEIGHT) - (vp.height / 2f / Tile.HEIGHT)));
            //
            //            if (px >= sprite.getX() + 7f && py >= sprite.getY() + 7f &&
            //                    px < sprite.getX() + 82f && py < sprite.getY() + 82f) {
            //                int color = tile.getMinimapColor();
            //                scene.getSpriteBatch().setColor(
            //                        ((color & 0xff000000) >>> 24) / 255f,
            //                        ((color & 0x00ff0000) >>> 16) / 255f,
            //                        ((color & 0x0000ff00) >>> 8) / 255f,
            //                        1f);
            //                scene.getSpriteBatch().draw(pixel, px, py, 2f, 2f);
            //            }
            //        }
            }
        }
    }
    scene.getSpriteBatch().setColor(1f, 1f, 1f, 1f);
}
Also used : Entity(com.badlogic.ashley.core.Entity) MiniMapObject(net.catacombsnatch.game.entity.components.MiniMapObject)

Example 8 with Entity

use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.

the class DestroyableWallTile method createFor.

@Override
public Entity createFor(Level level, final int x, final int y) {
    final Entity tile = Entities.createTile(level, x, y, color, Art.tiles_walls[0], true);
    tile.add(new Destroyable().add(new Destroyable.Callback() {

        @Override
        public void onEntityDestroyed(Level level, Entity entity) {
            Tiles.createAndAdd(Tiles.FLOOR, level, x, y);
        }
    }));
    return tile;
}
Also used : Entity(com.badlogic.ashley.core.Entity) Destroyable(net.catacombsnatch.game.entity.components.Destroyable) Level(net.catacombsnatch.game.world.level.Level)

Example 9 with Entity

use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.

the class Tiles method createAndAdd.

public static Entity createAndAdd(String name, Level level, int x, int y) {
    final Entity tile = create(name, level, x, y);
    level.setTile(tile, x, y);
    return tile;
}
Also used : Entity(com.badlogic.ashley.core.Entity)

Example 10 with Entity

use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.

the class WallTile method createFor.

@Override
public Entity createFor(Level level, int x, int y) {
    final Entity tile = Entities.createTile(level, x, y, color, textures, true);
    tile.add(new BoundingBox().set(x, y, Tiles.SIZE));
    return tile;
}
Also used : Entity(com.badlogic.ashley.core.Entity) BoundingBox(net.catacombsnatch.game.entity.components.BoundingBox)

Aggregations

Entity (com.badlogic.ashley.core.Entity)11 BoundingBox (net.catacombsnatch.game.entity.components.BoundingBox)2 Level (net.catacombsnatch.game.world.level.Level)2 Destroyable (net.catacombsnatch.game.entity.components.Destroyable)1 MiniMapObject (net.catacombsnatch.game.entity.components.MiniMapObject)1 LocalPlayer (net.catacombsnatch.game.player.LocalPlayer)1 Player (net.catacombsnatch.game.player.Player)1 View (net.catacombsnatch.game.world.level.View)1