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 & this.children.length==0 & this.parent == -1){
+
if(this.isComputer && this.children.length==0 && this.parent == -1){
 
spawnAIComputer();
 
spawnAIComputer();
 
}
 
}
Line 213: Line 213:
 
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 & this.isTouching(substrates[i])){
+
if(substrates[i].object!=undefined && this.isTouching(substrates[i])){
 
this.luminescence += SUBSTRATEVALUE;
 
this.luminescence += SUBSTRATEVALUE;
 
if(this.luminescence > MAXLUMINANCE){
 
if(this.luminescence > MAXLUMINANCE){
Line 229: Line 229:
 
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 & this.isTouching(foods[i])){
+
if(foods[i].object!=undefined && this.isTouching(foods[i])){
 
this.resize(this.radius+foods[i].radius/2);
 
this.resize(this.radius+foods[i].radius/2);
 
foods[i].destroy();
 
foods[i].destroy();
Line 245: Line 245:
 
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]) & this.distance(curCell.children[j])<this.radius){
+
if(this.isTouching(curCell.children[j]) && this.distance(curCell.children[j])<this.radius){
 
if(curCell.children[j].radius<this.radius*EATINGRATIO){
 
if(curCell.children[j].radius<this.radius*EATINGRATIO){
 
ateSomething = true;
 
ateSomething = true;
Line 253: Line 253:
 
}
 
}
 
}
 
}
if(this.isTouching(curCell) & this.distance(curCell)<this.radius){
+
if(this.isTouching(curCell) && this.distance(curCell)<this.radius){
 
if(curCell.radius<this.radius*EATINGRATIO){
 
if(curCell.radius<this.radius*EATINGRATIO){
 
ateSomething = true;
 
ateSomething = true;
Line 271: Line 271:
 
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 & this.radius>spikes[i].radius*1.5 & this.isTouching(spikes[i])){
+
if(spikes[i].object!=undefined && this.radius>spikes[i].radius*1.5 && this.isTouching(spikes[i])){
 
this.split();
 
this.split();
 
spikes[i].destroy();
 
spikes[i].destroy();
Line 325: Line 325:
 
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 &&
curCell.children[j].radius<this.radius*EATINGRATIO & this.distance(curCell.children[j])<sight){
+
curCell.children[j].radius<this.radius*EATINGRATIO && this.distance(curCell.children[j])<sight){
 
prey = curCell.children[j];
 
prey = curCell.children[j];
 
sight = this.distance(prey);
 
sight = this.distance(prey);
Line 333: Line 333:
 
}
 
}
 
if(curCell != this){
 
if(curCell != this){
if(curCell.object!=undefined & curCell.radius<this.radius*EATINGRATIO & this.distance(curCell)<sight){
+
if(curCell.object!=undefined && curCell.radius<this.radius*EATINGRATIO && this.distance(curCell)<sight){
 
prey = curCell;
 
prey = curCell;
 
sight = this.distance(prey);
 
sight = this.distance(prey);
Line 339: Line 339:
 
}
 
}
 
}
 
}
if(curCell.object!=undefined & curCell.size*EATINGRATIO>this.size & this.distance(curCell)<this.radius*5){ //this cell can eat me and is close
+
if(curCell.object!=undefined && curCell.size*EATINGRATIO>this.size && 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]];
 
var difference = [curCell.center[0]-this.center[0],curCell.center[1]-this.center[1]];
 
gottaRun[0] += difference[0];
 
gottaRun[0] += difference[0];
Line 361: Line 361:
 
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 & this.distance(curFood)<sight){
+
if(curFood!=undefined && this.distance(curFood)<sight){
 
food = curFood;
 
food = curFood;
 
sight = this.distance(curFood);
 
sight = this.distance(curFood);
Line 380: Line 380:
 
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 & this.distance(curSubstrate)<sight){
+
if(curSubstrate!=undefined && this.distance(curSubstrate)<sight){
 
substrate = curSubstrate;
 
substrate = curSubstrate;
 
sight = this.distance(curSubstrate);
 
sight = this.distance(curSubstrate);
Line 703: Line 703:
 
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 & computer.object!=undefined){
+
if(computer!=undefined && computer.object!=undefined){
 
computer.enemyMovementAI();
 
computer.enemyMovementAI();
 
}
 
}
Line 828: Line 828:
 
}
 
}
 
 
function main(){
+
function game(){
 
//make border and boundaries;
 
//make border and boundaries;
 
var gameWrapper = document.getElementById("gameWrapper");
 
var gameWrapper = document.getElementById("gameWrapper");
Line 859: Line 859:
  
 
<body>
 
<body>
<div id="gameWrapper" onclick="main();" style="width:400px; height:400px; position:absolute; background-color:MidnightBlue;overflow:hidden;border-style:outset;border-width:10px;border-color:green"/>
+
<div id="gameWrapper" onclick="game();" style="width:400px; height:400px; position:absolute; background-color:MidnightBlue;overflow:hidden;border-style:outset;border-width:10px;border-color:green"/>
 
</body>
 
</body>
  
 
</html>
 
</html>

Revision as of 14:13, 29 June 2015

Luciferase: The Game