Created
December 7, 2012 12:32
-
-
Save LouWii/4232993 to your computer and use it in GitHub Desktop.
YouCannotLoose
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
//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; | |
robot.clone(); | |
if (robot.parentId==null) | |
{ | |
robot.ahead(30); | |
robot.turn(3); | |
robot.rotateCannon(-20); | |
} | |
else | |
{ | |
robot.turn(45); | |
robot.ahead(30); | |
robot.rotateCannon(20); | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scanned = ev.scannedRobot; | |
if (scanned.id !== robot.parentId && scanned.parentId !== robot.id) | |
{ | |
var i = 0; | |
while (i!=3) | |
{ | |
robot.fire(); | |
robot.ahead(30); | |
robot.fire(); | |
robot.back(30); | |
i++; | |
} | |
robot.ahead(20); | |
} | |
}; | |
// this method gets called whenever we hit another robot... | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(45); | |
robot.ahead(40); | |
}; | |
// this method gets called whenever we hit a wall... | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(-20); | |
robot.ahead(10); | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
//robot.turn(ev.bearing); // Turn to wherever the bullet was fired | |
// so we can see who shot it | |
var i = 0; | |
while (i!=10) | |
{ | |
robot.turn(-5); | |
robot.ahead(40); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment