Skip to content

Instantly share code, notes, and snippets.

@orian
Created December 4, 2012 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save orian/4199989 to your computer and use it in GitHub Desktop.
Save orian/4199989 to your computer and use it in GitHub Desktop.
Dzdzowniczka
var Robot = function(robot) {
};
Robot.prototype.lastHitAngle = -1;
Robot.prototype.radius = 20;
Robot.prototype.hit = 0;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
this.hit = 0;
if (this.lastHitAngle < 0) {
for (var i=0; this.hit == 0 && i < 10;++i) {
robot.rotateCannon(360/10);
robot.ahead(5 + i/3);
robot.turn(360/10 + i/4);
console.log("hit: "+hit);
}
}
if (this.lastHitAngle - robot.cannonAbsoluteAngle > 10) {
robot.rotateCannon(this.lastHitAngle - robot.cannonAbsoluteAngle);
}
robot.rotateCannon(this.radius);
this.radius = (-2*this.radius)%360;
if (this.hit==0) {
this.lastHitAngle = -1;
console.log("nie ma niczego");
}
robot.turn(25);
robot.ahead(60);
robot.rotateCannon(-25);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.fire();
this.lastHitAngle = robot.cannonAbsoluteAngle;
this.radius = 10;
this.hit = this.hit +1 ;
console.log("hit jak nic");
};
// ohhh... we were hit by another robot...
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.turn(90 - ev.bulletBearing);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment