Skip to content

Instantly share code, notes, and snippets.

@grom44
Created December 6, 2012 20:21
Show Gist options
  • Save grom44/4227981 to your computer and use it in GitHub Desktop.
Save grom44/4227981 to your computer and use it in GitHub Desktop.
Grom_test_robot
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.rotateCannon(5);
robot.turn(5);
robot.back(10);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var enemy = ev.scannedRobot;
robot.clone();
if(enemy.parentId == robot.id || enemy.id == robot.parentId)
{
return;
}
for (var i=0; i<=50; i++)
{
robot.fire();
}
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.fire();
};
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.back(50);
robot.rotateCannon(ev.bearing);
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
var szer = robot.arenaWidth;
var wyso = robot.arenaHeight;
robot.turn(ev.bearing); // turn enought to be in a straight
if(robot.position.x > szer-20 || robot.position.x < 20)
{
robot.back(szer/4);
}
if(robot.position.y > wyso-20 || robot.position.y < 20)
{
robot.back(wyso/4);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment