Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shaking cannon
//FightCode can only understand your robot
//if its class is called Robot
var go=120;
var Robot = function(robot) {};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
var clo =0
robot.clone();
if(robot.parentId!=null){
robot.turn(30);
robot.back(100);
}
robot.rotateCannon(90);
robot = ev.robot;
if(.6>Math.random()){
robot.rotateCannon(10);
robot.ahead(go+clo);
robot.turn(95);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var sr = ev.scannedRobot;
var robot = ev.robot;
var bFriendly = ( robot.parentId !=null && robot.parentId==sr.id);
bFriendly |= ( sr.parentId !=null && sr.parentId==robot.id);
if(bFriendly){
robot.rotateCannon(30);
robot.back(20);
}
if(!bFriendly){
robot.fire();
robot.fire();
robot.rotateCannon(-15);
robot.fire();
robot.fire();
robot.rotateCannon(15);
robot.fire();
robot.fire();
robot.rotateCannon(-15);
}
};
Robot.prototype.onWallCollision= function(ev){
var robot = ev.robot;
//robot.ignore(onWallCollision);
go=go*-1;
robot.back(go);
//robot.listen(onWallCollision);
robot.rotateCannon(-30);
robot.turn(30);
robot.back(go);
robot.rotateCannon(30);
robot.back(go);
robot.rotateCannon(-10);
robot.back(go);
}
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
if(robot.parentId!=null){
robot.turnCannon(ev.bearing);
robot.fire();
robot.fire();
robot.ahead(100);
robot.fire();
robot.ahead(100);
}
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(45);
robot.ahead(100); // trying to run away
};
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.