Created
December 4, 2012 22:06
-
-
Save dlomibao/4209329 to your computer and use it in GitHub Desktop.
Shaking Cannon II
This file contains hidden or 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
//states | |
var clone=false; | |
var found=false; | |
var shots=0; | |
var hits=0; | |
//FightCode can only understand your robot | |
//if its class is called Robot | |
var Robot = function(robot) { | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if(robot.availableClones>0){ | |
robot.clone(); | |
clone=true; | |
robot.turn(60); | |
robot.ahead(100); | |
} | |
if(robot.parentId!=null){//original code | |
robot.ahead(50); | |
robot.rotateCannon(90); | |
} | |
else{//clone code | |
robot.back(50); | |
robot.rotateCannon(-90); | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var sr = ev.scannedRobot; | |
var bFriendly = ( robot.parentId !=null && robot.parentId==sr.id); | |
bFriendly |= ( sr.parentId !=null && sr.parentId==robot.id); | |
if(bFriendly){ | |
} | |
else | |
{ | |
if(robot.parentId!=null){//original code | |
robot.fire(); | |
robot.rotateCannon(-30) | |
robot.fire(); | |
robot.rotateCannon(3); | |
robot.fire(); | |
} | |
else{//clone code | |
robot.fire(); | |
robot.rotateCannon(-30); | |
robot.fire(); | |
robot.rotateCannon(3); | |
robot.fire(); | |
} | |
} | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(ev.bearing); // turn enought to be in a straight | |
robot.turn(90); | |
robot.back(100); | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
if(robot.parentId!=null){ | |
robot.turn(45); | |
robot.back(100); | |
}else{ | |
robot.turn(-45); | |
robot.ahead(100); | |
} | |
// trying to run away | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment