Difference between revisions of "Team:Carnegie Mellon/game"
Line 167: | Line 167: | ||
if(this.object==undefined){ return;} | if(this.object==undefined){ return;} | ||
− | if(this.isComputer | + | if(this.isComputer){ |
− | + | if(this.children.length==0){ | |
+ | if(this.parent == -1){ | ||
+ | spawnAIComputer(); | ||
+ | } | ||
+ | } | ||
} | } | ||
Line 213: | Line 217: | ||
var substrates = Substrate.GetSubstrates(); | var substrates = Substrate.GetSubstrates(); | ||
for(var i=0;i<substrates.length;i++){ | for(var i=0;i<substrates.length;i++){ | ||
− | if(substrates[i].object!=undefined | + | if(substrates[i].object!=undefined){ |
− | + | if(this.isTouching(substrates[i])){ | |
− | + | this.luminescence += SUBSTRATEVALUE; | |
− | + | if(this.luminescence > MAXLUMINANCE){ | |
+ | this.luminescence = MAXLUMINANCE; | ||
+ | } | ||
+ | substrates[i].destroy(); | ||
} | } | ||
− | |||
} | } | ||
} | } | ||
Line 229: | Line 235: | ||
var foods = Food.GetFood(); | var foods = Food.GetFood(); | ||
for(var i=0;i<foods.length;i++){ | for(var i=0;i<foods.length;i++){ | ||
− | if(foods[i].object!=undefined | + | if(foods[i].object!=undefined){ |
− | + | if(this.isTouching(foods[i])){ | |
− | + | this.resize(this.radius+foods[i].radius/2); | |
+ | foods[i].destroy(); | ||
+ | } | ||
} | } | ||
} | } | ||
Line 245: | Line 253: | ||
if(curCell.object!=undefined){ | if(curCell.object!=undefined){ | ||
for(var j=0;j<curCell.children;j++){ | for(var j=0;j<curCell.children;j++){ | ||
− | if(this.isTouching(curCell.children[j]) | + | if(this.isTouching(curCell.children[j])){ |
− | + | if(this.distance(curCell.children[j])<this.radius){ | |
− | + | if(curCell.children[j].radius<this.radius*EATINGRATIO){ | |
− | + | ateSomething = true; | |
− | + | this.resize(this.radius+curCell.children[j]/2); | |
+ | curCell.children[j].destroy(); | ||
+ | } | ||
} | } | ||
} | } | ||
} | } | ||
− | if(this.isTouching(curCell) | + | if(this.isTouching(curCell)){ |
− | + | if(this.distance(curCell)<this.radius){ | |
− | + | if(curCell.radius<this.radius*EATINGRATIO){ | |
− | + | ateSomething = true; | |
− | + | this.resize(this.radius+curCell.radius/2); | |
+ | curCell.destroy(); | ||
+ | } | ||
} | } | ||
} | } | ||
Line 271: | Line 283: | ||
var spikes = Spike.GetSpikes(); | var spikes = Spike.GetSpikes(); | ||
for(var i=0;i<spikes.length;i++){ | for(var i=0;i<spikes.length;i++){ | ||
− | if(spikes[i].object!=undefined | + | if(spikes[i].object!=undefined){ |
− | + | if(this.radius>spikes[i].radius*1.5){ | |
− | + | if(this.isTouching(spikes[i])){ | |
− | + | this.split(); | |
+ | spikes[i].destroy(); | ||
+ | break; | ||
+ | } | ||
+ | } | ||
} | } | ||
} | } | ||
Line 325: | Line 341: | ||
for(var j=0;j<curCell.children.length;j++){ | for(var j=0;j<curCell.children.length;j++){ | ||
if(curCell.children[j] != this){ | if(curCell.children[j] != this){ | ||
− | if(curCell.children[j].object!=undefined | + | if(curCell.children[j].object!=undefined){ |
− | + | if(curCell.children[j].radius<this.radius*EATINGRATIO){ | |
− | + | if(this.distance(curCell.children[j])<sight){ | |
− | + | prey = curCell.children[j]; | |
+ | sight = this.distance(prey); | ||
+ | } | ||
+ | } | ||
} | } | ||
} | } | ||
} | } | ||
if(curCell != this){ | if(curCell != this){ | ||
− | if(curCell.object!=undefined | + | if(curCell.object!=undefined){ |
− | + | if(curCell.radius<this.radius*EATINGRATIO){ | |
− | + | if(this.distance(curCell)<sight){ | |
+ | prey = curCell; | ||
+ | sight = this.distance(prey); | ||
+ | } | ||
+ | } | ||
} | } | ||
} | } | ||
} | } | ||
− | if(curCell.object!=undefined | + | if(curCell.object!=undefined){ |
− | + | if(curCell.size*EATINGRATIO>this.size){ | |
− | + | if(this.distance(curCell)<this.radius*5){ //this cell can eat me and is close | |
− | + | var difference = [curCell.center[0]-this.center[0],curCell.center[1]-this.center[1]]; | |
+ | gottaRun[0] += difference[0]; | ||
+ | gottRun[0] += difference[1]; | ||
+ | } | ||
+ | } | ||
} | } | ||
} | } | ||
Line 361: | Line 388: | ||
if(sight>proximity){ //if something is in proximity do immediately (else look for better) | if(sight>proximity){ //if something is in proximity do immediately (else look for better) | ||
var curFood = foods[i]; | var curFood = foods[i]; | ||
− | if(curFood!=undefined | + | if(curFood!=undefined){ |
− | + | if(this.distance(curFood)<sight){ | |
− | + | food = curFood; | |
+ | sight = this.distance(curFood); | ||
+ | } | ||
} | } | ||
} | } | ||
Line 380: | Line 409: | ||
if(sight>proximity){ //if something is in proximity do immediately (else look for better) | if(sight>proximity){ //if something is in proximity do immediately (else look for better) | ||
var curSubstrate = substrates[i]; | var curSubstrate = substrates[i]; | ||
− | if(curSubstrate!=undefined | + | if(curSubstrate!=undefined){ |
− | + | if(this.distance(curSubstrate)<sight){ | |
− | + | substrate = curSubstrate; | |
+ | sight = this.distance(curSubstrate); | ||
+ | } | ||
} | } | ||
} | } | ||
Line 703: | Line 734: | ||
for(var i=0;i<_computers.length;i++){ | for(var i=0;i<_computers.length;i++){ | ||
var computer = _computers[i]; | var computer = _computers[i]; | ||
− | if(computer!=undefined | + | if(computer!=undefined){ |
− | + | if(computer.object!=undefined){ | |
+ | computer.enemyMovementAI(); | ||
+ | } | ||
} | } | ||
} | } |
Revision as of 14:21, 29 June 2015