-
-
Save folkien/4208782 to your computer and use it in GitHub Desktop.
Fight me if u can?
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
var direction; | |
var start; | |
//FightCode can only understand your robot | |
//if its class is called Robot | |
var Robot = function(robot) { | |
direction = 1; | |
start = 0; | |
robot.clone(); | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if (!start) { | |
if(robot.parentId){ | |
robot.ahead(50); | |
robot.turnLeft(45); | |
} | |
else { | |
robot.turnRight(45); | |
} | |
start = 1; | |
} | |
robot.ahead(10); | |
robot.rotateCannon(20 * direction); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var i = 0; | |
if ((ev.scannedRobot.parentId == robot.id)||(ev.scannedRobot.id == robot.parentId)) { | |
robot.turn(15); | |
} else { | |
//Gdy szefunio | |
direction = (ev.bearing>0) ? 1 : -1; | |
for(i=0;i<5;i++) { | |
robot.fire(); | |
robot.ahead(1); | |
robot.fire(); | |
} | |
robot.rotateCannon(-20*direction); | |
} | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(90-(ev.bearing)); // turn enought to be in a straight | |
// angle with the wall. | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
var wrog = ev.collidedRobot; | |
if((wrog.parentId = robot.id)||(wrog.id==robot.parentId)) { | |
robot.turn(20*direction); | |
robot.ahead(100); // trying to run away | |
} else { | |
robot.turn(ev.bearing); | |
robot.fire(); | |
} | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
robot.ahead(15); | |
robot.turn(ev.bearing); // Turn to wherever the bullet was fired | |
// so we can see who shot it | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment