Procedural Generation

This week I’ve done some procedural generation using cellular automata. This was for generating coral reef inside levels. The coral reef acts as another obstacle that the player must avoid touching. Here is a look at some of the outputs of the generation:

Both the foreground and background coral are procedurally generated

The background coral uses a different tile set and tile size

The generation can create interesting loops such at this some times

To begin I had to write a grid structure as I found out LibGDX didn’t have one included. After a little research on different ways to implement a grid, I choose to represent mine as an Array of Arrays, which although might not be that efficient, is pretty easy to implement and understand, so heres the grid class I came up with:

package com.me.mygdxgame;

import com.badlogic.gdx.utils.Array;

public class Grid {

private Array<Array<Boolean>> grid = new Array<Array<Boolean>>();
private int rows;
private int collums;

public Grid(int rows, int collums)
{
this.rows = rows;
this.collums = collums;

//populate the grid with false values
for (int i= 0; i < rows; i ++)
{
Array<Boolean> tempArray = new Array<Boolean>();
for (int j = 0; j < collums; j++)
{
tempArray.add(false);
}
grid.add(tempArray);
}
}

/**
* Used to get the value of a cell from the grid
* @param row the row of the cell
* @param collum the columns of the cell
* @return the value of the cell
*/
public boolean getTile(int row, int collum)
{
return grid.get(row).get(collum);
}

/**
* Used to set the value of a cell in the grid
* @param row the row of the cell
* @param collum the columns of the cell
* @param aBool the value of the cell
*/
public void setTile(int row, int collum, boolean aBool)
{
grid.get(row).set(collum, aBool);
}

/**
*
* @return the number of horizontal rows in the grid
*/
public int Rows()
{
return rows;
}

/**
*
* @return the number of vertical columns in the grid
*/
public int Columns()
{
return collums;
}

public void printGrid()
{
for (int i= 0; i < rows; i ++)
{
String aString = new String();
for (int j = 0; j < collums; j++)
{
if (getTile(i,j) == true)
{
aString = aString + "1";
}
else
{
aString = aString + "0";
}
}
System.out.println(aString);
}
}
}

Once I had the grid, I ported the code from a flash demo I made that created cave/caverns using cellular automata. From there I just spent some time playing around with the rules. The main rules are cells with less than 3 neighbour cells that are ‘alive’ will die that pass, and cells surrounded by 5 or more living cells become ‘alive’ if they aren’t already alive. I do 5 iterations of these rules before doing a few special rule sets at the end to help clean up situations such as 1*1 single living cells and to shape the coral a little better.

Once created each cell auto tiles by working out how many cells it is surrounded by and in what positions to determine which tile to use for itself. I use two layers of coral, one for the foreground that when touched ‘hurts’ the player, and the other is a background layer just for aesthetics. The background layer uses bigger size cells, so has less cells in its grid. As such I fill the gird with more noise to start, but besides that it generates using the same rules as the foreground cells, and just auto tiles using a different tile set.

I am pretty pleased with the results of the generation, and have additional rules in place to make levels generate with more coral in later levels to make them harder as you progress, which I feel works pretty well.

This week I am planning to think about the design of the game more, as I feel it is more tedious to play than it is fun to play, so I will try and think of ways to make the game more fun!

Volcanoes

So its Friday of week two, so I really can’t put off doing a blog now if I want to stick to a blog a week!

This week I have implemented volcanoes into the game. Lets take a look!

Just one volcano, shooting some lava balls

Things can get hectic fast with more than one volcano

So maybe the level generation could do with some tweaking…

Lava Balls work pretty similar to Jelly Fish. If your finger ‘touches’ one you get hurt. The main difference is the movement. Jelly Fish swim around minding there own business much like fish (in fact exactly the same as fish). Lava Balls however get launched out of a volcano when it erupts and shoots upwards. They then slowly lose momentum and provided the initial eruption wasn’t so powerful they got launched off the top of the screen, they will then fall back down to the sea bed.

Although functioning well on a basic level, Volcanoes and Lava Balls could still do with some polishing (steam particle coming out of volcano before an eruption). One small issue I am having is the Lava Ball sprite is stretched on some screens. This is peculiar as I haven’t had this problem with any of the other sprites, and it is using the exact same code (copy and paste!). I hope to mess around with them a bit longer to try and sort the problem out.

Anyway, that is all I managed to do last week, this week I hope to work on some procedurally generated coral reef!

Time to Blog!

Hello.

So after putting it off for some time I’ve decided I should really start blogging. The main focus of this blog will be on the development of projects I am working on, so lets begin!

For the last 2 months I have been working on an Android game which I am developing with LibGDX. I have never done any Android development before so I am basically just learning it as I go along, but so far it has been pretty smooth (I’ll probably regret saying that when I start testing the game on a more diverse range of devices!)

The games main mechanic is drawing squares on the screen to catch fish. There is more to the game than that, but I keep changing everything else constantly. Here are some screenshots so you at least have some idea what I am talking about:

Image

(Just some fish swimming around, touching the jelly fish hurts you)

Image

(Drawing a square to try and catch two blue fish at once)

Image

(This is the half developed crab mini game!)

Most the art is ‘borrowed’ at the moment, it will all be replaced with unique art at some point before release, but for now I am focusing on the development to ensure the game does actually get released!

Recently in development I was having trouble with the game crashing after clearing about 30 ‘waves’ of fish. It turns out it was actually the seaweed that was causing the crash. At the moment the seaweed is the only animated object in the game, and each seaweed object loads all the textures in the animation (bad idea really!). After each ‘wave’ the sea bed would generate a new floor with new seaweed objects in new positions. It seems that after 30 waves there were so many seaweed textures loaded the game crashed. I have fixed the issue by pooling seaweed objects (you can only ever see like 10 on the screen so no more than 10 need to be created) however I can probably further optimise the seaweeds and improve performance by loading the textures in the animation once, and just reusing it when drawing all the seaweeds, instead of having it loaded into memory 10 times which I am doing at the moment.

So next I’m going to do a little re-organisation and cleaning up of the code base and then start working on volcanoes! The plan is a blog a week, so shout at me if I don’t do that!