View/Edit #963!aero.js

File name: aero.js
function moveto(div, x, y) {
  if (document.getElementById && document.getElementById(div)) { // IE5 and Gecko and Opera
    document.getElementById(div).style.left = x+"px";
    document.getElementById(div).style.top = y+"px";
  } else if (document.all) { // IE4
    document.all[div].style.left = x+"px";
    document.all[div].style.top = y+"px";
  }
}

function maxX() {
  if (document.getElementById && document.getElementById('maptable')) { // IE5 and Gecko and Opera
    return document.getElementById('maptable').offsetWidth;
  } else if (document.all) { // IE4
    return document.all['maptable'].offsetWidth;
  }
  return 100;
}

function maxY() {
  if (document.getElementById && document.getElementById('maptable')) { // IE5 and Gecko and Opera
    return document.getElementById('maptable').offsetHeight;
  } else if (document.all) { // IE4
    return document.all['maptable'].offsetHeight;
  }
  return 100;
}

function planeturn() {
  if (Math.random() < 0.5)
    planez--;
  else
    planez++;
  if (planez > 7)  planez = 0;
  if (planez < 0)  planez = 7;
  planeinit();
}

function planeinit() {
  eval('document.planeimg.src = plane'+planez+'.src');
  switch (planez) {
    case 0: // N
      planedx = 0;  planedy = -planespeed;
      break;
    case 1: // NE
      planedx = planespeed*Math.SQRT1_2;  planedy = -planespeed*Math.SQRT1_2;
      break;
    case 2: // E
      planedx = planespeed;  planedy = 0;
      break;
    case 3: // SE
      planedx = planespeed*Math.SQRT1_2;  planedy = planespeed*Math.SQRT1_2;
      break;
    case 4: // S
      planedx = 0;  planedy = planespeed;
      break;
    case 5: // SW
      planedx = -planespeed*Math.SQRT1_2;  planedy = planespeed*Math.SQRT1_2;
      break;
    case 6: // W
      planedx = -planespeed;  planedy = 0;
      break;
    case 7: // NW
      planedx = -planespeed*Math.SQRT1_2;  planedy = -planespeed*Math.SQRT1_2;
      break;
  }
}

var randomx;
var randomy;

function planego() {
  var nextgo = 150;
  planex += planedx;
  planey += planedy;

  if (planedx == 0 && planedy == 0) {
    // Activate the plane.
    randomx = Math.random()*maxX()-planesize;
    randomy = Math.random()*maxY()-planesize;
    planez = Math.floor(Math.random()*8);
    planeinit();
    switch (planez) {
      case 0: // N
        planex = randomx;  planey = maxY()-planesize;
        break;
      case 1: // NE
        if (Math.random() < 0.5) {
          planex = randomx;  planey = maxY()-planesize;
        } else {
          planex = 1;  planey = randomy;
        }
        break;
      case 2: // E
        planex = 1;  planey = randomy;
        break;
      case 3: // SE
        if (Math.random() < 0.5) {
          planex = 1;  planey = randomy;
        } else {
          planex = randomx;  planey = 1;
        }
        break;
      case 4: // S
        planex = randomx;  planey = 1;
        break;
      case 5: // SW
        if (Math.random() < 0.5) {
          planex = randomx;  planey = 1;
        } else {
          planex = maxX()-planesize;  planey = randomy;
        }
        break;
      case 6: // W
        planex = maxX()-planesize;  planey = randomy;
        break;
      case 7: // NW
        if (Math.random() < 0.5) {
          planex = maxX()-planesize;  planey = randomy;
        } else {
          planex = randomx;  planey = maxY()-planesize;
        }
        break;
    }
  } else if (planex < 0 || planey < 0 || planex > maxX()-planesize || planey > maxY()-planesize) {
    // Hide the plane, and spawn a lengthy reactivation thread.
    planedx = 0;  planedy = 0;
    planex = -100;  planey = -100;
    nextgo = Math.floor(Math.random()*15000)+ 5000;
  }
  moveto('planediv', planex, planey);
  window.setTimeout('planego()', nextgo);
}


if (aero && plane) {
  var plane0 = new Image(46, 46);  plane0.src = 'http://files.moo.ca/9/6/3/plane-n.gif';
  var plane1 = new Image(46, 46);  plane1.src = 'http://files.moo.ca/9/6/3/plane-ne.gif';
  var plane2 = new Image(46, 46);  plane2.src = 'http://files.moo.ca/9/6/3/plane-e.gif';
  var plane3 = new Image(46, 46);  plane3.src = 'http://files.moo.ca/9/6/3/plane-se.gif';
  var plane4 = new Image(46, 46);  plane4.src = 'http://files.moo.ca/9/6/3/plane-s.gif';
  var plane5 = new Image(46, 46);  plane5.src = 'http://files.moo.ca/9/6/3/plane-sw.gif';
  var plane6 = new Image(46, 46);  plane6.src = 'http://files.moo.ca/9/6/3/plane-w.gif';
  var plane7 = new Image(46, 46);  plane7.src = 'http://files.moo.ca/9/6/3/plane-nw.gif';
  var planedx = 0;
  var planedy = 0;
  var planex = -100;
  var planey = -100;
  var planez = 0;
  var planespeed = 10;
  var planesize = 46;
  window.setTimeout('planego()', 1000);
}


function chopperinit() {
  eval('document.chopperimg.src = chopper'+chopperz+'.src');
  switch (chopperz) {
    case 0: // N
      chopperdx = 0;  chopperdy = -chopperspeed;
      break;
    case 1: // NE
      chopperdx = chopperspeed*Math.SQRT1_2;  chopperdy = -chopperspeed*Math.SQRT1_2;
      break;
    case 2: // E
      chopperdx = chopperspeed;  chopperdy = 0;
      break;
    case 3: // SE
      chopperdx = chopperspeed*Math.SQRT1_2;  chopperdy = chopperspeed*Math.SQRT1_2;
      break;
    case 4: // S
      chopperdx = 0;  chopperdy = chopperspeed;
      break;
    case 5: // SW
      chopperdx = -chopperspeed*Math.SQRT1_2;  chopperdy = chopperspeed*Math.SQRT1_2;
      break;
    case 6: // W
      chopperdx = -chopperspeed;  chopperdy = 0;
      break;
    case 7: // NW
      chopperdx = -chopperspeed*Math.SQRT1_2;  chopperdy = -chopperspeed*Math.SQRT1_2;
      break;
  }
}

function chopperdist(x, y) {
  // Returns distance from x, y to the perimeter of the current goal.
  var z = Math.sqrt((x-choppergoalx)*(x-choppergoalx) + (y-choppergoaly)*(y-choppergoaly));
  return Math.abs(z-85);
}

function choppergo() {
  var distnow = chopperdist(chopperx, choppery);
  if (distnow > 15) { // We're not hugging the orbit
    var diststraight = chopperdist(chopperx+chopperdx, choppery+chopperdy);
    if (diststraight >= distnow) { // A turn is needed
      chopperz--;  // Try CCW
      if (chopperz < 0)  chopperz = 7;
      chopperinit();
      var distccw = chopperdist(chopperx+chopperdx, choppery+chopperdy);
      chopperz++;  // Straight
      chopperz++;  // Try CW
      if (chopperz > 7)  chopperz = chopperz - 8;
      chopperinit();
      var distcw = chopperdist(chopperx+chopperdx, choppery+chopperdy);
      if (distcw > distccw) { // Flip back CCW
        chopperz--;  // Straight
        chopperz--;  // CCW
        if (chopperz < 0)  chopperz = chopperz + 8;
        chopperinit();
      }
    }
  }
  chopperx += chopperdx;
  choppery += chopperdy;
  moveto('chopperdiv', chopperx-choppersize/2, choppery-choppersize/2);
  window.setTimeout('choppergo()', 200);
}

function newchoppergoal(e) {
  // Called as an event for document.onmousemove
  if (e && e.pageX) { // Mozilla
    choppergoalx = e.pageX;
    choppergoaly = e.pageY;
  } else { // IE/Opera
    choppergoalx = event.clientX;
    choppergoaly = event.clientY;
    if (document.all) { // IE bug
      choppergoalx += choppergoalx + document.body.scrollLeft;
      choppergoaly += choppergoaly + document.body.scrollTop;
    }
  }
  choppergoalx = Math.max(Math.min(choppergoalx, maxX()-100), 100);
  choppergoaly = Math.max(Math.min(choppergoaly, maxY()-100), 100);
}

if (aero && chopper) {
  var chopper0 = new Image(32, 32);  chopper0.src = 'http://files.moo.ca/9/6/3/chopper-n.gif';
  var chopper1 = new Image(32, 32);  chopper1.src = 'http://files.moo.ca/9/6/3/chopper-ne.gif';
  var chopper2 = new Image(32, 32);  chopper2.src = 'http://files.moo.ca/9/6/3/chopper-e.gif';
  var chopper3 = new Image(32, 32);  chopper3.src = 'http://files.moo.ca/9/6/3/chopper-se.gif';
  var chopper4 = new Image(32, 32);  chopper4.src = 'http://files.moo.ca/9/6/3/chopper-s.gif';
  var chopper5 = new Image(32, 32);  chopper5.src = 'http://files.moo.ca/9/6/3/chopper-sw.gif';
  var chopper6 = new Image(32, 32);  chopper6.src = 'http://files.moo.ca/9/6/3/chopper-w.gif';
  var chopper7 = new Image(32, 32);  chopper7.src = 'http://files.moo.ca/9/6/3/chopper-nw.gif';
  var chopperdx = 0;
  var chopperdy = 0;
  var choppersize = 32;
  var chopperspeed = 5;
  var choppergoalx = Math.random() * Math.max(maxX(), 500);
  var choppergoaly = Math.random() * Math.max(maxY(), 300);
  choppergoalx = Math.max(Math.min(choppergoalx, maxX()-100), 100);
  choppergoaly = Math.max(Math.min(choppergoaly, maxY()-100), 100);
  var chopperx = Math.random() * Math.max(maxX(), 500);
  var choppery = Math.random() * Math.max(maxY(), 300);
  var chopperz = Math.floor(Math.random()*8);
  document.onmousemove=newchoppergoal;

  chopperinit();
  window.setTimeout('choppergo()', 1000);
}

http://files.moo.ca:8081/9/6/3/aero.js
Size: 8,729 bytes.
File perms: Readable


You are not logged in.

[home | help | who | search | setup | code]