Created
December 7, 2012 13:06
-
-
Save p7o/4233174 to your computer and use it in GitHub Desktop.
DevStator
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 rotateStep = 50; | |
var turnStep = 25; | |
var goStep = 20; | |
var scanned = false; | |
var scannedPosition; | |
var scannedAngle; | |
var rotateLast = 0; | |
var shootLimit = 4; | |
var shootCounter = 0; | |
var hitCounter = 0; | |
var hitLimit = 2; | |
var Robot = function(robot) { | |
//robot.clone(); | |
}; | |
function rotateLeft(robot){ | |
robot.rotateCannon(-rotateStep); | |
} | |
function rotateRight(robot){ | |
robot.rotateCannon(rotateStep); | |
} | |
function turnLeft(robot){ | |
robot.turn(-turnStep); | |
} | |
function turnRight(robot){ | |
robot.turn(turnStep); | |
} | |
function goForward(robot){ | |
robot.ahead(goStep); | |
} | |
function goBack(robot){ | |
robot.back(goStep); | |
} | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if(!scanned){ | |
robot.ahead(30); | |
robot.turn(70); | |
robot.back(30); | |
}else{ | |
shootCounter++; | |
if(rotateLast == 0){ | |
rotateLeft(robot); | |
turnRight(robot); | |
goBack(robot); | |
rotateLast = 1; | |
}else{ | |
rotateRight(robot); | |
goForward(robot); | |
turnLeft(robot); | |
rotateLast = 0; | |
} | |
if(shootCounter == shootLimit){ | |
scanned = false; | |
} | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scannedRobot = ev.scannedRobot; | |
if(robot.parentId == scannedRobot.id ){ | |
}else if(robot.id == scannedRobot.parentId){ | |
}else{ | |
robot.fire(10); | |
scanned = true; | |
shootCounter = 0; | |
} | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
hitCounter ++; | |
if(hitCounter == hitLimit){ | |
//robot.clone(); | |
} | |
//robot.clone(); | |
robot.ahead(100); | |
robot.turn(ev.bearing); | |
robot.fire(10); | |
robot.ahead(50); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment