Created
December 6, 2012 18:50
-
-
Save bltavares/4227030 to your computer and use it in GitHub Desktop.
Let it rain
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
var robotFound = false; | |
var direction = 1; | |
var Robot = function(robot) { | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if(!robotFound) { | |
robot.rotateCannon(1 * direction); | |
} | |
direction = direction * (Math.random() < 0.5 ? 1 : -1); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scanned = ev.scannedRobot; | |
robotFound = true; | |
if(robot.id !== scanned.parentId | |
|| robot.parentId !== scanned.id) { | |
robot.fire(); | |
} | |
robot.clone(); | |
var bla = Math.random() * 10; | |
robot.turn(bla); | |
robot.rotateCannon(-1 * bla); | |
robot.ahead(50); | |
robotFound = false; | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
robotFound = false; | |
robot.turn(ev.bearing - 90); | |
robot.ahead(100); | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(ev.bearing - 180); | |
robot.ahead(100); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment