169 lines
No EOL
3.8 KiB
Text
169 lines
No EOL
3.8 KiB
Text
|
|
// LEGS = left arm
|
|
// HEAD = right arm
|
|
|
|
object vehicle_platypus_cockpit : vehicle_basic_cockpit {
|
|
void preinit();
|
|
void destroy();
|
|
|
|
void AnimThread();
|
|
|
|
void OnEntered();
|
|
|
|
float HideSurface( string surfaceName );
|
|
void ShowSurface( float id );
|
|
|
|
string wheelAnim;
|
|
string leverAnim;
|
|
|
|
float wheelAnimFrames;
|
|
float wheelAnimFramesMiddle;
|
|
|
|
float leverAnimFrames;
|
|
float leverAnimFrameMiddle;
|
|
|
|
float surfaceId0;
|
|
float surfaceId1;
|
|
float surfaceId2;
|
|
float surfaceId3;
|
|
};
|
|
|
|
void vehicle_platypus_cockpit::preinit() {
|
|
surfaceId0 = -1;
|
|
surfaceId1 = -1;
|
|
surfaceId2 = -1;
|
|
surfaceId3 = -1;
|
|
}
|
|
|
|
void vehicle_platypus_cockpit::destroy() {
|
|
ShowSurface( surfaceId0 );
|
|
ShowSurface( surfaceId1 );
|
|
ShowSurface( surfaceId2 );
|
|
ShowSurface( surfaceId3 );
|
|
|
|
sys.killThread( "vehicle_platypus_cockpit::AnimThread" );
|
|
}
|
|
|
|
void vehicle_platypus_cockpit::OnEntered() {
|
|
wheelAnim = "left_to_right";
|
|
leverAnim = "reverse_to_forward";
|
|
|
|
wheelAnimFrames = getNumFrames( wheelAnim ) - 2;
|
|
wheelAnimFramesMiddle = wheelAnimFrames / 2;
|
|
|
|
leverAnimFrames = getNumFrames( leverAnim ) - 2;
|
|
leverAnimFrameMiddle = leverAnimFrames / 2;
|
|
|
|
surfaceId0 = HideSurface( getKey( "surface_name0" ) );
|
|
surfaceId1 = HideSurface( getKey( "surface_name1" ) );
|
|
surfaceId2 = HideSurface( getKey( "surface_name2" ) );
|
|
surfaceId3 = HideSurface( getKey( "surface_name3" ) );
|
|
|
|
thread AnimThread();
|
|
}
|
|
|
|
void vehicle_platypus_cockpit::AnimThread() {
|
|
sys.threadName( "vehicle_platypus_cockpit::AnimThread" );
|
|
|
|
float length =
|
|
playAnim( ANIMCHANNEL_LEGS, "into" );
|
|
playAnim( ANIMCHANNEL_HEAD, "into" );
|
|
|
|
sys.wait( length );
|
|
|
|
float wheelAngle = 0.f;
|
|
float leverAngle = 0.f;
|
|
|
|
while ( true ) {
|
|
entity driver = myVehicle.getDriver();
|
|
|
|
vector move;
|
|
if ( driver != $null_entity ) {
|
|
move = driver.getMove();
|
|
} else {
|
|
move = '0 0 0';
|
|
}
|
|
|
|
|
|
|
|
float oldWheelAngle = wheelAngle;
|
|
|
|
if ( move_y < 0 ) {
|
|
wheelAngle = wheelAngle - 1.f * sys.getFrameTime();
|
|
if ( wheelAngle < -1.f ) {
|
|
wheelAngle = -1.f;
|
|
}
|
|
} else if ( move_y > 0 ) {
|
|
wheelAngle = wheelAngle + 1.f * sys.getFrameTime();
|
|
if ( wheelAngle > 1.f ) {
|
|
wheelAngle = 1.f;
|
|
}
|
|
} else {
|
|
if ( wheelAngle > 0.f ) {
|
|
wheelAngle = wheelAngle - 0.8 * sys.getFrameTime();
|
|
if ( wheelAngle < 0.f ) {
|
|
wheelAngle = 0.f;
|
|
}
|
|
} else if ( wheelAngle < 0.f ) {
|
|
wheelAngle = wheelAngle + 0.8 * sys.getFrameTime();
|
|
if ( wheelAngle > 0.f ) {
|
|
wheelAngle = 0.f;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( oldWheelAngle != wheelAngle ) {
|
|
setAnimFrame( wheelAnim, ANIMCHANNEL_LEGS, ( 1 + wheelAngle ) * wheelAnimFramesMiddle );
|
|
}
|
|
|
|
|
|
|
|
|
|
float oldLeverAngle = leverAngle;
|
|
|
|
if ( move_x < 0 ) {
|
|
leverAngle = leverAngle - 2.f * sys.getFrameTime();
|
|
if ( leverAngle < -1.f ) {
|
|
leverAngle = -1.f;
|
|
}
|
|
} else if ( move_x > 0 ) {
|
|
leverAngle = leverAngle + 2.f * sys.getFrameTime();
|
|
if ( leverAngle > 1.f ) {
|
|
leverAngle = 1.f;
|
|
}
|
|
} else {
|
|
if ( leverAngle > 0.f ) {
|
|
leverAngle = leverAngle - 1.8 * sys.getFrameTime();
|
|
if ( leverAngle < 0.f ) {
|
|
leverAngle = 0.f;
|
|
}
|
|
} else if ( leverAngle < 0.f ) {
|
|
leverAngle = leverAngle + 1.8 * sys.getFrameTime();
|
|
if ( leverAngle > 0.f ) {
|
|
leverAngle = 0.f;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( oldLeverAngle != leverAngle ) {
|
|
setAnimFrame( leverAnim, ANIMCHANNEL_HEAD, ( 1 + leverAngle ) * leverAnimFrameMiddle );
|
|
}
|
|
|
|
sys.waitFrame();
|
|
}
|
|
}
|
|
|
|
float vehicle_platypus_cockpit::HideSurface( string surfaceName ) {
|
|
float id = -1;
|
|
if ( surfaceName != "" ) {
|
|
id = myVehicle.getSurfaceId( surfaceName );
|
|
myVehicle.hideSurface( id );
|
|
}
|
|
return id;
|
|
}
|
|
|
|
void vehicle_platypus_cockpit::ShowSurface( float id ) {
|
|
if ( id != -1 ) {
|
|
myVehicle.showSurface( id );
|
|
}
|
|
} |