Skip to content

Instantly share code, notes, and snippets.

@demetriusnunes
Forked from p7o/robot.js
Created December 10, 2012 20:53
Show Gist options
  • Save demetriusnunes/4253311 to your computer and use it in GitHub Desktop.
Save demetriusnunes/4253311 to your computer and use it in GitHub Desktop.
Gunkerzer
//FightCode can only understand your robot
//if its class is called Robot
var direction = 1;
var moveStep = 7;
var rotateStep = 1;
var initialized = false;
var noScanCount = 0;
var noScanLimit = 50;
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if(initialized){
if(direction == 1){
robot.ahead(moveStep);
robot.rotateCannon(-rotateStep);
}else{
robot.back(moveStep);
robot.rotateCannon(rotateStep);
}
robot.fire();
noScanCount ++;
if(noScanCount == noScanLimit){
initialized = false;
}
}else{
robot.rotateCannon(-rotateStep);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
initialized = true;
robot.fire();
noScanCount = 0;
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
//robot.turn(ev.bearing - 90);
direction *= -1;
};
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.rotateCannon(ev.bulletBearing);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
direction *= -1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment