Infinite pseudo - procedural generation in Slick2D Infinite Sidescroller

by Hill   Last Updated May 11, 2017 15:13 PM

This is my first game project, which I am working on with a friend. We currently have a window that display 32 tiles wide and 18 tiles high. We want to switch to a procedural generation, where we have a set of maps "chunks" that are randomly loaded onto the end of an ArrayList or something. Currently, the camera scrolls to the right as you try to move right (you can move halfway across the map before it begins to scroll), and if you try to move to the left, it will not scroll (think Mario).

I am basically unsure how to go about implementing this. The level that is displayed on the screen at any given time should be a maximum of 5 "chunks" (they are 8 wide each. So there could be a max of 5 different chunks showing at any given time). What I'd like to have is a system where as you move right, new chunks are added onto an ArrayList, and after the far right tile of a map is no longer rendered, it be dropped from the ArrayList. I'm just looking for a lead in the right direction.

All I have at the moment is in our Level class, the following method which will be called by the Constructor:

    public void initProceduralTiles()throws SlickException{
    for(int i = 0; i < 5; i++){
        TiledMap newMap = new TiledMap("data/levels/promap" + rng.nextInt(6) + 1 + ".tmx");

I need to find a way to make our array that holds the tiles be capable of handling all of the tiles as they move (I think this array only needs to be updated when a new chunk is loaded. If I am correct, this would need to be 40 wide to accommodate 5 chunks.), I need to be able to detect when a chunk is no longer rendered so it can be removed. And then I will somehow need to adapt collision to work with this.

Until now, we have been using a static map that does not change, which is all displayed at once (yes this is borrowed):

public void initTiles() {
    tiles = new Tile[currentMap.getWidth()][currentMap.getHeight()];

    int layerIndex = currentMap.getLayerIndex("SmashLayer");
    if (layerIndex == -1) {
        System.err.println("Map is missing the \"SmashLayer\" layer. Please add one to handle collisions.");

    for (int x = 0; x < currentMap.getWidth(); x++) {
        for (int y = 0; y < currentMap.getHeight(); y++) {

            int tileID = currentMap.getTileId(x, y, layerIndex);

            Tile loader = null;
            switch (currentMap.getTileProperty(tileID, "blocked", "true")) {
            case "false":
                loader = new OpenTile(x, y);
            case "true":
                loader = new ClosedTile(x, y);
                System.out.println("CLOSED TILE");
                loader = new ClosedTile(x, y);
            tiles[x][y] = loader;


Thanks for any help you can provide!

Related Questions

Handling (spawning/removing) entities in SFML

Updated April 16, 2015 00:05 AM

How to make my Diamond-Square-algorithm less 'random'?

Updated December 03, 2016 08:05 AM

2D Infinite scrolling terrain on two axes

Updated May 18, 2017 14:13 PM