Skip to content

Instantly share code, notes, and snippets.

@klod76
Created December 6, 2012 13:46
Show Gist options
  • Save klod76/4224550 to your computer and use it in GitHub Desktop.
Save klod76/4224550 to your computer and use it in GitHub Desktop.
MmmMHHmmmm
var Robot = function(robot) {
this.direction = 1;
this.found = 0;
this.speed = 3;
};
Robot.prototype.onIdle = function(ev) {
var r = ev.robot;
if (this.found == 0) {
// left wall
if (r.position.x < r.position.y && r.position.x < (r.arenaHeight-r.position.y) && r.position.x < r.arenaWidth/2) {
(r.angle < 90) ? r.turn(-90-r.angle) : r.turn(270-r.angle);
}
// top wall
else if (r.position.x > r.position.y && (r.arenaWidth-r.position.x) > r.position.y && r.position.y < r.arenaHeight/2) {
(r.angle < 180) ? r.turn(-r.angle) : r.turn(360-r.angle);
}
// right wall
else if ((r.arenaWidth-r.position.x) < (r.arenaHeight-r.position.y)) {
(r.angle < 270) ? r.turn(90-r.angle) : r.turn(450-r.angle);
}
// bottom wall
else {
(r.angle < 180) ? r.turn(180-r.angle) : r.turn(-180+r.angle);
}
this.found = 1;
}
r.ahead(this.speed);
r.rotateCannon(10);
};
Robot.prototype.onScannedRobot = function(ev) {
var r = ev.robot;
r.fire();
r.rotateCannon(-3);
r.rotateCannon(-25);
}
Robot.prototype.onWallCollision = function(ev) {
var r = ev.robot;
r.turnRight(ev.bearing + 90);
};
Robot.prototype.onHitByBullet = function(ev) {
var r = ev.r;
if(r.parentId!=null){
r.rotateCannon(ev.bearing);
r.fire();
r.fire();
r.fire();
r.fire();
r.fire();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment