Created
December 3, 2012 19:59
-
-
Save mdonahoo/4197579 to your computer and use it in GitHub Desktop.
WALL GRABBER
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 northAngle = 360; | |
var westAngle = 90; | |
var southAngle = 180; | |
var eastAngle = 270; | |
var turnedNorth = false; | |
var turnedWest = false; | |
var turnedEast = false; | |
var turnedSouth = false; | |
var stopRotating = false; | |
var minRotation = 0; | |
var maxRotation = 0; | |
var cannonRotation = 10; | |
var movementSpeed = 100; | |
var turningSpeed = 40; | |
//FightCode can only understand your robot | |
//if its class is called Robot | |
var Robot = function(robot) { | |
//turnNorth(robot); | |
// rotate 90 degress | |
//robot.rotateCannon(90); | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
moveFoward(robot); | |
turn(robot); | |
scanForTargets(robot); | |
}; | |
function cloneRobot(r) { | |
r.clone(); | |
} | |
function scanForTargets(r) { | |
r.rotateCannon(cannonRotation); | |
} | |
function moveFoward(r) { | |
r.ahead(movementSpeed); | |
} | |
function turn(r) { | |
r.turn(turningSpeed); | |
} | |
function moveFoward(r, move) { | |
r.ahead(move); | |
} | |
function turnSouth(r) { | |
r.turn(southAngle - r.angle); | |
turnedSouth = true; | |
} | |
function turnNorth(r) { | |
r.turn(northAngle - r.angle); | |
turnedNorth = true; | |
} | |
function turnWest(r) { | |
r.turn(westAngle - r.angle); | |
turnedWest = true; | |
} | |
function turnEast(r) { | |
r.turn(eastAngle - r.angle); | |
turnedEast = true; | |
} | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scannedRobot = ev.scannedRobot; | |
if(scannedRobot.parentId == null) | |
{ | |
// seek and destroy | |
robot.fire(); | |
} | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(90); // turn enought to be in a straight | |
minRotation = robot.angle; | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot; | |
robot = ev.robot; | |
// evasive manuvers | |
cloneRobot(robot); | |
evasiveManuverAlpha(robot); | |
}; | |
function evasiveManuverAlpha(r) { | |
r.ahead(300); | |
r.turn(30); | |
r.ahead(50); | |
r.turn(-50); | |
r.back(40); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment