Skip to content

Instantly share code, notes, and snippets.

@juniorz
Forked from yuyi/robot.js
Created December 7, 2012 23:04
Show Gist options
  • Save juniorz/4237323 to your computer and use it in GitHub Desktop.
Save juniorz/4237323 to your computer and use it in GitHub Desktop.
OPENROBOT
function Robot(robot) {
this.dd = false;
}
// well, we need to do something...
// whenever our robot is idle, this method gets called.
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
///robot.ahead(10);
//robot.rotateCannon(-robot.cannonAbsoluteAngle);
//robot.turn(-robot.angle)
var x = robot.position.x;
var y = robot.position.y;
var pi = Math.PI;
var dx = 0 - x;
var dy = 0 - y;
var degree = Math.atan2(dx,-dy)*180/pi;
if(!this.dd)
robot.log(x,y,degree);
this.dd=true;
};
// this method gets called whenever we hit another robot...
Robot.prototype.onRobotCollision = function(ev) {};
// this method gets called whenever we hit a wall...
Robot.prototype.onWallCollision = function(ev) {};
// yay we see another robot! time to wreak some havoc...
Robot.prototype.onScannedRobot = function(ev) {
var robot;
robot = ev.robot;
//robot.fire(1);
};
// 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