Wednesday, 4 November 2009

IDAT204 - Behind the Digital Organism Part 2

So like i said previously im just going through my Digital Organism, now im going through some of the difficult parts of the coding, well might not seem difficult to you, but it was to me.

The first part i had a problem with was the random number generator, we needed our program to produce a random number every time the food reset, so that it would randomally place along the "x" axis. This is how we did it.


The second part i had problems with was the collision detection, not only did it need to know that the food had hit something, it also needed to do a number of other things. This is the code we used to get around it.


The third & final main problem i had was with the evolving part of the organism. Not only did it need to run a check to see what state the organism was, it also needed to make the hit square from above grow as the organism grew, so here's the code.