Skip to content

Instantly share code, notes, and snippets.

@mdonahoo
Forked from gabrielgarciagava/robot.js
Created December 4, 2012 22:30
Show Gist options
  • Save mdonahoo/4209576 to your computer and use it in GitHub Desktop.
Save mdonahoo/4209576 to your computer and use it in GitHub Desktop.
RoboTosco
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
robot.clone();
};
var girar = 1;
var count = 0;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if(girar == 1){
robot.rotateCannon(90);
robot.turn(120);
girar = 0;
}else{
robot.ahead(5);
robot.turn(2);
robot.rotateCannon(3);
count += 1;
if(count == 90){
count = 0;
girar = 1;
}
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
if(!(ev.scannedRobot.parentId == robot.id) && !(ev.scannedRobot.id == robot.parentId)){
robot.fire();
robot.gunCoolDownTime = 0;
robot.rotateCannon(-25);
}
};
Robot.prototype.onWallCollision = function(ev) {
robot.back(30);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.turn(15);
robot.ahead(90);
robot.rotateCannon(ev.bearing); // Turn to wherever the bullet was fired
// so we can see who shot it
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment