Created
December 8, 2012 16:12
-
-
Save p7o/4240860 to your computer and use it in GitHub Desktop.
Gunkerzer
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
//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