Skip to content

Instantly share code, notes, and snippets.

@LouWii

LouWii/robot.js

Created Dec 7, 2012
Embed
What would you like to do?
YouCannotLoose
//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.clone();
if (robot.parentId==null)
{
robot.ahead(30);
robot.turn(3);
robot.rotateCannon(-20);
}
else
{
robot.turn(45);
robot.ahead(30);
robot.rotateCannon(20);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scanned = ev.scannedRobot;
if (scanned.id !== robot.parentId && scanned.parentId !== robot.id)
{
var i = 0;
while (i!=3)
{
robot.fire();
robot.ahead(30);
robot.fire();
robot.back(30);
i++;
}
robot.ahead(20);
}
};
// this method gets called whenever we hit another robot...
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(45);
robot.ahead(40);
};
// this method gets called whenever we hit a wall...
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(-20);
robot.ahead(10);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
//robot.turn(ev.bearing); // Turn to wherever the bullet was fired
// so we can see who shot it
var i = 0;
while (i!=10)
{
robot.turn(-5);
robot.ahead(40);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.