each germ below is programmed to randomly move around. on the event that one germ absorbs another, the story changes. once a germ begins to grow, it’s movement and behavior changes from random movement to a power-hungry frenzy. each growing germ will constantly seek out smaller germs and attempt to kill them for their own power.
ok so it’s a sort of “programmed” intelligence that i set for them, but hey, as long as we have the space to write thousands of if and else statements, we can program these things to do whatever we want based on any current condition.
its nothing too fancy. i won’t post up the entire source until i’ve cleaned it up, but here is the heart of the entire thing:
stage.addEventListener(Event.ENTER_FRAME,collisionDetect);
function collisionDetect(e:Event):void {
trace(stage.numChildren);
for(i=0; i<=numOfClips-1; i++) {
var squareA = clips[i];
for(j=i+1; j<numOfClips; j++) {
var squareB = clips[j];
if(squareA.notRemoved == 1 && squareB.notRemoved == 1) {
if(squareA.hitTestObject(squareB)) {
Tweener.removeTweens(squareB);
Tweener.removeTweens(squareA);
if(squareA.power>squareB.power || squareA.power==squareB.power){
removeChild(squareB);
movement(clips[i],1);
squareA.notRemoved = 1;
squareB.notRemoved = 0;
delete(squareB);
squareA.mover.play();
squareA.power += 1;
} else if(squareA.power<squareB.power){
removeChild(squareA);
movement(clips[j],1);
squareA.notRemoved = 0;
squareB.notRemoved = 1;
delete(squareA);
squareB.mover.play();
squareB.power += 1;
} else if(squareA.power==squareB.power){
}
}
}
}
}
}
you can download the swf file here
Related posts: