Created
December 6, 2012 16:09
-
-
Save floralvikings/4225643 to your computer and use it in GitHub Desktop.
LooperBot 1.0.1
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
var forward = true; | |
var rotateClockwise = true; | |
var turnClockwise = true; | |
// This corrects the cannon's rotation when turning. Slows the bot considerably when turning, consider carefully. | |
var correctCannonForTurning = true; | |
var attackClone = false; | |
var moveSpeed = 3; | |
var rotateSpeed = 2; | |
var turnSpeed = 0; | |
var scanning = true; | |
var scanAngle = 30; | |
var scannedClockwise = 0; | |
var scannedCounterclockwise = 0; | |
var startedScanClockwise = true; | |
var spotted = false; | |
var spottedAngle; | |
var Robot = function(robot) | |
{ | |
}; | |
Robot.prototype.onIdle = function(ev) | |
{ | |
var robot = ev.robot; | |
move(ev); | |
rotate(ev); | |
turn(ev); | |
if(scanning) | |
scan(ev); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) | |
{ | |
ev.robot.fire(); | |
turnSpeed = 0; | |
if(!attackClone && ev.parentID!=null) | |
return; | |
spotted = true; | |
spottedAngle = ev.robot.cannonAbsoluteAngle; | |
startedScanClockwise = rotateClockwise; | |
scannedClockwise = 0; | |
scannedCounterclockwise = 0; | |
}; | |
Robot.prototype.onRobotCollision = function(ev) | |
{ | |
forward = !(forward); | |
}; | |
Robot.prototype.onWallCollision = function(ev) | |
{ | |
forward = !(forward); | |
}; | |
Robot.prototype.onHitByBullet = function(ev) | |
{ | |
turnSpeed = 1; | |
forward = !(forward); | |
}; | |
function move(ev) | |
{ | |
if(forward) | |
ev.robot.ahead(moveSpeed); | |
else | |
ev.robot.back(moveSpeed); | |
}; | |
function rotate(ev) | |
{ | |
if(rotateClockwise) | |
ev.robot.rotateCannon(rotateSpeed); | |
else | |
ev.robot.rotateCannon(-rotateSpeed); | |
}; | |
function turn(ev) | |
{ | |
if(turnClockwise) | |
ev.robot.turn(turnSpeed); | |
else | |
ev.robot.turn(-turnSpeed); | |
if(!correctCannonForTurning) | |
return; | |
if(turnClockwise) | |
ev.robot.rotateCannon(-turnSpeed); | |
else | |
ev.robot.rotateCannon(turnSpeed); | |
}; | |
function scan(ev) | |
{ | |
if(!spotted) | |
{ | |
return; | |
} | |
if(rotateClockwise) | |
{ | |
scannedClockwise++; | |
}else{ | |
scannedCounterclockwise++; | |
} | |
if(scannedClockwise>=scanAngle && scannedCounterclockwise>=scanAngle) | |
{ | |
spotted = false; | |
scannedClockwise = 0; | |
scannedCounterclockwise = 0; | |
return; | |
} | |
if(startedScanClockwise && scannedClockwise>=(scanAngle/2)) | |
{ | |
rotateClockwise = false; | |
if(scannedCounterclockwise >= scanAngle) | |
rotateClockwise = true; | |
}else if(!startedScanClockwise && scannedCounterclockwise>=(scanAngle/2)) | |
{ | |
rotateClockwise = true; | |
if(scannedClockwise >= scanAngle) | |
rotateClockwise = false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment