home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Diversos / clowns.swf / scripts / DefineSprite_366 / frame_1 / DoAction.as
Encoding:
Text File  |  2006-06-13  |  5.6 KB  |  207 lines

  1. function matterHitTest(pPosX, pPosY, pSensor)
  2. {
  3.    tCheckX = pPosX + sensors[pSensor].x;
  4.    tCheckY = pPosY + sensors[pSensor].y;
  5.    return _root.world.matter.hitTest(tCheckX,tCheckY,true);
  6. }
  7. function solidHitTest(pPosX, pPosY, pSensor)
  8. {
  9.    tCheckX = pPosX + sensors[pSensor].x;
  10.    tCheckY = pPosY + sensors[pSensor].y;
  11.    return _root.world.matter.solid.hitTest(tCheckX,tCheckY,true);
  12. }
  13. function deadlyHitTest(pPosX, pPosY, pSensor)
  14. {
  15.    tCheckX = pPosX + sensors[pSensor].x;
  16.    tCheckY = pPosY + sensors[pSensor].y;
  17.    return _root.world.matter.deadly.hitTest(tCheckX,tCheckY,true);
  18. }
  19. function objectsHitTest(pPosX, pPosY, pSensor)
  20. {
  21.    tCheckX = pPosX + sensors[pSensor].x;
  22.    tCheckY = pPosY + sensors[pSensor].y;
  23.    tResults = new Array();
  24.    tResultCount = 0;
  25.    tRegId = 0;
  26.    while(tRegId < _root.world.regCount)
  27.    {
  28.       if(_root.world.regObjects[tRegId].hitTest(tCheckX,tCheckY,false) && _root.world.regObjects[tRegId].hitTest(tCheckX,tCheckY,true))
  29.       {
  30.          tResults[tResultCount++] = _root.world.regObjects[tRegId];
  31.       }
  32.       tRegId++;
  33.    }
  34.    return tResults;
  35. }
  36. function Sensor(pX, pY, pBounceH, pBounceV, pActive, pDieAtDanger, pHitObjects, pPassSolid)
  37. {
  38.    tThis = new Object();
  39.    tThis.x = pX;
  40.    tThis.y = pY;
  41.    tThis.bounceH = pBounceH;
  42.    tThis.bounceV = pBounceV;
  43.    tThis.active = pActive;
  44.    tThis.dieAtDanger = pDieAtDanger;
  45.    tThis.hitObjects = pHitObjects;
  46.    tThis.passSolid = pPassSolid;
  47.    return tThis;
  48. }
  49. function refill()
  50. {
  51.    _global.stat.actShots = _global.opt.startShots;
  52. }
  53. function reset()
  54. {
  55.    needCollect = 0;
  56.    _parent.resetLevel();
  57.    _root.console.time = _global.opt.startTime;
  58.    timerMax = 25;
  59.    timer = timerMax;
  60.    vx = 0;
  61.    vy = 0;
  62.    vr = 0;
  63.    refill();
  64.    mainSprite._x = 275;
  65.    mainSprite._y = wallBottom;
  66.    clowns[0].mode = MODE_STANDING;
  67.    clowns[1].mode = MODE_FLYING;
  68.    clowns[0].gotoAndStop("standing");
  69.    clowns[1].gotoAndStop("flying");
  70.    clowns[1]._x = clowns[1].originalX;
  71.    clowns[1]._y = clowns[1].originalY;
  72.    i = 0;
  73.    while(i < 2)
  74.    {
  75.       clowns[i].plankX = 0.5;
  76.       clowns[i].vx = 0;
  77.       clowns[i].vy = 0;
  78.       clowns[i].health = 1;
  79.       updateHealth(clowns[i]);
  80.       i++;
  81.    }
  82.    mainSprite.plank.maxRotation = 15;
  83.    mainSprite.plank._rotation = -1 * mainSprite.plank.maxRotation;
  84.    plankTargetX = mainSprite._x;
  85.    clowns[0]._x = calcOnPlankX(0);
  86.    clowns[0]._y = calcOnPlankY(0);
  87. }
  88. function setScore(pScore)
  89. {
  90.    _global.stat.actScore = pScore;
  91.    _root.console.score = _global.stat.actScore;
  92. }
  93. function addToScore(pScore)
  94. {
  95.    _global.stat.actScore += pScore;
  96.    _root.console.score = _global.stat.actScore;
  97. }
  98. function addHealthToFlying(pAdd)
  99. {
  100.    flyingClown.health += pAdd;
  101.    if(flyingClown.health > 1)
  102.    {
  103.       flyingClown.health = 1;
  104.    }
  105.    updateHealth(flyingClown);
  106. }
  107. function damageHealth(pClown, pDamage)
  108. {
  109.    pClown.health -= pDamage;
  110.    if(pClown.health < 0)
  111.    {
  112.       pClown.health = 0;
  113.       updateHealth(pClown);
  114.       pClown.gotoAndStop("dead");
  115.       gotoAndPlay(7);
  116.    }
  117.    else
  118.    {
  119.       updateHealth(pClown);
  120.    }
  121. }
  122. function updateHealth(pClown)
  123. {
  124.    tFrame = Math.round(pClown.healthDisplay._totalframes * pClown.health);
  125.    if(tFrame < 1)
  126.    {
  127.       tFrame = 1;
  128.    }
  129.    pClown.healthDisplay.gotoAndStop(tFrame);
  130. }
  131. function updateLifes()
  132. {
  133.    if(_global.stat.actLifes < 5)
  134.    {
  135.       _root.console.lifes.gotoAndStop(_global.stat.actLifes + 1);
  136.    }
  137.    else
  138.    {
  139.       _root.console.lifes.gotoAndStop(6);
  140.       _root.console.actLifes = _global.stat.actLifes;
  141.    }
  142. }
  143. function setClownStanding(pClown)
  144. {
  145.    pClown._x = mainSprite._x + pClown.plankX * pClown.mirrorX * plankWidth * 0.5;
  146.    pClown._y = wippeTop + mainSprite.plank._rotation;
  147. }
  148. function calcOnPlankY(pId)
  149. {
  150.    return axisY + Math.sin(mainSprite.plank._rotation / 180 * 3.141592653589793) * clowns[pId].mirrorX * plankWidth / 2 * clowns[pId].plankX;
  151. }
  152. function calcOnPlankX(pId)
  153. {
  154.    return plankTargetX + Math.cos(mainSprite.plank._rotation / 180 * 3.141592653589793) * clowns[pId].mirrorX * plankWidth / 2 * clowns[pId].plankX;
  155. }
  156. function calcPlankLandingX(pId)
  157. {
  158.    return (clowns[pId].targetX - plankTargetX) / (plankWidth / 2) * clowns[pId].mirrorX;
  159. }
  160. sensors = new Array();
  161. sensorAmount = 8;
  162. sensors[0] = Sensor(0,0,0,0,true,true,true,true);
  163. sensors[1] = Sensor(0,-35,0,0,true,true,true,true);
  164. sensors[2] = Sensor(22,-12,0,0,true,true,true,true);
  165. sensors[3] = Sensor(-22,-12,0,0,true,true,true,true);
  166. sensors[4] = Sensor(22,-24,0,0,true,true,true,true);
  167. sensors[5] = Sensor(-22,-24,0,0,true,true,true,true);
  168. sensors[6] = Sensor(0,-12,0,0,true,true,true,true);
  169. sensors[7] = Sensor(0,-24,0,0,true,true,true,true);
  170. plankWidth = 130;
  171. setScore(_global.stat.actScore);
  172. updateLifes();
  173. mainSprite.cycle.monkey.stop();
  174. mainSprite.cycle.monkeyLeg.stop();
  175. mainSprite.cycle.stop();
  176. vxMax = 5;
  177. vyMax = 5;
  178. ax = 5;
  179. gravity = 0.33;
  180. fx = 0;
  181. fy = 0;
  182. wallLeft = 0;
  183. wallRight = 550;
  184. wallTop = 32;
  185. wallBottom = 395;
  186. axisY = wallBottom - 20;
  187. wippeHeight = 40;
  188. wippeTop = wallBottom - wippeHeight;
  189. lifes = _global.stat.actLifes;
  190. updateLifes();
  191. clowns = new Array();
  192. clowns[0] = clownLeft;
  193. clowns[1] = clownRight;
  194. clowns[0].partner = clownRight;
  195. clowns[1].partner = clownLeft;
  196. clowns[0].originalX = clowns[0]._x;
  197. clowns[0].originalY = clowns[0]._y;
  198. clowns[1].originalX = clowns[1]._x;
  199. clowns[1].originalY = clowns[1]._y;
  200. MODE_FLYING = 1;
  201. MODE_STANDING = 0;
  202. MODE_RETURNING = 2;
  203. clowns[0].lookDir = "right";
  204. clowns[1].lookDir = "left";
  205. clowns[0].healthDisplay = _root.console.health_left;
  206. clowns[1].healthDisplay = _root.console.health_right;
  207.