Created
March 4, 2013 21:30
-
-
Save argyleink/5085848 to your computer and use it in GitHub Desktop.
My js robot
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) {}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
robot.ahead(20); | |
robot.rotateCannon(10); | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
ev.robot.turn(ev.bearing + 100); | |
} | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot, | |
loser = ev.scannedRobot, | |
foe = loser.id != robot.id && loser.id != robot.parentId; | |
if(!loser.parentId && foe) { | |
robot.fire(); | |
robot.rotateCannon(-25); | |
} | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
robot.clone(); | |
if (robot.life < 40) | |
robot.disappear(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment