Created
December 6, 2012 23:37
-
-
Save diasbruno/4229439 to your computer and use it in GitHub Desktop.
Turin
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
// | |
// Turin.js 2.0.7b | |
// @author Bruno Dias | |
// | |
// Damn...events should never block!! | |
// TODO: a lot... | |
var clone; | |
var Robot = function(robot) { | |
this.targetAquired = false; | |
this.targetX = 0; | |
this.targetY = 0; | |
clone = robot.clone(); | |
}; | |
function isTurim(r1,r2) { | |
if ( r1.id===r2.parentId || | |
r1.parentId===r2.id ) { | |
return true; | |
} | |
return false; | |
} | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot, | |
rC = 1; | |
robot.ahead(10); | |
if (robot.parentId) { | |
robot.turn(20); | |
} | |
if (!this.targetAquired) { | |
rC = (robot.position.x < this.targetX) ? -1 : 1; | |
robot.rotateCannon( rC * 180 * Math.sin(robot.position.x) * Math.cos(robot.position.y) ); | |
} | |
//robot.fire(1 ); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
if ( isTurim(robot, ev.scannedRobot) ) return; | |
//robot.turn(40); | |
this.targetAquired = true; | |
this.targetX = ev.scannedRobot.position.x; | |
this.targetY = ev.scannedRobot.position.y; | |
robot.fire( 1 ); | |
robot.fire( 1 ); | |
robot.fire( 1 ); | |
robot.ahead( 40 ); | |
robot.fire( 1 ); | |
this.targetAquired = false; | |
//robot.rotateCannon(360); | |
robot.fire( 1 ); | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(20); | |
robot.back(10); | |
robot.ahead(100); // trying to run away | |
}; | |
// this method gets called whenever we hit a wall... | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
// testing | |
robot.ignore('onWallCollision'); | |
robot.turn(60); | |
robot.back(10); | |
robot.ahead(100); | |
robot.listen('onWallCollision'); | |
}; | |
// this method gets called whenever we hit a wall... | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
robot.ignore('onHitByBullet'); | |
robot.turn( 50 ); | |
robot.ahead( 104 ); | |
robot.rotateCannon(-robot.cannonAbsoluteAngle+ev.bulletBearing); | |
robot.listen('onHitByBullet'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment