Skip to content

Instantly share code, notes, and snippets.

@longle255
Forked from cfsghost/robot.js
Created December 7, 2012 02:53
Show Gist options
  • Save longle255/4230350 to your computer and use it in GitHub Desktop.
Save longle255/4230350 to your computer and use it in GitHub Desktop.
Frextank
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
var self = this;
self.robot = robot;
self.members = {};
self.enemies = {};
robot.clone();
};
Robot.prototype.onIdle = function(ev) {
var self = this;
var robot = ev.robot;
// Initializing all tanks
if (!self.members[robot.id]) {
self.members[robot.id] = {
scanning: true
};
}
if (self.members[robot.id].scanning) {
robot.turn(30);
if (robot.id != self.robot.id)
robot.ahead(65);
else
robot.back(65);
robot.rotateCannon(15);
}
};
Robot.prototype.onHitByBullet = function(ev) {
var self = this;
var robot = ev.robot;
// run away right now
robot.stop();
robot.fire();
robot.turn(30);
if (robot.id != self.robot.id)
robot.ahead(200);
else
robot.back(200);
self.members[robot.id].scanning = true;
};
Robot.prototype.onScannedRobot = function(ev) {
var self = this;
var robot = ev.robot;
if (!self.members[ev.scannedRobot.id]) {
robot.stop();
robot.fire();
robot.rotateCannon(-15);
if (robot.id != self.robot.id) {
// Just go stright to Enemy, and kill it
if (robot.cannonRelativeAngle >= 355 &&
robot.cannonRelativeAngle >= 0 &&
robot.cannonRelativeAngle <= 5) {
robot.turn(-30);
}
robot.ahead(50);
} else {
// Just go stright to Enemy, and kill it
if (robot.cannonRelativeAngle >= 175 &&
robot.cannonRelativeAngle <= 85) {
robot.turn(-30);
}
robot.back(50);
}
}
self.enemies[ev.scannedRobot.id] = ev.scannedRobot;
};
Robot.prototype.onRobotCollision = function(ev) {
var self = this;
var robot = ev.robot;
if (robot.id != self.robot.id)
robot.back(200);
else
robot.ahead(200);
self.members[robot.id].scanning = true;
};
Robot.prototype.onWallCollision = function(ev) {
var self = this;
var robot = ev.robot;
if (robot.id != self.robot.id)
robot.back(300);
else
robot.ahead(300);
self.members[robot.id].scanning = true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment