Skip to content

Instantly share code, notes, and snippets.

@tsholmes
Created February 13, 2014 08:27
Show Gist options
  • Save tsholmes/8971674 to your computer and use it in GitHub Desktop.
Save tsholmes/8971674 to your computer and use it in GitHub Desktop.
(function(){
var counter = 0;
function swimmyai() {
var x = james.center.x;
var y = james.center.y;
var ice = iceburgs[0];
if (ice) {
if (x > ice.x + 100) ice = iceburgs[1];
var top = ice.IceburgTopUnderWaterHeight + ice.IceburgTopY;
var odx = ice.x - x;
var by = ice.IceburgBottomY;
var botcol = false;
var topcol = false;
var dt = .033;
var y2 = y;
var dy = james.dy;
var dy2 = dy + 200;
while (y > 0 || y2 > 0) {
x += dt * 180;
y += dt * dy;
y2 += dt * dy2;
dy -= 300 * dt;
dy2 -= 300 * dt;
if (x >= ice.x && x <= ice.x + 100) {
botcol = botcol || y2 >= by - 10;
topcol = topcol || y <= top + 10;
}
}
if (!botcol && topcol && counter > 5) {
$CVS.onclick();
counter = 0;
}
counter++;
}
setTimeout(swimmyai,33);
}
swimmyai();
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment