Created
December 5, 2012 22:52
-
-
Save leandromoreira/4220235 to your computer and use it in GitHub Desktop.
dreampeppers99
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 Robot = function(robot) { | |
}; | |
var firstTime = true; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
var moveAhead = Math.floor(Math.random()*101); | |
robot.ahead(moveAhead); | |
robot.turn(35); | |
robot.ahead(moveAhead); | |
robot.turn(36); | |
robot.ahead(69); | |
if (firstTime) { | |
robot.clone(); | |
firstTime = false; | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scannedRobot = ev.scannedRobot; | |
if (scannedRobot.parentId !== robot.id || | |
robot.id !== scannedRobot.parentId){ | |
robot.ahead(50); | |
robot.fire(); | |
robot.ahead(50); | |
robot.fire(); | |
} | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(20); | |
robot.ahead(100); // trying to run away | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(20); | |
robot.ahead(100); | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
robot.turn(ev.bearing); | |
robot.ahead(100); | |
robot.clone(233); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment