Skip to content

Instantly share code, notes, and snippets.

@andrestc
Created December 2, 2012 15:08
Show Gist options
  • Save andrestc/4189255 to your computer and use it in GitHub Desktop.
Save andrestc/4189255 to your computer and use it in GitHub Desktop.
Robotnik
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot;
robot = ev.robot;
robot.ahead(150);
robot.rotateCannon(360);
robot.back(100);
robot.rotateCannon(360);
robot.turn(20);
};
// this method gets called whenever we hit another robot...
Robot.prototype.onRobotCollision = function(ev) {
var robot;
robot = ev.robot;
robot.back(100);
robot.rotateCannon(360);
robot.turn(20);
};
// this method gets called whenever we hit a wall...
Robot.prototype.onWallCollision = function(ev) {
var robot;
robot = ev.robot;
robot.turn(180);
};
// yay we see another robot! time to wreak some havoc...
Robot.prototype.onScannedRobot = function(ev) {
var robot;
var enemy;
robot = ev.robot;
robot.fire(1);
robot.ahead(50);
};
// ohhh... we were hit by another robot...
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.turn(ev.bearing);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment