// File : DogFight.c // Author : John Wojcik ( QuietBloke ) // Created : September 2000 // Desc : My first game written using my 2D Game framework. // The game is very simple. Two biplanes battle it out in the // Yaroze sky for air supremacy. // // History : // Date Author Description // -------- --------------- ---------------------------------------- #include #include #include "fw.h" #include "pad.h" #include "Dogfight.h" #include "PlaneMov.h" void MovePlane ( int CurrentPlayer ) { int TargetSpeedModifier; int PlaneAngle; PlaneAngle = fwActorGetAngle( PlaneActor[CurrentPlayer] ); // Sin/Cos functions return a value between 0 and 255 TargetSpeedModifier = ( fwAngleGetCos ( PlaneAngle ) * fwAngleGetCos ( PlaneAngle ) ) >> 8; // Modifier becomes a value between 0 and .25 * PlaneAcceleration TargetSpeedModifier = (TargetSpeedModifier * PlaneAcceleration ) >> 10; } void AcceleratePlane ( int CurrentPlayer ) { int TempSpeed; int TargetSpeedModifier; int AllowedSpeed; int PlaneAngle; // Before we do anything decelerate the plane ( Plane drag ) TempSpeed = fwAnimateGetChangeValue( XPlaneAnim[CurrentPlayer] ); TempSpeed = TempSpeed * PlaneDeceleration / 100; fwAnimateSetChangeValue ( XPlaneAnim[CurrentPlayer], TempSpeed ); TempSpeed = fwAnimateGetChangeValue( YPlaneAnim[CurrentPlayer] ); TempSpeed = TempSpeed * PlaneDeceleration / 100; fwAnimateSetChangeValue ( YPlaneAnim[CurrentPlayer], TempSpeed ); PlaneAngle = fwActorGetAngle( PlaneActor[CurrentPlayer] ); // Sin/Cos functions return a value between 0 and 255 TargetSpeedModifier = ( fwAngleGetCos ( PlaneAngle ) * fwAngleGetCos ( PlaneAngle ) ) >> 8; // Modifier becomes a value between 0 and .5 * PlaneAcceleration TargetSpeedModifier = (TargetSpeedModifier * PlaneAcceleration ) >> 9; if ( PlaneAngle < 90 || PlaneAngle > 270 ) TargetSpeedModifier *= -1; // Because we are dealing with int's the PlaneAccel is stored as a fixed point field // Convert calculations appropriately. AllowedSpeed = ( PlaneAcceleration + TargetSpeedModifier ) << PLANE_ACCEL_SHIFT; if ( PlaneAccel[CurrentPlayer] < AllowedSpeed ) PlaneAccel[CurrentPlayer]++; if ( PlaneAccel[CurrentPlayer] > AllowedSpeed ) PlaneAccel[CurrentPlayer]--; // Now apply the plane acceleration fwActorAddVelocity ( PlaneActor[CurrentPlayer], fwActorGetAngle ( PlaneActor[CurrentPlayer] ), ( PlaneAccel[CurrentPlayer] >> PLANE_ACCEL_SHIFT ) ); // NOTE : deceleration is performed as a percentage of the previous // speed. Acceleration is a simple addition. Therefore drag increases // as speed increases and we naturally get a max speed for the plane. // Now add the gravity factor fwActorAddVelocity ( PlaneActor[CurrentPlayer] ,180, Gravity ); } void FreeFallPlane ( int CurrentPlayer ) { int TempSpeed; // Before we do anything decelerate the plane ( Plane drag ) // NOTE : When falling only apply the drag to the x movement TempSpeed = fwAnimateGetChangeValue( XPlaneAnim[CurrentPlayer] ); TempSpeed = TempSpeed * PlaneDeceleration / 100; fwAnimateSetChangeValue ( XPlaneAnim[CurrentPlayer], TempSpeed ); // Now add the gravity factor fwActorAddVelocity ( PlaneActor[CurrentPlayer] ,180, (Gravity<<2) ); TempSpeed = fwAnimateGetChangeValue( YPlaneAnim[CurrentPlayer] ); // We cant fall faster than the plane can fly.. it would be daft if ( TempSpeed > (PlaneAcceleration<<1) ) { TempSpeed = (PlaneAcceleration<<1); } fwAnimateSetChangeValue ( YPlaneAnim[CurrentPlayer], TempSpeed ); }