home *** CD-ROM | disk | FTP | other *** search
- class CWheel extends MovieClip
- {
- var mRadius;
- var pRadius;
- var mCircumference;
- var mFriction;
- var mMass;
- var mDelta;
- var mInertia;
- var mPosition;
- var mRotation;
- var mAngularVelocity;
- var mTrackPosition;
- var mTrackPositionIndex;
- var mControlLeft;
- var mControlRight;
- var mArena;
- var _Interior;
- var mCollide;
- var mDeltaTravelledTotal;
- var mDeltaTravelled;
- var mCount = 0;
- static var mTime = 1;
- static var GARWIN_ALPHA = 0.4;
- static var Ex = 0.2;
- static var Ey = 0.4;
- function CWheel()
- {
- super();
- this.mRadius = this._width / 2;
- this.pRadius = new flash.geom.Point(this.mRadius,this.mRadius);
- this.mCircumference = this.mRadius * 2 * 3.141592653589793;
- this.mFriction = 1;
- this.mMass = 1;
- this.mDelta = new flash.geom.Point(0,0);
- this.mInertia = new flash.geom.Point(0,0);
- this.mPosition = new flash.geom.Point(this._x,this._y);
- this.mRotation = 0;
- this.mAngularVelocity = 0;
- this.mTrackPosition = new Array(20);
- this.mTrackPositionIndex = 0;
- this.mControlLeft = this.mControlRight = false;
- this._visible = true;
- }
- function Process()
- {
- var _loc5_ = this.mPosition.clone();
- this.mCount = 0;
- this.mDelta = this.mDelta.add(this.mArena.mGravity);
- this.mDelta.x += this.mAngularVelocity / 1000;
- this.mAngularVelocity *= 0.99;
- this.mRotation += this.mAngularVelocity;
- _root.mDebug = Math.round(this.mAngularVelocity) + ", " + Math.round(this.mDelta.length);
- if(Math.abs(this.mAngularVelocity) >= 25)
- {
- var _loc4_ = Math.round(Math.abs(this.mAngularVelocity) / 25);
- if(_loc4_ > 4)
- {
- _loc4_ = 4;
- }
- this._Interior.filters = [new flash.filters.BlurFilter(_loc4_,_loc4_,3)];
- }
- else
- {
- this._Interior.filters = [];
- }
- this.mCount = 0;
- this.mCollide = false;
- this.Collide();
- this.mArena.mMap.WheelCollide(this,_loc5_,this.mPosition);
- this._x = this.mPosition.x;
- this._y = this.mPosition.y;
- this._Interior._rotation = this.mRotation;
- this.mTrackPositionIndex = (this.mTrackPositionIndex + 1) % this.mTrackPosition.length;
- this.mTrackPosition[this.mTrackPositionIndex] = this.mPosition.clone();
- if(_global.mKeyControl)
- {
- this.mControlLeft = Key.isDown(37);
- this.mControlRight = Key.isDown(39);
- }
- if(this.mControlLeft)
- {
- if(this.mAngularVelocity > 0)
- {
- this.mAngularVelocity = 0;
- }
- this.mAngularVelocity -= 4;
- this.mControlLeft = false;
- }
- if(this.mControlRight)
- {
- if(this.mAngularVelocity < 0)
- {
- this.mAngularVelocity = 0;
- }
- this.mAngularVelocity += 4;
- this.mControlRight = false;
- }
- }
- function Collide(tNotThisLine)
- {
- this.mDeltaTravelledTotal = this.mDelta.length;
- if(tNotThisLine == undefined)
- {
- this.mDeltaTravelled = 1;
- }
- var _loc5_ = new flash.geom.Point(this.mDelta.x * this.mDeltaTravelled,this.mDelta.y * this.mDeltaTravelled);
- var _loc6_ = this.mPosition.add(_loc5_);
- var _loc7_ = this.mArena.mLineManager.GetLineList(this.mPosition,_loc6_,this.pRadius);
- var _loc2_ = CLine.WheelToLineList(_loc7_,this.mPosition,_loc6_,this.mRadius);
- if(_loc2_.length > 1)
- {
- trace(" ********* 2 Intersections ***************");
- }
- for(var _loc4_ in _loc2_)
- {
- if(tNotThisLine != _loc2_[_loc4_])
- {
- if(this.LineCollide(_loc2_[_loc4_]))
- {
- this.mDeltaTravelled -= flash.geom.Point.distance(this.mPosition,_loc2_[_loc4_].mPointOfIntersection) / this.mDeltaTravelledTotal;
- this.mPosition = _loc2_[_loc4_].mPointOfIntersection;
- if(this.mDeltaTravelled <= 0)
- {
- this.mDeltaTravelled = 0;
- }
- this.Collide(_loc2_[_loc4_]);
- return undefined;
- }
- }
- }
- this.mPosition = CLine.CollisionError(_loc7_,this.mPosition,_loc5_);
- if(this.mArena.mState == "stop")
- {
- trace("mDelta = " + this.mDelta);
- trace("nDelta = " + _loc5_);
- trace("nLineList = " + _loc2_.length);
- trace("nLineList[0].POI = " + _loc2_[0].mPointOfIntersection);
- trace("tNotThisLine.POI = " + tNotThisLine.mPointOfIntersection);
- }
- }
- function LineCollide(tLine, tDeflectOnly)
- {
- if(tLine == undefined)
- {
- return false;
- }
- var _loc8_ = tLine.mMatrix.transformPoint(tLine.mP1);
- var _loc7_ = tLine.mMatrix.transformPoint(tLine.mP2);
- var _loc6_ = tLine.mMatrix.transformPoint(this.mPosition);
- var _loc3_ = tLine.mMatrix.transformPoint(this.mDelta);
- var _loc5_ = this.mAngularVelocity * 3.141592653589793 / 180;
- _loc3_.y = this.computeVyGarwin(_loc3_.y);
- _loc3_.x = this.computeVxGarwin(_loc3_.x,_loc5_,this.mRadius);
- this.mAngularVelocity = this.computeAVGarwin(_loc3_.x,_loc5_,this.mRadius) * 180 / 3.141592653589793;
- this.mDelta = tLine.iMatrix.transformPoint(_loc3_);
- tLine.mOnline = _loc3_.y != 0 ? false : true;
- if(tLine.mOnline)
- {
- var _loc4_ = new flash.geom.Point(tLine.mP2.x - tLine.mP1.x,tLine.mP2.y - tLine.mP1.y);
- _loc4_.normalize(_loc3_.x < 0 ? - this.mDelta.length : this.mDelta.length);
- this.mDelta = _loc4_;
- }
- this.mCollide = true;
- return true;
- }
- function computeVxGarwin(vx, av, r)
- {
- return ((1 - CWheel.GARWIN_ALPHA * CWheel.Ex) * vx + CWheel.GARWIN_ALPHA * (1 + CWheel.Ex) * r * av) / (1 + CWheel.GARWIN_ALPHA) * this.mFriction;
- }
- function computeVyGarwin(vy)
- {
- var _loc1_ = - CWheel.Ey * vy;
- if(_loc1_ >= -5)
- {
- _loc1_ = 0;
- }
- return _loc1_;
- }
- function computeAVGarwin(vx, av, r)
- {
- return ((1 + CWheel.Ex) * vx + (CWheel.GARWIN_ALPHA - CWheel.Ex) * r * av) / (r * (1 + CWheel.GARWIN_ALPHA)) * this.mFriction;
- }
- }
-