Created
December 4, 2012 01:11
-
-
Save joshstrange/4199615 to your computer and use it in GitHub Desktop.
Hal
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 Robot = function(robot) { | |
var self = this; | |
var self.seenRobots = {}; | |
self.aim = function(robot, target) { | |
console.log('My: '+robot.position.x+','+robot.position.y); | |
console.log('Target: '+target.position.x); | |
console.log('Angle'+robot.cannonAbsoluteAngle) | |
} | |
self.recordRobot(robot) { | |
if(robot.parentId) | |
{ | |
if(self.seenRobots[robot.parentId]) | |
{ | |
self.seenRobots[robot.parentId].children[] | |
} | |
} | |
else | |
{ | |
self.seenRobots | |
} | |
} | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
robot.rotateCannon(360); | |
}; | |
// this method gets called whenever we hit another robot... | |
Robot.prototype.onRobotCollision = function(ev) {}; | |
// this method gets called whenever we hit a wall... | |
Robot.prototype.onWallCollision = function(ev) {}; | |
// yay we see another robot! time to wreak some havoc... | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
this.aim(robot, ev.scannedRobot); | |
robot.fire(); | |
}; | |
// ohhh... we were hit by another robot... | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot; | |
robot = ev.robot; | |
robot.turn(90 - ev.bulletBearing); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment