Skip to content

Instantly share code, notes, and snippets.

@mariuszklinger
Created December 9, 2012 12:24
Show Gist options
  • Save mariuszklinger/4244645 to your computer and use it in GitHub Desktop.
Save mariuszklinger/4244645 to your computer and use it in GitHub Desktop.
Breakfast_Time
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
this.speed = 30;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
//robot.clone();
var s = this.speed;
if(robot.life < 30){
this.speed = 60;
}
robot.ahead(s);
if(!this.fire){
robot.rotateCannon(20);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var stranger = ev.scannedRobot;
if(this.isEnemy(ev)){
robot.fire();
robot.turn(20);
robot.fire();
robot.fire();
robot.turn(-20);
robot.fire();
robot.fire();
robot.turn(20);
//this.fire = true;
}
};
Robot.prototype.onWallCollision = function(ev) {
ev.robot.turn(ev.bearing + 90);
ev.robot.back(this.speed);
};
Robot.prototype.isEnemy = function(ev){
var me = ev.robot;
var stranger = ev.scannedRobot;
return (me.id != stranger.parentId) && (me.parentId != stranger.id);
}
Robot.prototype.onRobotCollision = function(ev) {
ev.robot.turn(ev.bearing + 90);
ev.robot.ahead(100);
};
Robot.prototype.onHitByBullet = function(ev){
var me = ev.robot;
me.ahead(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment