Skip to content

Instantly share code, notes, and snippets.

@diofeher
Forked from rafaelcaricio/robot.js
Created December 5, 2012 03:30
Show Gist options
  • Save diofeher/4211935 to your computer and use it in GitHub Desktop.
Save diofeher/4211935 to your computer and use it in GitHub Desktop.
Mother of Gods
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
robot.clone();
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
robot.rotateCannon(360);
robot.back(100);
robot.rotateCannon(360);
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
//robot.back(50);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.back(50);
robot.turn(15);
}
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var enemy = ev.scannedRobot;
var bFriendly = ( robot.parentId !=null && robot.parentId==enemy.id);
bFriendly |= (enemy.parentId !=null && enemy.parentId==robot.id);
if(!bFriendly) {
robot.fire();
robot.rotateCannon(3);
robot.rotateCannon(-30);
robot.fire();
robot.ahead(20);
robot.turn(10);
} else {
robot.ahead(30);
robot.turn(25);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment