5.14.05
Here's the chunk of code that governs the above:
var spacer:Number = 5;
var gridCount:Number = 28;
var collisionThreshold:Number = 3;
var jumpRange:Number = 3;
bumpSound = new Sound();
bumpSound.attachSound("bump");
bumpSound.setVolume(5);
function layoutElements(gridCount) {
for(i=1; i<=gridCount; i++) {
for(j=1; j<=gridCount; j++) {
_root.attachMovie("element", ["element_" + i + "_" + j], _root.getNextHighestDepth());
_root["element_" + i + "_" + j]._x = (_root["element_" + i + "_" + j]._width + _root.spacer) * i;
_root["element_" + i + "_" + j]._y = (_root["element_" + i + "_" + j]._height + _root.spacer) * j;
}
}
}
layoutElements(_root.gridCount);
var xGrid1:Number = gridCount / 2;
var yGrid1:Number = gridCount / 2;
var xGrid2:Number = gridCount / 2;
var yGrid2:Number = gridCount / 2;
var xGrid3:Number = gridCount / 2;
var yGrid3:Number = gridCount / 2;
_root.onEnterFrame = function() {
direction1 = Math.round(Math.random() * 4);
var inc1:Number = Math.round(Math.random()*_root.jumpRange);
switch (direction1) {
case 1:
xGrid1 = Math.abs((xGrid1 + inc1) % _root.gridCount);
break;
case 2:
yGrid1 = Math.abs((yGrid1 + inc1) % _root.gridCount);
break;
case 3:
xGrid1 = Math.abs((xGrid1 - inc1) % _root.gridCount);
break;
default:
yGrid1 = Math.abs((yGrid1 - inc1) % _root.gridCount);
}
direction2 = Math.round(Math.random() * 4);
var inc2:Number = Math.round(Math.random()*_root.jumpRange);
switch (direction2) {
case 1:
xGrid2 = Math.abs((xGrid2 + inc2) % _root.gridCount);
break;
case 2:
yGrid2 = Math.abs((yGrid2 + inc2) % _root.gridCount);
break;
case 3:
xGrid2 = Math.abs((xGrid2 - inc2) % _root.gridCount);
break;
default:
yGrid2 = Math.abs((yGrid2 - inc2) % _root.gridCount);
}
_root["element_"+ xGrid1 +"_" + yGrid1].gotoAndPlay("flash");
_root["element_"+ xGrid2 +"_" + yGrid2].gotoAndPlay("flash");
_root["element_"+ xGrid3 +"_" + yGrid3].gotoAndPlay("flash");
if((Math.abs(xGrid1-xGrid2) <= _root.collisionThreshold) and (Math.abs(yGrid1-yGrid2) <= _root.collisionThreshold)) {
_root["element_"+ xGrid1 +"_" + yGrid1].gotoAndPlay("flash2");
_root["element_"+ xGrid2 +"_" + yGrid2].gotoAndPlay("flash2");
if(bumpSound.getVolume() < 100) {
bumpSound.setVolume(bumpSound.getVolume() + 5);
}
bumpSound.start();
}
if(bumpSound.getVolume() > 5){
bumpSound.setVolume(bumpSound.getVolume() - 3);
}
}
stop();
|