Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Forked from mdonahoo/robot.js
Created December 4, 2012 22:28
Show Gist options
  • Save yitsushi/4209560 to your computer and use it in GitHub Desktop.
Save yitsushi/4209560 to your computer and use it in GitHub Desktop.
Folyam2
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {};
var target = null;
var intelAge = 0;
var cloned = false;
var pointAt = function(robot, enemy)
{
var my = robot.position;
var opp = my.y - enemy.y;
var adj = my.x - enemy.x;
var angle = Math.atan2(opp, adj) * 180 / Math.PI;
if(angle < 0) angle += 360;
var myAngle = robot.cannonAbsoluteAngle;
var diff = angle - myAngle;
if(diff > 180) diff -= 360;
if(diff < -180) diff += 360;
robot.rotateCannon(diff);
}
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (!cloned && robot.parentId == null) {
cloned = true;
robot.clone();
robot.turn(30);
robot.ahead(100);
}
intelAge += 1;
if(intelAge > 3)
{
target = null;
}
if(!target)
{
robot.rotateCannon(-30);
}
else
{
pointAt(ev.robot, target);
robot.fire();
robot.fire();
robot.fire();
}
robot.turn(-13);
robot.ahead(23);
};
Robot.prototype.onScannedRobot = function(ev) {
if (ev.scannedRobot.id != ev.robot.parentId
&& ev.robot.id != ev.scannedRobot.parentId) {
target = ev.scannedRobot.position;
intelAge = 0;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment