At the moment 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.
The Flocking Algorithm - The Technical Bit:
The game uses the flocking algorithm to control the movement of fish within the game. Programmatically each fish has a 3 distances defined from it's centre, effectively making the three rings representing the 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 the position of a fish, its position is checked 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 execute, changing it's position, based on the other fish.
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 the others in their orientation and attraction zone.
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 perfectly 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 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.
Although this can't really be shown in a screenshot, I have tried my best in the above. The larger green fish represents the player and the blue fish represent the rest of the shoal. Something to bear in mind- the graphics on this screenshot are very much programmer art.
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 on the diagram below 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.