Skip to content

Instantly share code, notes, and snippets.

@richarddaros
Created December 6, 2012 18:10
Show Gist options
  • Select an option

  • Save richarddaros/4226668 to your computer and use it in GitHub Desktop.

Select an option

Save richarddaros/4226668 to your computer and use it in GitHub Desktop.
RDAROS
var Robot = function(robot) {};
// meus robos
var my_robots = [];
/**
*
*/
var verify_my_robots = function(a, obj) {
for (var i = 0; i < a.length; i++) {
if (a[i] === obj) {
return true;
}
}
return false;
}
/**
* Inicializa todos os robos e adiciona eles em uma lista de robos proprios
*/
var start_robots = function(robot){
robot.clone();
var is_my_robot = verify_my_robots(my_robots, robot.id);
if(is_my_robot==false){
my_robots[my_robots.length] = robot.id;
}
}
/**
* Fogo seguindo o inimigo pra onde ele for
*/
var sleep_fire = function(number, robot){
for(var i = 0; i < number; i++){
robot.fire();
}
for(var i = 0; i < 10; i++){
robot.rotateCannon(-2);
robot.fire();
robot.turn(5);
robot.ahead(10);
robot.fire();
}
for(var i = 0; i < 10; i++){
robot.back(10);
robot.rotateCannon(-2);
robot.fire();
robot.turn(-5);
robot.fire();
}
}
/**
* Looop infinito até encontrar um evento
{
robot: {
// INFORMATION ON THE CURRENT GAME
id, // Id from your robot
angle, // Current angle from your robot in degrees
cannonRelativeAngle, // Current angle from your cannon
// relative to your robot
cannonAbsoluteAngle, // Current angle from your cannon
// relative to the board
position: {
x, // X position in the board from your robot
y // Y position in the board from your robot
},
life, // Percentage of the life from your robot
gunCoolDownTime, // Time remaining in the cooldown from your
// cannon after shooting
availableClones, // Number of available clones you can use
parentId, // In the case of being a clone, the id
// from your parent element. null otherwise
arenaWidth, // Width from the board
arenaHeight // Height from the board
// AVAILABLE ACTIONS
// Moves the given amount ahead
ahead: function(amount),
// Moves the given amount backwards
back: function(amount),
// Rotates your cannon angle by the specified number of degrees
rotateCannon: function(amount),
// Rotates your robot the by the specified number of degrees
turn: function(amount),
// Fires your cannon. This functin has a cooldown before you can
// use it again.
fire: function(),
// Subscribe to get notified whenever this action gets called
// in the queue.
notify: function(callback),
// Removes all remaining actions your robot has from the queue
stop: function(),
// Clones your robot into another robot and can only be used once
// per fight. Remember to check the parentId property to stop
// your clone from shooting you.
clone: function(),
// Stops your robot from listening a given event (onWallColision,
// for instance).
ignore: function(eventName),
// Starts listening a given event (onWallColision, for instance).
listen: function(eventName)
}
}
*/
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
start_robots(robot);
//robot.ahead(90);//move o robo para frente
if(my_robots[0] == robot.id){
robot.ahead(100);
robot.turn(50);
robot.ahead(100);
robot.rotateCannon(180);//rotaciona o canhao
}else{
robot.rotateCannon(-180);
//robot.turn(100);//rotaciona o canhao
//robot.back(50);
}
//robot.back(100);//move o robo para traz
//robot.fire();//dispara
};
/**
se encontrar algum robo na mira do canhao
{
robot: {
// Same as onIdle
},
scannedRobot: {
id, // Id from the robot
position: {
x, // X position from the other robot relative to the board
},
angle, // Angle from the other robot
cannonAngle, // Cannon angle relative to the other robot
life, // Percentage of life from the other robot
parentId // If this is a clone, the clone's parent id.
// null otherwise
}
}
*/
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scannedRobot = ev.scannedRobot;
var is_my_robot = verify_my_robots(my_robots, scannedRobot.id);
if(is_my_robot == false){
//fogo no robo inimigo
sleep_fire(100, robot);
}else{
//robo amigo deve se movimentar
}
};
/**
* sempre que uma bala atinge seu robo
{
robot: {
// Same as onIdle
},
bearing // angle that the bullet came from relative
// to my tank's angle
}
*/
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.ahead(50);
robot.turn(50);
robot.ahead(50);
robot.turn(ev.bearing);
};
/*
* quando seu robo bate em uma parede
{
robot: {
// Same as onIdle
},
bearing // Degrees of the wall relative to my robot
// this property can vary from -180 to 180 degrees
}
*/
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(-ev.bearing);
robot.ahead(10);
};
/**
Quando colidir com outro robo
{
robot: {
// Same as onIdle
},
bearing, // Degrees that the other robot relative to my robot
// this property can vary from -180 to 180 degrees
collidedRobot: { // Information on the robot that collided with mine
id, // Id from the robot
position: {
x, // X position from the other robot relative to the board
y // Y position from the other robot relative to the board
},
angle, // Angle from the other robot
cannonAngle, // Cannon angle relative to the other robot
life, // Percentage of life from the other robot
parentId // If this is a clone, the clone's parent id.
// null otherwise
},
myFault // Boolean value that indicates whether I hit the other
// robot or the opposite
}
*/
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing);
robot.ahead(100);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment