Skip to content

Instantly share code, notes, and snippets.

@mariuszklinger
Created December 9, 2012 12:24
Show Gist options
  • Select an option

  • Save mariuszklinger/4244645 to your computer and use it in GitHub Desktop.

Select an option

Save mariuszklinger/4244645 to your computer and use it in GitHub Desktop.
Breakfast_Time
var Robot = function(robot) {
this.speed = 30;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.clone();
robot.ahead(this.speed);
if(!this.fire){
robot.rotateCannon(180);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var stranger = ev.scannedRobot;
if(this.isEnemy(ev)){
robot.fire();
robot.fire();
robot.rotateCannon(20);
robot.fire();
robot.fire();
robot.rotateCannon(-20);
robot.fire();
robot.fire();
robot.ahead(this.speed);
//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);
if(ev.myFault){
ev.robot.back(20);
}
else{
ev.robot.back(20);
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.turn(90);
robot.ahead(50);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment