Floqua is an Android and desktop game based on the flocking and social networking of animals such as birds and fish. It was created as part of a 9 week summer placement with the YCCSA at the University of York.

The game simulates a shoal of fish swimming around a tank, With one fish being user controlled. The user is shown an area, the size of their screen, of the game map which they can explore with their shoal.

Download Floqua from the Google Play Store

Technical Approach

When approaching the programming of this application I decided to use the LibGdx framework. LibGdx is a cross-platform development library based on OpenGL. I decided to use LibGdx as not only did it allow the game to be run both as a desktop application and an Android application, but also allowed for better performance, especially with an application that is likely to have a large number of moving sprites.

The Flocking Algorithm

The game uses the flocking algorithm to control the movement of the fish. Programmatically each fish has a 3 distances defined from it’s centre, effectively making three rings representing it’s repulsion, orientation and attraction zones.

The fish also has a cone of angles, defined as it’s viewing zone, the fish can only react to other fish within this cone. When changing position, a fish checks its position against the position of all other fish, if another fish is within one the fishes zone it’s position vector is added to the total for that zone. When a fish has analysed all other fish and their positions it can alter it’s position accordingly.

According to the algorithm the fish’s repulsion zone takes priority, this means that if another fish is within the repulsion zone the fish will move itself away, regardless of how many fish are within the orientation and attraction zone, this is reflected in the algorithm. If their are no other fish in the repulsion zone then the fish can react to those fish within it’s orientation and attraction zones.

In this game the user plays as one of the fish, the leader of the pack, obviously in order for the player to be controlling and moving a fish within the shoal the algorithm cannot be entirely accurately implemented. However I think I managed to get around this (relatively) elegantly by making the user controlled fish appear to all other fish as multiple fish i.e. the other fish are more heavily weighted towards the player, for example if the weighting was 10 the fish would act as if there were 10 fish moving in the same direction and from the same position as the player.

This is also useful as it means we can have fish that are specifically replelled from the player, making them harder to control.


Obstacles and Walls

I have added walls to the game at the perimeter of the background to prevent the fish from escaping, and obstacles within the game that the fish can’t pass through. The interaction between a fish and an obstacle/wall is similar to a bounce, where the relative component of the fish’s velocity is inverted. For example, if the fish were to hit the bottom edge of the tank, the Y-Component of the fish’s velocity would be inverted upon hitting the wall whilst the X-Component can remain the same. Once the fish is no-longer touching the wall it returns to executing the flocking algorithm.