-
-
Save rafaelcaricio/4195533 to your computer and use it in GitHub Desktop.
Bartorista
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
function Robot(robot) {} | |
// well, we need to do something... | |
// whenever our robot is idle, this method gets called. | |
Robot.prototype.onIdle = function(ev) { | |
var robot; | |
robot = ev.robot; | |
robot.ahead(50); | |
robot.turn(90); | |
robot.rotateCannon(10); | |
robot.rotateCannon(-20); | |
robot.rotateCannon(10); | |
}; | |
// this method gets called whenever we hit another robot... | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
var collidedRobot = ev.collidedRobot; | |
if((robot.parentId == null && collidedRobot.parentId != robot.id)){ | |
robot.fire(); | |
}else if((robot.parentId != null && collidedRobot.id != robot.parentId)){ | |
robot.fire(); | |
} | |
}; | |
// this method gets called whenever we hit a wall... | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turnRight(ev.bearing + 90); | |
}; | |
// yay we see another robot! time to wreak some havoc... | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot; | |
var scannedRobot; | |
robot = ev.robot; | |
scannedRobot = ev.scannedRobot; | |
if((robot.parentId == null && scannedRobot.parentId != robot.id)){ | |
for (var i=0; i<5; i++) { | |
robot.fire(); | |
robot.ahead(10); | |
} | |
robot.clone(); | |
}else if((robot.parentId != null && scannedRobot.id != robot.parentId)){ | |
for (var i=0; i<5; i++) { | |
robot.fire(); | |
robot.ahead(10); | |
} | |
} | |
}; | |
// ohhh... we were hit by another robot... | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot; | |
robot = ev.robot; | |
robot.turn(90 - ev.bulletBearing); | |
robot.ahead(150); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment