-
-
Save yitsushi/4209560 to your computer and use it in GitHub Desktop.
Folyam2
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 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