Skip to content

Instantly share code, notes, and snippets.

@Isinlor
Forked from cgardner/robot.js
Created December 5, 2012 19:09
Show Gist options
  • Save Isinlor/4218579 to your computer and use it in GitHub Desktop.
Save Isinlor/4218579 to your computer and use it in GitHub Desktop.
IsinBot
/*
* It would be great if you fork & upgrade
* created by; Zolmeister
* edited by: Isinlor
* - added clone
* - upgrade of aim - for cloned robot
* - upgrade of aim - counting missed attack and adaptation
* - upgrade of dodge - move according to the hp
* edited by: type your nickname
* - what you changed - description
* TODO; RobotCollision - it sucks
* shooting when you are next to wall and in front of enemy
* shooting when enemy robot is going around in wrong direction
* upgrade of dodge of enemy attacks when robots are facing each other
*/
var count = 0;
var savedEnemyLife = 0;
var turnDirections = 1;
var Robot = function(robot){
robot.clone();
robot.turnLeft(robot.angle % 90);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.parentId) {
robot.ahead(1*turnDirections);
robot.turnGunRight(1*turnDirections);
}
else {
robot.ahead(-1*turnDirections);
robot.turnGunLeft(1*turnDirections);
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
if(!robot.parentId) {
robot.turnRight(ev.bearing - 90);
}
else {
robot.turnRight(ev.bearing + 90);
}
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot, collidedRobot = ev.collidedRobot;
robot.ignore('onRobotCollision');
if (ev.bearing > -90 && ev.bearing < 90) {
robot.back(100);
}
else {
robot.ahead(100);
}
if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
}
robot.listen('onRobotCollision')
};
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.ahead(120-robot.life);
// robot.turn(45 - ev.bulletBearing);
// robot.ahead(-50);
// robot.turn(45 - ev.bulletBearing);
// robot.back(90);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot, scannedRobot = ev.scannedRobot;
if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
return;
}
if(count > 5){
count = 0;
robot.log('5 miss');
if (robot.parentId) {
robot.turnGunRight(7);
} else {
robot.turnGunLeft(7);
}
}
robot.fire();
if(savedEnemyLife == scannedRobot.life){
count +=1;
} else {
count = 0;
}
savedEnemyLife = scannedRobot.life;
if (robot.parentId) {
robot.turnGunLeft(30);
} else {
robot.turnGunRight(30);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment