Last active
December 11, 2015 05:38
-
-
Save sivartydrup/4553404 to your computer and use it in GitHub Desktop.
Next iteration
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.rotateCannon(90); | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
ev.robot.clone(); | |
if (ev.robot.parentId !== null) { | |
ev.robot.turn(90); | |
ev.robot.rotateCannon(3); | |
ev.robot.rotateCannon(30); | |
} | |
ev.robot.ahead(1000); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
if(ev.scannedRobot.id !== ev.robot.parentId && ev.scannedRobot.parentId !== ev.robot.id) { | |
ev.robot.fire(1); | |
if (ev.robot.parentId !== null) { | |
ev.robot.rotateCannon(-10); | |
ev.robot.rotateCannon(-10); | |
} | |
} | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
if (ev.robot.parentId == null) { | |
ev.robot.turn(ev.bearing + 90); | |
} | |
else { | |
ev.robot.back(100); | |
ev.robot.rotateCannon(-180); | |
ev.robot.turn(ev.bearing + 150); | |
} | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
ev.robot.back(100); | |
ev.robot.turn(90); | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
if (ev.robot.parentId !== null) { | |
ev.robot.turn(90 - ev.bulletBearing); | |
} | |
else | |
{ | |
ev.robot.turn(90 - (ev.bulletBearing*2)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment