Created
December 4, 2012 16:48
-
-
Save folkien/4206067 to your computer and use it in GitHub Desktop.
Folkien PUS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var start; | |
//FightCode can only understand your robot | |
//if its class is called Robot | |
var Robot = function(robot) { | |
robot.clone(); | |
start = 0; | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if( !robot.parentId ) { | |
robot.turnLeft(36); | |
} else { | |
if (!start){ | |
robot.ahead(150); | |
start = 1; | |
} | |
robot.turnRight(36); | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var wrog = ev.scannedRobot; | |
var i; | |
if ((wrog.id == robot.parentId) ||(wrog.parentId == robot.id)) { | |
return; | |
} | |
robot.fire(); | |
if(!robot.parentId) { | |
robot.rotateCannon(30); | |
}else { | |
robot.rotateCannon(-30); | |
} | |
robot.ahead(10); | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
var wrog = ev.colidedRobot; | |
if ((wrog.id == robot.parentId) ||(wrog.parentId == robot.id)) { | |
if(robot.parentId) { | |
robot.ahead(10); | |
} else { | |
robot.back(10); | |
} | |
} else { | |
var i ; | |
for (i=0;i<3;i++) { | |
robot.fire(); | |
robot.back(10); | |
} | |
} | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(ev.bearing+180); // turn enought to be in a straight | |
// angle with the wall. | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
robot.turn(40); | |
robot.rotateCannon(-40); | |
for(i=0;i<4;i++) { | |
robot.ahead(15); | |
robot.fire(); | |
} | |
// so we can see who shot it | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment