-
-
Save cezarsa/4176842 to your computer and use it in GitHub Desktop.
seeker
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
var robotData = {}; | |
var isClone = function(r) { | |
return !!r.parentId; | |
}; | |
var isRelated = function(r1, r2) { | |
return r1.id == r2.parentId || r1.parentId == r2.id; | |
}; | |
var set = function(r, k, v) { | |
robotData[r.id] = robotData[r.id] || {}; | |
robotData[r.id][k] = v === undefined ? true : v; | |
}; | |
var get = function(r, k) { | |
return robotData[r.id] && robotData[r.id][k]; | |
}; | |
var Robot = function(robot){ | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var r = ev.robot; | |
if (!get(r, 'started')) { | |
set(r, 'spd', 10); | |
if (!isClone(r)) { | |
r.clone(); | |
set(r, 'dir', 1); | |
set(r, 'cdir', 1); | |
} else { | |
set(r, 'dir', -1); | |
set(r, 'cdir', -1); | |
} | |
set(r, 'started'); | |
return; | |
} | |
var cc = get(r, 'changeC'); | |
if (cc != null && cc > 0) { | |
cc--; | |
set(r, 'changeC', cc); | |
if (!r.gunCoolDownTime) { | |
r.fire(); | |
} | |
} else if (cc === 0) { | |
set(r, 'changeC', null); | |
set(r, 'cdir', get(r, 'cdir') * -1); | |
} | |
r.move(get(r, 'spd'), get(r, 'dir')); | |
r.rotateCannon(get(r, 'cdir')*get(r, 'spd')/2); | |
var cr = get(r, 'changeR'), ncr; | |
var inc = 1; | |
if (cr) { | |
if (cr < 0) inc = -1; | |
r.turn(inc); | |
ncr = cr + (inc * -1); | |
set(r, 'changeR', ncr); | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var r = ev.robot, sr = ev.scannedRobot; | |
if (isRelated(r, sr)) { | |
return; | |
} | |
set(r, 'spd', 1); | |
set(r, 'changeC', 20); | |
r.fire(); | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var r = ev.robot; | |
//set(r, 'dir', get(r, 'dir') * -1); | |
if (isClone(r)) { | |
//set(r, 'dir', 1); | |
//set(r, 'changeR', ev.bearing + 90); | |
r.turn(ev.bearing + 90); | |
} else { | |
//set(r, 'changeR', ev.bearing + 90); | |
r.turn(ev.bearing - 90); | |
} | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
var r = ev.robot; | |
set(r, 'dir', get(r, 'dir') * -1); | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment