Skip to content

Instantly share code, notes, and snippets.

@julianosam
Created December 10, 2012 12:43
Show Gist options
  • Save julianosam/4250345 to your computer and use it in GitHub Desktop.
Save julianosam/4250345 to your computer and use it in GitHub Desktop.
bad_titanium_ass
var st_move = {
keep_time: 360,
turn_dir: 5,
move_dir: 10,
angle : 10,
calls : 0,
run: function (robot) {
robot.turn(this.turn_dir);
robot.move(this.move_dir);
robot.rotateCannon(1);
//if(++this.calls == this.keep_time){
//this.turn_dir++;
//this.move_dir++;
//this.calls = 0;
//}
}
}
var st_fire = {
keep_time: 3,
amount: 4,
run: function (robot){
robot.fire();
robot.turnLeft(this.amount);
robot.fire();
robot.turnRight(this.amount);
}
}
var strategies = {
active : 0,
moves : 0,
array : [st_move, st_fire],
get : function() {
return this.array[this.active];
},
plan : function(){
var st = this.get();
this.moves++;
if(this.moves > st.keep_time){
this.active = this.active+1 >= this.array.length ? 0 : this.active+1 ;
this.moves = 0;
}
},
set : function(index){
this.moves = 0;
this.active = index;
}
};
var Robot = function(robot) {
//console.log("Position: " + robot.position.x + ', '+robot.position.y);
};
Robot.prototype.onIdle = function(ev) {
strategies.get().run(ev.robot);
strategies.plan();
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var other = ev.scannedRobot;
//if (robot.id == other.parentId || robot.parentId == other.id) return;
robot.stop();
//console.log(other.angle);
strategies.set(1);
};
// 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) {
ev.robot.back(50);
ev.robot.turn(90);
//ev.robot.back(50);
};
Robot.prototype.onHitByBullet = function(ev){
ev.robot.move(25);
console.log("Bullet from:" + ev.bearing);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment