LibGDX Mobile Game

So for the last few months I have been working on a small mobile game. I had to stop using Marmalade because I was unable to get a student licence and my trial expired. Because of this I have decided to moved back to LibGDX which actually supports iOS now. The process of getting a LibGDX game onto iOS seems a little daunting but I will give it a try anyways when the game is more complete. Anyways, here are some screen shots of what I’m working on:

Inside a cave

Inside a cave

Some spinning obstacles

Some spinning obstacles

A mine field

A mine field

The graphics are being created by Liam Bower. The game is basically a helicopter style game with extra features such as different areas, power ups and a shop. We hope to have it finished pretty soon, although it has already taken much longer than originally anticipated.

One interesting problem I had to work on recently was generating caves with smooth walls like in the first and second screen shot. Before smoothing the wall generation, the walls were generated in square blocks, and actually still are. What I do is convert the top and bottom blocks on the walls into two triangles.One triangle using the center point on the top edge of the block, the center point on the top edge of the next block, and its x and y position to draw a triangle. Then the other triangle just draws to fill in the rest of the block. This picture should help illustrate whats happening:

Debug drawing of triangles

Debug drawing of triangles

The results of this method are good, however it is probably more process intensive than it needs to be, and finding ways to optimize it will be something I will need to look into. One solution could be generating ‘height map’ like structures, and then using the triangles to draw from the edge of the screen to the tip point of the map. This will remove the drawing of all the boxes under the triangles as the triangles would create the entire terrain. Generating the terrain in wider sections will lower the number of triangles being drawn at once too.

The progress of the game is going good, with almost all the main features already programmed into the game, but there is still quite a lot of work to do before we can call it finished and release it…

Been awhile

So oops, I haven’t blogged in about 2 months! But there is good reasons:


Firstly, I started a 12 month work placement at Canalside Studios back in September which has made me much more busy. I am currently working as part of a small team at the studio creating a mobile game using Marmalade. Although I have only been at the studio a short period, less than 3 months, I have already learnt a great deal. One of the areas I have learnt the most in so far is C++, as Marmalade is a cross platform SDK written in C++. The game is still in pretty early stages but so far the team seems pretty excited about what we’re creating! Hopefully it’ll turn out good.

In a slightly related note, I have also been working on my own little Engine/Frame Work for Marmalade. When we began our current project we created our own engine at the studio, however I am interested in trying my hand at creating some small mobile games in my own time so have decided to create my own engine based on what I’ve learned so far. The main reason for switching to Marmalade, over say, just continuing with LibGDX is because Marmalade works on iOS , Android and a whole array of other devices. So far my engine is in pretty early stages but check out all these crabs:

This does unfortunately mean I have stopped working on the Fish Game I was making in LibGDX. After learning about basic game engine structure working at the studio, it made me realize what a complete mess the code was. Also, the game just wasn’t very fun!

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!