home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Diversos / cone_crazy_2.swf / scripts / frame_5 / DoAction.as
Encoding:
Text File  |  2007-03-20  |  9.3 KB  |  251 lines

  1. function WorldToScreen(world_x, world_y, world_z)
  2. {
  3.    x = Math.round(world_x * 7 + world_z * 5 * 1.4);
  4.    y = Math.round(- world_z * 5 + world_x * 7 * 0.71426 - world_y * 5);
  5.    return [x,y];
  6. }
  7. var Snd_hit = new Sound();
  8. Snd_hit.attachSound("hit_1");
  9. var Snd_hit2 = new Sound();
  10. Snd_hit2.attachSound("hit_2");
  11. var B = new Object();
  12. B.clip = "tile_blktop";
  13. B.oktodrive = true;
  14. B.effects = new Object();
  15. B.effects.bumpy = 0;
  16. B.effects.drag = 0;
  17. var P = new Object();
  18. P.clip = "tile_pothole";
  19. P.oktodrive = true;
  20. P.effects = new Object();
  21. P.effects.bumpy = 5;
  22. P.effects.drag = 0.08;
  23. var L = new Object();
  24. L.clip = "obj_lightpole";
  25. L.doWhenHit = function(speed, angle, tile)
  26. {
  27.    if(Math.abs(_root.game.player.speed) >= 0.5)
  28.    {
  29.       _root.Snd_hit.start();
  30.    }
  31.    _root.game.player.car_x += (- speed) * Math.sin(angle * 3.141592653589793 / 180);
  32.    _root.game.player.car_z += (- speed) * Math.cos(angle * 3.141592653589793 / 180);
  33.    _root.game.player.speed = - _root.game.player.speed * 0.8;
  34. };
  35. var H = new Object();
  36. H.clip = "obj_hydrant";
  37. H.doWhenHit = function(speed, angle, tile)
  38. {
  39.    _root.lives = _root.lives - 1;
  40.    this.nextFrame();
  41.    if(Math.abs(_root.game.player.speed) >= 0.5)
  42.    {
  43.       _root.Snd_hit.start();
  44.    }
  45.    _root.game.player.car_x += (- speed) * Math.sin(angle * 3.141592653589793 / 180);
  46.    _root.game.player.car_z += (- speed) * Math.cos(angle * 3.141592653589793 / 180);
  47.    _root.game.player.speed = - _root.game.player.speed * 0.8;
  48.    tile.object = null;
  49.    if(_root.lives <= 0)
  50.    {
  51.       _root.lives = 0;
  52.       timer.display = 0;
  53.       this._xscale = 0;
  54.       _root.timer.onEnterFrame = null;
  55.       _root.game.player.onEnterFrame = null;
  56.       _root.gotoAndPlay("game_over");
  57.    }
  58. };
  59. var S = new Object();
  60. S.clip = "obj_sp_cone";
  61. S.doWhenHit = function(speed, angle, tile)
  62. {
  63.    _root.Snd_hit2.start();
  64.    _root.score += 50;
  65.    _root.cones_hit = _root.cones_hit + 1;
  66.    this.speed = speed * 1.8;
  67.    this.angle = angle + (random(30) - 15);
  68.    if(this.angle < 0)
  69.    {
  70.       this.angle = 360 + this.angle;
  71.    }
  72.    this.angle %= 360;
  73.    var _loc3_ = "hit_" + 45 * Math.floor(this.angle / 45);
  74.    this.gotoAndStop(_loc3_);
  75.    _root.game.player.speed *= 0.8;
  76.    this.onEnterFrame = this.doAfterHit;
  77.    tile.object = null;
  78. };
  79. S.doAfterHit = function()
  80. {
  81.    if(Math.abs(this.trans_x) + Math.abs(this.trans_z) >= 0.01)
  82.    {
  83.       this.trans_x = this.speed * Math.sin(this.angle * 3.141592653589793 / 180);
  84.       this.trans_z = this.speed * Math.cos(this.angle * 3.141592653589793 / 180);
  85.       this.pos_x += this.trans_x;
  86.       this.pos_z += this.trans_z;
  87.       var _loc3_ = _root.WorldToScreen(this.pos_x,0,this.pos_z);
  88.       var _loc4_ = Math.floor((world.totaldepth - (this.pos_z + 8)) * 1000 + this.pos_x);
  89.       this.swapDepths(_loc4_);
  90.       this._x = _loc3_[0];
  91.       this._y = _loc3_[1];
  92.       this.speed *= 0.8;
  93.       this.t_row = Math.floor(this.pos_z / _root.world.tile_height);
  94.       this.t_col = Math.floor(this.pos_x / _root.world.tile_width);
  95.       this.t_tile = _root.game["tile_" + this.t_row + "_" + this.t_col];
  96.       this.t_object = this.t_tile.object;
  97.       if(this.t_object)
  98.       {
  99.          _loc3_ = WorldToScreen(this.t_object.pos_x,0,this.t_object.pos_z);
  100.          if(this.hitTest(_loc3_[0] + _root.game._x,_loc3_[1] + _root.game._y,true))
  101.          {
  102.             this.t_object = null;
  103.             this.t_object.doWhenHit(this.speed,this.angle,this.t_tile);
  104.          }
  105.       }
  106.    }
  107.    else
  108.    {
  109.       this._alpha -= 5;
  110.       if(this._alpha <= 0)
  111.       {
  112.          this.removeMovieClip();
  113.       }
  114.    }
  115. };
  116. var C = new Object();
  117. C.clip = "obj_cone";
  118. C.doWhenHit = function(speed, angle, tile)
  119. {
  120.    _root.Snd_hit2.start();
  121.    _root.score += 10;
  122.    _root.cones_hit = _root.cones_hit + 1;
  123.    this.speed = speed * 1.8;
  124.    this.angle = angle + (random(30) - 15);
  125.    if(this.angle < 0)
  126.    {
  127.       this.angle = 360 + this.angle;
  128.    }
  129.    this.angle %= 360;
  130.    var _loc3_ = "hit_" + 45 * Math.floor(this.angle / 45);
  131.    this.gotoAndStop(_loc3_);
  132.    _root.game.player.speed *= 0.8;
  133.    this.onEnterFrame = this.doAfterHit;
  134.    tile.object = null;
  135. };
  136. C.doAfterHit = function()
  137. {
  138.    if(Math.abs(this.trans_x) + Math.abs(this.trans_z) >= 0.01)
  139.    {
  140.       this.trans_x = this.speed * Math.sin(this.angle * 3.141592653589793 / 180);
  141.       this.trans_z = this.speed * Math.cos(this.angle * 3.141592653589793 / 180);
  142.       this.pos_x += this.trans_x;
  143.       this.pos_z += this.trans_z;
  144.       var _loc3_ = _root.WorldToScreen(this.pos_x,0,this.pos_z);
  145.       var _loc4_ = Math.floor((world.totaldepth - (this.pos_z + 8)) * 1000 + this.pos_x);
  146.       this.swapDepths(_loc4_);
  147.       this._x = _loc3_[0];
  148.       this._y = _loc3_[1];
  149.       this.speed *= 0.8;
  150.       this.t_row = Math.floor(this.pos_z / _root.world.tile_height);
  151.       this.t_col = Math.floor(this.pos_x / _root.world.tile_width);
  152.       this.t_tile = _root.game["tile_" + this.t_row + "_" + this.t_col];
  153.       this.t_object = this.t_tile.object;
  154.       if(this.t_object)
  155.       {
  156.          _loc3_ = WorldToScreen(this.t_object.pos_x,0,this.t_object.pos_z);
  157.          if(this.hitTest(_loc3_[0] + _root.game._x,_loc3_[1] + _root.game._y,true))
  158.          {
  159.             this.t_object = null;
  160.             this.t_object.doWhenHit(this.speed,this.angle,this.t_tile);
  161.          }
  162.       }
  163.    }
  164.    else
  165.    {
  166.       this._alpha -= 5;
  167.       if(this._alpha <= 0)
  168.       {
  169.          this.removeMovieClip();
  170.       }
  171.    }
  172. };
  173. var map = new Array();
  174. map[0] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  175. map[1] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  176. map[2] = [B,B,B,P,B,B,B,B,P,B,B,B,B,B,B,P,B,B,B,B,P,B,B,B];
  177. map[3] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  178. map[4] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  179. map[5] = [B,B,B,B,B,B,P,B,B,B,B,B,B,B,B,B,B,B,P,B,B,B,B,B];
  180. map[6] = [B,B,P,B,B,B,B,B,B,B,B,B,B,B,P,B,B,B,B,B,B,B,B,B];
  181. map[7] = [B,B,B,P,B,B,B,B,B,B,B,B,B,B,B,P,B,B,B,B,B,B,B,B];
  182. map[8] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  183. map[9] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  184. map[10] = [B,B,B,B,B,B,B,P,B,B,B,B,B,B,B,B,B,B,B,P,B,B,B,B];
  185. map[11] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  186. map[12] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  187. map[13] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  188. map[14] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  189. map[15] = [B,B,B,P,B,B,B,B,P,B,B,B,B,B,B,P,B,B,B,B,P,B,B,B];
  190. map[16] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  191. map[17] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  192. map[18] = [B,B,B,B,B,B,P,B,B,B,B,B,B,B,B,B,B,B,P,B,B,B,B,B];
  193. map[19] = [B,B,P,B,B,B,B,B,B,B,B,B,B,B,P,B,B,B,B,B,B,B,B,B];
  194. map[20] = [B,B,B,P,B,B,B,B,B,B,B,B,B,B,B,P,B,B,B,B,B,B,B,B];
  195. map[21] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  196. map[22] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  197. map[23] = [B,B,B,B,B,B,B,P,B,B,B,B,B,B,B,B,B,B,B,P,B,B,B,B];
  198. map[24] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  199. map[25] = [B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B];
  200. var objects = new Array();
  201. objects[0] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  202. objects[1] = [0,S,0,C,0,0,C,0,0,S,0,0,0,S,0,C,0,0,C,0,0,S,0,0];
  203. objects[2] = [0,C,0,0,0,H,0,0,C,O,0,H,0,C,0,0,0,H,0,0,C,O,0,0];
  204. objects[3] = [0,0,C,C,L,0,H,0,0,0,C,0,0,0,C,C,L,0,H,0,0,0,C,0];
  205. objects[4] = [0,0,0,0,0,0,0,0,0,0,C,0,0,0,0,0,0,0,0,0,0,0,C,0];
  206. objects[5] = [0,H,C,O,0,0,0,O,0,C,0,0,H,0,C,O,0,0,0,O,0,C,0,0];
  207. objects[6] = [0,0,0,L,0,0,C,0,0,C,0,0,0,0,0,L,0,0,C,0,0,C,0,0];
  208. objects[7] = [0,0,L,H,0,C,0,C,0,0,H,0,0,0,L,0,H,C,0,C,0,0,H,0];
  209. objects[8] = [0,0,C,O,0,0,O,0,C,0,C,0,0,0,C,O,0,0,O,0,C,0,C,0];
  210. objects[9] = [0,C,S,0,0,0,C,C,C,0,H,0,0,C,S,0,0,0,C,C,C,0,H,0];
  211. objects[10] = [0,0,0,C,H,0,C,S,C,0,0,0,0,0,0,C,0,H,C,S,C,0,0,0];
  212. objects[11] = [0,0,C,C,0,S,C,C,C,0,O,0,0,H,C,C,0,S,C,C,C,0,O,0];
  213. objects[12] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,H,0,0,0];
  214. objects[13] = [0,0,C,C,0,S,C,C,C,0,H,0,0,0,C,C,0,S,C,C,C,0,O,0];
  215. objects[14] = [0,S,H,C,0,C,C,0,0,S,0,0,0,S,0,C,0,C,C,0,0,S,0,0];
  216. objects[15] = [0,C,0,0,0,0,0,0,C,L,0,0,0,C,0,0,0,H,0,0,C,L,0,0];
  217. objects[16] = [0,C,C,C,0,0,H,0,0,C,C,0,0,C,C,C,0,0,C,0,0,0,C,0];
  218. objects[17] = [0,C,0,0,C,S,0,0,0,C,H,0,0,C,0,0,C,S,0,0,0,C,C,0];
  219. objects[18] = [0,L,C,H,0,0,0,L,C,C,0,0,0,L,C,0,H,0,C,L,0,C,0,0];
  220. objects[19] = [0,0,0,S,C,C,H,C,0,0,0,0,0,0,0,S,C,C,C,C,0,C,0,0];
  221. objects[20] = [0,L,0,0,0,C,0,C,0,0,H,0,0,0,0,S,C,C,C,C,0,H,0,0];
  222. objects[21] = [0,C,C,C,L,0,C,0,C,0,C,0,0,0,C,C,C,H,C,0,C,S,C,0];
  223. objects[22] = [0,C,S,C,0,0,0,C,H,0,0,O,0,C,S,C,0,0,C,C,H,0,0,0];
  224. objects[23] = [0,H,C,C,0,0,C,S,C,0,0,0,C,C,C,C,0,0,0,C,C,0,0,0];
  225. objects[24] = [0,C,C,C,H,S,C,C,C,0,L,0,0,C,C,C,H,S,C,C,C,0,L,0];
  226. objects[25] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  227. var world = new Object();
  228. world.tile_width = 10;
  229. world.tile_height = 10;
  230. world.totaldepth = world.tile_height * map.length;
  231. world.totalwidth = world.tile_width * map[0].length;
  232. var screen = new Object();
  233. screen.scroll_x = 0;
  234. screen.scroll_y = 0;
  235. screen.keepplayerat_x = 200;
  236. screen.keepplayerat_y = 200;
  237. var player = new Object();
  238. player.car_x = 55;
  239. player.car_y = 0;
  240. player.car_z = 55;
  241. player.speed = 0;
  242. player.maxspeed = 2;
  243. player.accelrate = 0.2;
  244. player.decelrate = 0.9;
  245. player.angle = 0;
  246. player.anglechange = 0;
  247. player.maxanglechange = 10;
  248. player.anglechangerate = 7;
  249. player.allowturns = true;
  250. stop();
  251.