Created
December 6, 2012 19:55
-
-
Save brunopedroso/4227768 to your computer and use it in GitHub Desktop.
DOJOBOT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//FightCode can only understand your robot | |
//if its class is called Robot | |
var Robot = function(robot) { | |
this.state = 'procurando'; | |
this.voltadas = 0 | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if(this.state=='procurando'){ | |
robot.rotateCannon(30); | |
robot.ahead(30); | |
} else if (this.state=='quicando') { | |
this.corretPosition(robot); | |
}else if(this.state=='voltando_arma'){ | |
robot.rotateCannon(-30); | |
robot.ahead(10); | |
this.state = 'procurando'; | |
}else if(this.state=='fuga'){ | |
robot.back(100); | |
robot.turn(20); | |
if (this.fugas<=5) { | |
this.fugas += 1; | |
} else { | |
this.state='procurando'; | |
this.fugas = 0; | |
} | |
} | |
}; | |
Robot.prototype.correctPosition = function(robot){ | |
robot.back(50); | |
robot.turn(50); | |
robot.ahead(50); | |
robot.state = 'procurando'; | |
/* | |
var divide = 5; | |
var p1 = (0.0+this.angulo_carro)/divide; | |
var p2 = (0.0+this.angulo_arma)/divide; | |
robot.turn(p1); | |
robot.rotateCannon(p2); | |
this.angulo_carro_virado += p1; | |
this.angulo_arma_virado += p2; | |
if(Math.abs(this.angulo_carro)<=Math.abs(this.angulo_carro_virado)){ | |
this.state = 'procurando'; | |
} | |
*/ | |
} | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
this.state = 'voltando_arma'; | |
robot.fire(); | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot; | |
this.fugas = 0; | |
robot = ev.robot; | |
this.state = 'fuga'; | |
}; | |
/* Robot.prototype.nWallCollision = function(ev) { | |
var robot = ev.robot; | |
if (this.state != 'quicando') { | |
var angulo; | |
if(ev.bearing>0) | |
angulo = -180+2*ev.bearing; | |
else | |
angulo = +180+2*ev.bearing; | |
this.state = 'quicando'; | |
this.angulo_carro = angulo; | |
this.angulo_arma = -angulo; | |
this.angulo_carro_virado = 0.0; | |
this.angulo_arma_virado = 0.0; | |
robot.log(this.angulo_carro); | |
} | |
}; | |
*/ | |
Robot.prototype.onWallCollision = function(ev){ | |
var robot = ev.robot; | |
this.correctPosition(robot); | |
}; | |
Robot.prototype.onRobotCollision = function(ev){ | |
var robot = ev.robot; | |
robot.rotateCannon(-ev.collidedRobot.angle); | |
robot.fire(); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment