Skip to content

Instantly share code, notes, and snippets.

@rfloriano
Forked from yetanotherportfolio/robot.js
Created December 10, 2012 17:50
Show Gist options
  • Save rfloriano/4252107 to your computer and use it in GitHub Desktop.
Save rfloriano/4252107 to your computer and use it in GitHub Desktop.
BoBot
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
var is_scanning = true;
var is_blocking = false;
var angleTarget = 0;
var lastTarget = [0,0];
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
var angle;
if (robot.availableClones > 0)
{
robot.clone();
}
if (is_blocking)
{
robot.turn(20);
robot.back(20);
is_blocking = false;
}
else
{
/*if (robot.parentId)
angle = 20;
else
angle = -20;
robot.turn(angle);*/
var sign;
if (robot.parentId)
{
sign = 1;
}
else
{
sign = -1;
}
robot.turn(20*sign);
robot.ahead(20);
if(is_scanning)
{
robot.rotateCannon(20*sign);
}
}
/*else
{
angle = robot.angle-angleTarget;
if (angle != 0)
{
robot.turn(-angle);
robot.rotateCannon(robot.angle-robot.cannonAbsoluteAngle+90);
}
robot.ahead(1);
is_scanning = true;
}*/
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing+90);
//robot.ahead(50);
is_blocking = true;
is_scanning = true;
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing+90);
//robot.ahead(50);
is_blocking = true;
is_scanning = true;
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing);
is_scanning = false;
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var otherBot = ev.scannedRobot;
if (otherBot.parentId != robot.id && otherBot.id != robot.parentId)
{
robot.fire();
//robot.back(120);
is_scanning = false;
angleTarget = robot.cannonAbsoluteAngle-90;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment