Created
December 8, 2012 22:37
-
-
Save p7o/4242312 to your computer and use it in GitHub Desktop.
Gunkerzer II
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 direction = 1; | |
var direction2 = 1; | |
var moveStep = 7; | |
var rotateStep = 2; | |
var initialized = false; | |
var initialized2 = false; | |
var noScanCount = 0; | |
var noScanCount2 = 0; | |
var noScanLimit = 50; | |
var Robot = function(robot) { | |
robot.clone(); | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if(robot.parentId == null){ | |
if(initialized){ | |
if(direction == 1){ | |
robot.ahead(moveStep); | |
robot.rotateCannon(-rotateStep); | |
}else{ | |
robot.back(moveStep); | |
robot.rotateCannon(rotateStep); | |
} | |
robot.fire(); | |
noScanCount ++; | |
if(noScanCount == noScanLimit){ | |
initialized = false; | |
} | |
}else{ | |
robot.rotateCannon(-rotateStep); | |
} | |
}else{ | |
if(initialized2){ | |
if(direction2 == 1){ | |
robot.back(moveStep); | |
robot.rotateCannon(-rotateStep); | |
}else{ | |
robot.ahead(moveStep); | |
robot.rotateCannon(rotateStep); | |
} | |
noScanCount2 ++; | |
if(noScanCount2 == noScanLimit){ | |
initialized2 = false; | |
} | |
robot.fire(); | |
}else{ | |
robot.rotateCannon(rotateStep); | |
} | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scannedRobot = ev.scannedRobot; | |
if(robot.parentId == scannedRobot.id ){ | |
}else if(robot.id == scannedRobot.parentId){ | |
}else{ | |
if(robot.parentId == null){ | |
noScanCount = 0; | |
initialized = true; | |
}else{ | |
noScanCount2 = 0; | |
initialized2 = true; | |
} | |
robot.fire(); | |
} | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
//robot.turn(ev.bearing - 90); | |
if(robot.parentId == null){ | |
direction *= -1; | |
}else{ | |
direction2 *= -1; | |
} | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot; | |
robot = ev.robot; | |
robot.rotateCannon(ev.bulletBearing); | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
if(robot.parentId == null){ | |
direction *= -1; | |
}else{ | |
direction2 *= -1; | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment