Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lil Red Biotch
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.foundFirstWall=false;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if(robot.parentId !== null){
robot.turn(1);
robot.rotateCannon(1);
robot.ahead(1);
}else{
robot.ahead(1);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scanBot=ev.scannedRobot;
if(scanBot.id !== robot.parentId && scanBot.parentId !== robot.id) {
var distance=this.distToPoint(robot.position,scanBot.position);
robot.fire();
if(distance<300){
if(robot.cannonRelativeAngle!==90){
robot.rotateCannon(-90);
}
robot.turn(90);
robot.fire();
for(var i=0;i<40;i++){
robot.ahead(5);
robot.fire();
}
}
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
var self=this;
robot.turn(ev.bearing);
if(robot.cannonRelativeAngle==90){
robot.rotateCannon(90);
}
if(this.foundFirstWall==false){
robot.clone();
robot.turn(90);
this.foundFirstWall=true;
}else{
robot.turn(90);
}
};
Robot.prototype.onRobotCollision=function(ev){
var robot=ev.robot;
robot.back(50);
};
Robot.prototype.angleToPoint=function(mePos,newPos){
var xDiff=mePos.x-newPos.x;
var yDiff=mePos.y-newPos.y;
var rads=Math.atan2(-yDiff,xDiff);
return rads*(180 / Math.PI);
}
Robot.prototype.distToPoint=function(mePos,newPos){
var xDiff=mePos.x-newPos.x;
var yDiff=mePos.y-newPos.y;
var hyp=Math.sqrt(Math.pow(yDiff,2)+Math.pow(xDiff,2));
return hyp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment