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

  1. timer.gameStartTime = getTimer();
  2. timer.gameDuration = 60000;
  3. timer.gameTimerStarted = false;
  4. timer.display = 60;
  5. timer.onEnterFrame = function()
  6. {
  7.    gameTimeLeft = this.gameDuration - (getTimer() - this.gameStartTime);
  8.    if(gameTimeLeft <= 0)
  9.    {
  10.       timer.display = 0;
  11.       this._xscale = 0;
  12.       _root.timer.onEnterFrame = null;
  13.       _root.game.player.onEnterFrame = null;
  14.       _root.gotoAndPlay("game_over");
  15.    }
  16.    else
  17.    {
  18.       secondsleft = Math.ceil(gameTimeLeft / 1000);
  19.       timer.display = secondsleft;
  20.       this._xscale = secondsleft * 1000 / this.gameDuration * 100;
  21.    }
  22. };
  23. game.player.onEnterFrame = function()
  24. {
  25.    if(Key.isDown(38))
  26.    {
  27.       this.speed = Math.min(this.maxspeed,this.speed + this.accelrate);
  28.    }
  29.    else if(Key.isDown(40))
  30.    {
  31.       this.speed = Math.max(- this.maxspeed,this.speed - this.accelrate);
  32.    }
  33.    else if(Math.abs(this.speed) <= 0.1)
  34.    {
  35.       this.speed = 0;
  36.    }
  37.    else
  38.    {
  39.       this.speed *= this.decelrate;
  40.    }
  41.    if(this.car_tile.effects.drag)
  42.    {
  43.       this.speed -= this.speed * this.car_tile.effects.drag;
  44.    }
  45.    if(Key.isDown(39) && this.allowturns == true)
  46.    {
  47.       this.speedpercent = this.speed / this.maxspeed;
  48.       this.anglechange = Math.min(this.maxanglechange,this.maxanglechange * this.speedpercent);
  49.       this.angle += this.anglechange;
  50.    }
  51.    else if(Key.isDown(37) && this.allowturns == true)
  52.    {
  53.       this.speedpercent = this.speed / this.maxspeed;
  54.       this.anglechange = Math.max(- this.maxanglechange,(- this.maxanglechange) * this.speedpercent);
  55.       this.angle += this.anglechange;
  56.    }
  57.    if(this.angle < 0)
  58.    {
  59.       this.angle = 360 + this.angle;
  60.    }
  61.    this.angle %= 360;
  62.    this.stepfactor_x = Math.sin(this.angle * 3.141592653589793 / 180);
  63.    this.stepfactor_z = Math.cos(this.angle * 3.141592653589793 / 180);
  64.    this.t_car_x = this.car_x + this.speed * this.stepfactor_x;
  65.    this.t_car_z = this.car_z + this.speed * this.stepfactor_z;
  66.    if(this.speed >= 0)
  67.    {
  68.       this.t_bumper_x = this.t_car_x + 6 * this.stepfactor_x;
  69.       this.t_bumper_z = this.t_car_z + 6 * this.stepfactor_z;
  70.    }
  71.    else
  72.    {
  73.       this.t_bumper_x = this.t_car_x + -6 * this.stepfactor_x;
  74.       this.t_bumper_z = this.t_car_z + -6 * this.stepfactor_z;
  75.    }
  76.    this.t_car_row = Math.floor(this.t_car_z / _root.world.tile_height);
  77.    this.t_car_col = Math.floor(this.t_car_x / _root.world.tile_width);
  78.    this.t_car_tile = _root.game["tile_" + this.t_car_row + "_" + this.t_car_col];
  79.    this.t_bumper_row = Math.floor(this.t_bumper_z / _root.world.tile_height);
  80.    this.t_bumper_col = Math.floor(this.t_bumper_x / _root.world.tile_width);
  81.    this.t_bumper_tile = _root.game["tile_" + this.t_bumper_row + "_" + this.t_bumper_col];
  82.    this.t_bumper_object = this.t_bumper_tile.object;
  83.    if(!this.t_bumper_tile.oktodrive)
  84.    {
  85.       this.speed = - this.speed * 0.8;
  86.       this.allowturns = false;
  87.       clearInterval(intervalID);
  88.       var intervalID = setInterval(function()
  89.       {
  90.          _root.game.player.allowturns = true;
  91.          clearInterval(intervalID);
  92.       }
  93.       ,250);
  94.       return undefined;
  95.    }
  96.    this.car_x = this.t_car_x;
  97.    this.car_z = this.t_car_z;
  98.    this.bumper_x = this.t_bumper_x;
  99.    this.bumper_z = this.t_bumper_z;
  100.    this.car_row = this.t_car_row;
  101.    this.car_col = this.t_car_col;
  102.    this.car_tile = this.t_car_tile;
  103.    this.bumper_row = this.t_bumper_row;
  104.    this.bumper_col = this.t_bumper_col;
  105.    this.bumper_tile = this.t_bumper_tile;
  106.    this.bumper_object = this.t_bumper_object;
  107.    this.bumper_local_x = this.bumper_x % _root.world.tile_width;
  108.    this.bumper_local_z = this.bumper_z % _root.world.tile_height;
  109.    if(this.bumper_object)
  110.    {
  111.       var _loc3_ = WorldToScreen(this.bumper_object.pos_x,0,this.bumper_object.pos_z);
  112.       if(this.car_collider.hitTest(_loc3_[0] + _root.game._x,_loc3_[1] + _root.game._y,true))
  113.       {
  114.          this.bumper_object.doWhenHit(this.speed,this.angle,this.bumper_tile);
  115.       }
  116.    }
  117.    this.pan_pos_x = this.car_x + 7 * this.speed * this.stepfactor_x;
  118.    this.pan_pos_z = this.car_z + 7 * this.speed * this.stepfactor_z;
  119.    _loc3_ = WorldToScreen(this.pan_pos_x,0,this.pan_pos_z);
  120.    _root.focus_x = _loc3_[0];
  121.    _root.focus_y = _loc3_[1];
  122.    _loc3_ = WorldToScreen(this.car_x,this.car_y,this.car_z);
  123.    var _loc5_ = Math.floor((world.totaldepth - this.car_z) * 1000 + this.car_x);
  124.    this.swapDepths(_loc5_);
  125.    var _loc4_ = Math.round(this.angle * 0.1) + 1;
  126.    this.gotoAndStop(_loc4_);
  127.    this.car_collider.gotoAndStop(_loc4_);
  128.    this._x = _loc3_[0];
  129.    this._y = _loc3_[1] + random(this.car_tile.effects.bumpy * Math.abs(this.speed));
  130. };
  131. stop();
  132.