Poor man’s level editor

Welcome to my first blog post. I’ll use it to present you my ongoing progress on my different games. The new game I’m working on is a god game for mobile.
For now its name is ‘monolith‘ but it’s not definitive yet. The game is in isometric 2d (or 2.5d) and will strongly rely on physics and AI.

I decided to go with the LibGdx framework since it’s easily available on a bunch of platforms, free, open-source and I had some experience using it with my previous game project.
For the assets I use the cool and free tiles from Kenney as placeholders, so I have something that doesn’t look too bad for a prototype.

 

 

So far I worked on world generation and level building. Since I’m too lazy to code an actual level editor, I used a bmp file as a map, with colors representing the different type of tiles.
In code it all boils down to my class called WorldFactory :

public WorldFactory(World world) {
    loadPixmap();
    readTilesFromPixmap();
    setTilesContext();
    createWorldGraphics();
    createWorldPhysics(world);
}

With the following function simply being :

private void readTilesFromPixmap() {
    final int worldW = pixmap.getWidth();
    final int worldH = pixmap.getHeight();

    tiles = new Tile[worldW][worldH];
    for (int y = 0; y < worldH; y++) {
        for (int x = 0; x < worldW; x++) {
            final int pixel = pixmap.getPixel(x, y);
            tiles[x][y] = new Tile(Tile.fromRGB(pixel));
        }
    }
}

And that’s what it looks like to create a world !

create_map
Editing in gimp
proof_map
Testing in the engine

 

EDIT : As asked in the comment, here is an example of how the Tile.fromRGB() function may be implemented

 

public static Type fromRGB(int rgbValue) {
    tmpColor = new Color(rgbValue);
    if (tmpColor.g == 1) {
        return Type.HILL;
    } else if (tmpColor.b == 1) {
        return Type.WATER;
    } else if (tmpColor == Color.WHITE) {
        return Type.HOUSE;
    } else {
        return Type.GRASS;
    }
}

4 thoughts on “Poor man’s level editor

  1. Hi!

    Are you planning to share your code? I’m wondering what your Tile.fromRGB looks like.

    Good job on a fun project!

    Christian

    Like

  2. I don’t plan on sharing the whole project, but I edited my article to add an example of Tile.fromRGB() implementation ;).

    It’s really basic, but gets the job done.

    Like

    1. Thanks!

      I was imagining something along those lines, but I mostly wanted to check whether it was your own or from libgdx. I checked that API and didn’t find anything, so I came back here 🙂

      Quick suggestion: you might find it helps your code readability (and debuggability) if anything that returns a Tile Type actually be named in a way that says so. For example, changing the Type type name to TileType would make things unambiguous. If your codebase is small and personal, you might disagree, but I believe it can help you in the long run.

      As a further explanation, when I read ‘Tile.fromRGB’ I thought ‘ok, that must return a Tile, since only those words appear there’. Now that I know your method, I know that it returns an enum type. Quite different! If the method was called typeFromRGB, I might have guessed sooner, and possibly even not needed to see the fromRGB method. Anyway, I’m just sharing in case it helps – I know you might have your own ideas about that 🙂

      Have fun with your project!

      Like

Leave a comment