Created
December 4, 2012 08:58
-
-
Save ArnaudRinquin/4201968 to your computer and use it in GitHub Desktop.
Flibustache
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 = "spawned"; | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
switch(this.state) { | |
case "firing": | |
robot.fire(3); | |
break; | |
case "spawned": | |
this.center = { | |
x:robot.arenaWidth / 2, | |
y:robot.arenaHeight / 2 | |
}; | |
this.start = robot.position; | |
this.target = { | |
x: this.center.x - this.start.x, | |
y: this.center.y - this.start.y | |
} | |
this.radius = Math.min(ev.arenaWidth, ev.arenaHeight) - 10; | |
console.log("w,h,cx,cy", robot.arenaWidth, robot.arenaHeight, this.center.x, this.center.y); | |
console.log("rx, ry,tx,ty", robot.position.x, robot.position.y, this.target.x, this.target.y); | |
console.log("at, aa", robot.cannonAbsoluteAngle, robot.angle); | |
var angle = Math.floor(180 * Math.atan(this.target.y/this.target.x) / Math.PI); | |
//angle -= robot.cannonAbsoluteAngle; | |
robot.rotateCannon(angle); | |
console.log("angle=", angle); | |
this.state = "positioning"; | |
break; | |
case "positioning": | |
console.log("at, aa", robot.cannonAbsoluteAngle, robot.angle); | |
this.state = "idle"; | |
break; | |
case "circling": | |
case "hit": | |
//robot.rotateCannon(10); | |
} | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
this.status = "hit"; | |
} | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
//this.state = "firing"; | |
//robot.stop(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment