home *** CD-ROM | disk | FTP | other *** search
- class Vehicle extends MovieClip
- {
- var currentSpeed;
- var heading;
- var direction;
- var directionLatency;
- var steeringPosition;
- var carNumber;
- var startX;
- var startY;
- var BRAKE_POWER;
- var MAX_SPEED;
- var MAX_SPEED_REVERSE;
- var ACCELERATION;
- var REVERSE_ACCELERATION;
- var ROAD_WIPEOUT_THRESHOLD;
- var GRASS_WIPEOUT_THRESHOLD;
- var tyres;
- var turningLeft;
- var turningRight;
- var accelerating;
- var braking;
- var wipeOutThreshold;
- var lostIt;
- var steeringResponse;
- var STEERING_RATE_OF_CHANGE = 1;
- var STEERING_MAX = 8;
- var STEERING_RANDOM_ELEMENT = 2;
- var FRICTION = 0.1;
- var STEERING_SNAP = 10;
- var SKIDMARK_THRESHOLD = 50;
- var SKIDMARK_LIMIT = 500;
- var SKIDMARK_ADJUSTMENT = 8;
- var MOUSE_DISTANCE_LIMIT = 200;
- var WIPE_OUT_FRICTION = 0.2;
- var SPEED_BLEED_STRENGTH = 0.3;
- var SPEED_BLEED_MAX = 60;
- var MULTIPLIER_TIMEOUT = 30;
- var DRIFT = 3;
- var drifting = false;
- var onGrass = false;
- var onBump = false;
- var onOil = false;
- var x = 0;
- var y = 0;
- var targetSpeed = 0;
- var currentSkidmarkDepth = 0;
- var active = false;
- var lastGateHit = 0;
- var driftTimer = 0;
- var noDriftTimer = 0;
- var reversing = false;
- var loseIt = false;
- var BUMP_WIPEOUT_THRESHOLD = 5;
- function Vehicle()
- {
- super();
- this.currentSpeed = 0;
- this.heading = 0;
- this.direction = 0;
- this.directionLatency = 0;
- this.steeringPosition = 0;
- this.gotoAndStop(this.carNumber);
- this.startX = this._x;
- this.startY = this._y;
- this.BRAKE_POWER = _root.carData_array[this.carNumber].BRAKE_POWER;
- this.MAX_SPEED = _root.carData_array[this.carNumber].MAX_SPEED;
- this.MAX_SPEED_REVERSE = _root.carData_array[this.carNumber].MAX_SPEED_REVERSE;
- this.ACCELERATION = _root.carData_array[this.carNumber].ACCELERATION;
- this.REVERSE_ACCELERATION = _root.carData_array[this.carNumber].REVERSE_ACCELERATION;
- this.ROAD_WIPEOUT_THRESHOLD = _root.carData_array[this.carNumber].ROAD_WIPEOUT_THRESHOLD;
- this.GRASS_WIPEOUT_THRESHOLD = _root.carData_array[this.carNumber].GRASS_WIPEOUT_THRESHOLD;
- this.tyres = _root.carData_array[this.carNumber].TYRES;
- }
- function updatePosition()
- {
- var newXPosition = this._x + Math.sin(this.direction * 3.141592653589793 / 180) * this.currentSpeed;
- var newYPosition = this._y - Math.cos(this.direction * 3.141592653589793 / 180) * this.currentSpeed;
- this._x = newXPosition;
- this._y = newYPosition;
- this.x = this._x;
- this.y = this._y;
- this._rotation = this.heading;
- this.turningLeft = false;
- this.turningRight = false;
- if(!_root.ghostPlayback)
- {
- if(Key.isDown(37))
- {
- this.turningLeft = true;
- }
- if(Key.isDown(39))
- {
- this.turningRight = true;
- }
- if(Key.isDown(38))
- {
- if(_root.gameTicks == 1)
- {
- _root.engineUp_sound.start(audioStartPointUp,1);
- }
- if(this.accelerating == false)
- {
- var acceleratorHit = true;
- }
- else
- {
- var acceleratorHit = false;
- }
- this.accelerating = true;
- }
- else
- {
- if(this.accelerating == true)
- {
- var acceleratorRelease = true;
- }
- else
- {
- var acceleratorRelease = false;
- }
- this.accelerating = false;
- }
- if(Key.isDown(40))
- {
- this.braking = true;
- }
- else
- {
- this.braking = false;
- }
- }
- else
- {
- if(_root.keyPlayback_array[_root.gameTicks] & 1)
- {
- this.turningLeft = true;
- }
- if(_root.keyPlayback_array[_root.gameTicks] & 2)
- {
- this.turningRight = true;
- }
- if(_root.keyPlayback_array[_root.gameTicks] & 4)
- {
- if(this.accelerating == false)
- {
- var acceleratorHit = true;
- }
- else
- {
- var acceleratorHit = false;
- }
- this.accelerating = true;
- }
- else
- {
- if(this.accelerating == true)
- {
- var acceleratorRelease = true;
- }
- else
- {
- var acceleratorRelease = false;
- }
- this.accelerating = false;
- }
- if(_root.keyPlayback_array[_root.gameTicks] & 8)
- {
- this.braking = true;
- }
- else
- {
- this.braking = false;
- }
- }
- if(acceleratorHit and !_root.raceStarted and !_root.garage)
- {
- trace("STARTED AT " + _root.gameTicks);
- _root.startBonus = (10 - _root.gameTicks) * 1000;
- trace("garage is " + _root.garage);
- if(_root.startBonus <= 0 or _root.garage or _root.donutChallenge)
- {
- _root.startBonus = "";
- }
- else
- {
- _root.bonusPoints(_root.startBonus);
- }
- _root.raceStarted = true;
- }
- if(_root.gameTicks > 60)
- {
- _root.startBonus = "";
- }
- var audioStartPointUp = this.currentSpeed / this.MAX_SPEED * 3;
- var audioStartPointDown = 3 - audioStartPointUp;
- if(acceleratorHit)
- {
- trace("trigger");
- _root.engineDown_sound.stop();
- _root.idle_sound.stop();
- _root.engineUp_sound.stop();
- _root.engineUp_sound.start(audioStartPointUp,1);
- }
- if(acceleratorRelease)
- {
- _root.engineUp_sound.stop();
- _root.topSpeed_sound.stop();
- _root.engineDown_sound.stop();
- _root.engineDown_sound.start(audioStartPointDown,1);
- }
- if(this.loseIt)
- {
- _root.engineUp_sound.stop();
- _root.topSpeed_sound.stop();
- _root.engineDown_sound.stop();
- _root.engineDown_sound.start(audioStartPointDown,1);
- this.loseIt = false;
- }
- if(this.onGrass)
- {
- this.wipeOutThreshold = this.GRASS_WIPEOUT_THRESHOLD;
- }
- else
- {
- this.wipeOutThreshold = this.ROAD_WIPEOUT_THRESHOLD;
- }
- switch(this.tyres)
- {
- case 1:
- break;
- case 2:
- this.wipeOutThreshold += 10;
- break;
- case 3:
- this.wipeOutThreshold += 5;
- }
- if(this.onBump)
- {
- this.currentSpeed *= Math.random();
- this.wipeOutThreshold = this.BUMP_WIPEOUT_THRESHOLD;
- }
- if(this.onOil)
- {
- this.lostIt = true;
- }
- if(!this.lostIt)
- {
- if(this.accelerating)
- {
- if(this.currentSpeed < this.MAX_SPEED)
- {
- this.currentSpeed += this.ACCELERATION;
- }
- }
- else if(this.braking)
- {
- if(this.currentSpeed > 0)
- {
- this.currentSpeed -= this.BRAKE_POWER;
- if(this.currentSpeed < 0)
- {
- }
- }
- else
- {
- this.reversing = true;
- this.currentSpeed -= this.REVERSE_ACCELERATION;
- }
- }
- else if(this.currentSpeed > 0 and !this.lostIt)
- {
- this.reversing = false;
- this.currentSpeed -= this.FRICTION;
- if(this.currentSpeed < 0)
- {
- this.currentSpeed = 0;
- }
- }
- }
- if(this.lostIt)
- {
- this.currentSpeed -= this.WIPE_OUT_FRICTION;
- }
- if(this.lostIt)
- {
- if(this.steeringPosition > 0)
- {
- this.turningRight = true;
- }
- else
- {
- this.turningLeft = true;
- }
- }
- if(this.turningLeft)
- {
- if(this.steeringPosition > - this.STEERING_MAX)
- {
- this.steeringPosition -= this.STEERING_RATE_OF_CHANGE;
- }
- }
- else if(this.turningRight)
- {
- if(this.steeringPosition < this.STEERING_MAX)
- {
- this.steeringPosition += this.STEERING_RATE_OF_CHANGE;
- }
- }
- else
- {
- if(this.steeringPosition > 0)
- {
- this.steeringPosition -= this.STEERING_RATE_OF_CHANGE;
- }
- else if(this.steeringPosition < 0)
- {
- this.steeringPosition += this.STEERING_RATE_OF_CHANGE;
- }
- if(Math.abs(this.steeringPosition) < this.STEERING_RATE_OF_CHANGE)
- {
- this.steeringPosition = 0;
- }
- }
- this.heading += this.currentSpeed / this.MAX_SPEED * this.steeringPosition;
- this.heading = Math.round(this.heading);
- this.steeringResponse = this.DRIFT - this.currentSpeed / this.MAX_SPEED * 2 + this.directionLatency / 90 * 4;
- if(!this.lostIt)
- {
- if(this.direction < this.heading)
- {
- this.direction += this.steeringResponse;
- this.directionLatency = this.heading - this.direction;
- }
- else if(this.direction > this.heading)
- {
- this.direction -= this.steeringResponse;
- this.directionLatency = this.direction - this.heading;
- }
- }
- if(this.currentSpeed < 0)
- {
- if(this.currentSpeed < - this.MAX_SPEED_REVERSE)
- {
- this.currentSpeed = - this.MAX_SPEED_REVERSE;
- }
- if(this.currentSpeed < - this.FRICTION and !this.reversing)
- {
- this.currentSpeed = 0;
- }
- else
- {
- this.currentSpeed += this.FRICTION;
- }
- }
- if(this.currentSpeed <= 0)
- {
- this.direction = this.heading;
- this.directionLatency = 0;
- this.lostIt = false;
- this.accelerating = false;
- }
- if(this.directionLatency > this.SKIDMARK_THRESHOLD and !this.lostIt)
- {
- this.currentSkidmarkDepth = this.currentSkidmarkDepth + 1;
- _root.newClipName = "tracks" + this.currentSkidmarkDepth;
- if(_root.leaveSkidMarks)
- {
- if(this.onGrass)
- {
- _root.game_mc.tracks_grass.duplicateMovieClip(_root.newClipName,this.currentSkidmarkDepth);
- }
- else
- {
- _root.game_mc.tracks_road.duplicateMovieClip(_root.newClipName,this.currentSkidmarkDepth);
- }
- var skidAmount = this.directionLatency - this.SKIDMARK_THRESHOLD;
- eval("_root.game_mc." + _root.newClipName)._x = this._x;
- eval("_root.game_mc." + _root.newClipName)._y = this._y;
- if(this.direction < this.heading)
- {
- eval("_root.game_mc." + _root.newClipName)._rotation = this.direction - this.SKIDMARK_ADJUSTMENT;
- }
- else
- {
- eval("_root.game_mc." + _root.newClipName)._rotation = this.direction + this.SKIDMARK_ADJUSTMENT;
- }
- eval("_root.game_mc." + _root.newClipName)._alpha = skidAmount;
- _root.screech_sound.setVolume(skidAmount);
- }
- }
- if(!this.lostIt)
- {
- var speedBleed = this.SPEED_BLEED_STRENGTH * (Math.abs(this.directionLatency) / this.SPEED_BLEED_MAX);
- if(speedBleed > this.SPEED_BLEED_STRENGTH)
- {
- speedBleed = this.SPEED_BLEED_STRENGTH;
- }
- if(speedBleed < 0.1)
- {
- speedBleed = 0;
- }
- this.currentSpeed -= speedBleed;
- }
- var pivotShift = (this.wipeOutThreshold - Math.abs(this.directionLatency)) / this.wipeOutThreshold * 23;
- _root.originalCar.car._y = -39 + pivotShift;
- if(this.directionLatency > this.SKIDMARK_THRESHOLD and !this.lostIt)
- {
- if(!this.drifting)
- {
- _root.game_mc.video_mc.gotoAndPlay("car");
- _root.currentDrift = 0;
- _root.screech_sound.setVolume(0);
- _root.screech_sound.start(0,999);
- this.drifting = true;
- if(this.noDriftTimer > this.MULTIPLIER_TIMEOUT)
- {
- this.driftTimer = 0;
- }
- }
- this.driftTimer = this.driftTimer + 1;
- this.noDriftTimer = 0;
- _root.driftScoreMultiplier = Math.round(this.driftTimer / _root.DRIFT_SCORE_MULTIPLIER_INTERVAL);
- if(_root.driftScoreMultiplier > 1)
- {
- _root.driftScoreMultiplier_str = _root.driftScoreMultiplier + "X";
- }
- else
- {
- _root.driftScoreMultiplier_str = "";
- }
- switch(this.tyres)
- {
- case 1:
- var tyreBonus = 0;
- break;
- case 2:
- var tyreBonus = 10;
- break;
- case 3:
- var tyreBonus = 20;
- }
- _root.currentDrift += Math.round(_root.driftScoreMultiplier * (2 * (this.directionLatency - this.SKIDMARK_THRESHOLD + tyreBonus)));
- if(_root.currentDrift > 0 and !_root.garage)
- {
- _root.currentDrift_str = _root.convertNumberDisplay(_root.currentDrift);
- }
- else
- {
- _root.currentDrift_str = "";
- }
- }
- else
- {
- _root.screech_sound.stop();
- this.noDriftTimer = this.noDriftTimer + 1;
- if(this.drifting)
- {
- _root.game_mc.video_mc.gotoAndPlay("turn");
- trace("drift was " + _root.currentDrift);
- if(_root.donutChallenge)
- {
- _root.score = _root.currentDrift;
- }
- else
- {
- _root.score += _root.currentDrift;
- }
- _root.currentDrift = 0;
- _root.currentDrift_str = "";
- _root.driftScoreMultiplier_str = "";
- if(_root.donutChallenge)
- {
- if(_root.bestDonut < _root.score)
- {
- _root.bestDonut = _root.score;
- _root.so.data.bestDonut = _root.score;
- }
- if(_root.game_mc.car.currentSkidmarkDepth > 0)
- {
- var i = 1;
- while(i <= _root.game_mc.car.currentSkidmarkDepth)
- {
- eval("_root.game_mc.tracks" + i).removeMovieClip();
- i++;
- }
- }
- }
- }
- this.drifting = false;
- _root.screech_sound.setVolume(0);
- }
- _root.directionLatency = this.directionLatency;
- if(Math.abs(this.directionLatency) > this.wipeOutThreshold and !this.lostIt)
- {
- this.loseIt = true;
- this.lostIt = true;
- }
- if(this.heading > 360 and this.direction > 360)
- {
- this.heading -= 360;
- this.direction -= 360;
- }
- if(this.heading < 0 and this.direction < 0)
- {
- this.heading += 360;
- this.direction += 360;
- }
- }
- function setCarStats(param_carNumber)
- {
- this.BRAKE_POWER = _root.carData_array[param_carNumber].BRAKE_POWER;
- this.MAX_SPEED = _root.carData_array[param_carNumber].MAX_SPEED;
- this.MAX_SPEED_REVERSE = _root.carData_array[param_carNumber].MAX_SPEED_REVERSE;
- this.ACCELERATION = _root.carData_array[param_carNumber].ACCELERATION;
- this.REVERSE_ACCELERATION = _root.carData_array[param_carNumber].REVERSE_ACCELERATION;
- this.ROAD_WIPEOUT_THRESHOLD = _root.carData_array[param_carNumber].ROAD_WIPEOUT_THRESHOLD;
- this.GRASS_WIPEOUT_THRESHOLD = _root.carData_array[param_carNumber].GRASS_WIPEOUT_THRESHOLD;
- this.tyres = _root.carData_array[this.carNumber].TYRES;
- }
- }
-