Created
December 6, 2012 21:59
-
-
Save bltavares/4228885 to your computer and use it in GitHub Desktop.
Pink warrior
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 robotFound = {"one" : false | |
,"two": false}; | |
var splited = false; | |
var Robot = function(robot) { | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
var direction = 1; | |
var number = (robot.parentId ? "two" : "one"); | |
if(number == "two"){ | |
direction = -1; | |
if(!splited){ | |
robot.turn(Math.random() * 100); | |
robot.ahead(20); | |
splited = true; | |
} | |
} | |
if(!robotFound[number]) { | |
robot.rotateCannon(1 * direction); | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scanned = ev.scannedRobot; | |
var number = (robot.parentId ? "two" : "one"); | |
robotFound[number] = true; | |
if(!(robot.id == scanned.parentId | |
|| | |
robot.parentId == scanned.id)) { | |
robot.fire(); | |
} | |
robot.clone(); | |
var bla = Math.random() * 10; | |
robot.turn(bla); | |
robot.rotateCannon(-1 * bla); | |
robot.ahead(50); | |
robotFound[number] = false; | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
robot.turn(ev.bearing - 90); | |
robot.ahead(100); | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(ev.bearing - 180); | |
robot.ahead(100); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment