MORE CODE | ||||||||||
FLIGHT SIM BASICS |
||||||||||
LEAVE THE AILERONS,ELEVATORS AND RUDDER BEHIND. FLY WITH THE MOUSE. CONTROL SPEED WITH THE ARROW KEYS. FIRE WITH A LEFT CLICK. PITCH UP IN A TURN TO COME AROUND FASTER. CHASE DOWN TWO DRONES. |
||||||||||
`Flight Final `Author: Hop A Long `July 25, 2004 `Flight controls, ship, moving targets ,simple collision AutoCam Off : Hide Mouse : Sync On : Sync Rate 30 ` *****Make a surface******* Make Matrix 1,1400,1400,20,20 Create Bitmap 1,256,256 : cls rgb(0,100,250) : ink rgb(0,0,150),0 For j = 1 to 4 Circle 128,128,j*32 Next j Get Image 1,0,0,256,256 : Delete Bitmap 1 Prepare Matrix Texture 1,1,1,1 Fill Matrix 1,0,1 Randomize Matrix 1,30 ` *****Fog****************** Fog On : Fog Distance 1300 : Fog Color RGB(0,0,250) ` *****Make a Plane********* Make Object Box 1,35,4,1 : ` the wing Position Object 1,0,-5,-2 Make mesh from Object 1,1 Delete Object 1 Make Object Sphere 2,10 : ` the cockpit Position Object 2,0,-2,-5 Scale Object 2,75,100,150 Make Mesh from Object 2,2 Delete Object 2 Make Object Cylinder 3,3 : ` fuel tank Position Object 3,15,-1,-2 Scale Object 3,100,400,100 Make Mesh From Object 3,3 Delete Object 3 Make Object Cylinder 4,3 : ` fuel tank Position Object 4,-15,-1,-2 Scale Object 4,100,400,100 Make Mesh From Object 4,4 Delete Object 4 Make Object Cylinder 1,15 : ` the body Color Object 1,RGB( 0,128,180) Position Object 1,0,20,50 Scale Object 1,75,50,300 Rotate Object 1,90,0,0 Fix Object Pivot 1 Add Limb 1,1,1 : Color Limb 1,1, RGB(250,0,0) Add Limb 1,2,2 Add Limb 1,3,3 : Color Limb 1,3, RGB(250,0,0) Add Limb 1,4,4 : Color Limb 1,4, RGB(250,0,0) Position Object 1,750,40,50 ` *****Make drone to mark a back position make object sphere 30,10 ` *****Make targets******** Make Object Sphere 9,20 Position Object 9,50,50,50 Make Object Sphere 10,30 Position Object 10,50,50,50 ` *****Make bullet********** Make Object Sphere 20,4 Color Object 20, RGB(0,250,0) Hide Object 20 `*****MAIN LOOP********************************** Do FLIGHT() x# = Object Position X(1) y# = Object Position Y(1) z# = Object Position Z(1) ` *****COLLISION********* col_return = Object Collision(20,0) If col_return > 1 Color Object col_return, RGB(250,0,0) BulletLife = 0 Hide Object 20 EndIf Text 200,20,"Collision with : "+str$(col_return) ` *****BULLETS******** ` Left Click returns 1, Right Click returns 2 If Mouseclick()=1 and BulletLife = 0 ` Place the bullet in the gun Position object 20, x#,y#,z# ` The bullet faces the same direction as the gun, Set object to object orientation 20,1 BulletLife =40 Record_Score = 1 Show object 20 Endif If BulletLife > 0 Dec BulletLife Move object 20,25+throttle# If BulletLife = 0 then Hide object 20 Endif ` *****ANIMATE TARGETS*** ang# = ang# + 1.0 pos# = WrapValue(ang#) posx# = Sin(pos#) * 500 posz# = Cos(pos#) * 600 posy# = 100.0 Position Object 9,posx# + 500.0,posy#,posz# + 350.0 Position Object 10,posx# + 750.0,posy#,posz# + 750.0 ` *****CAMERA ROUTINE**** ` Get back position of object for camera pitch object down 1,10 move object 1,-65 position object 30,object position x(1),object position y(1),object position z(1) move object 1,65 pitch object up 1,10 ` Place camera and set orientation to object position camera object position x(30),object position y(30),object position z(30) `set camera to object orientation 1 Point Camera x#,y#,z# Sync Loop `*****END OF MAIN LOOP*************************** FUNCTION FLIGHT() ` *****Variables********* turn_factor# = 0.05 : `sensitivity to mouse input pitch_factor# = 0.80 : `sensitivity to mouse input roll_factor# = 1.5 : `sensitivity to mouse input max_throttle# = 5.0 : `maximum speed ` ******PITCH************ old_mouse_y# = mouse_y# mouse_y# = mouse_y# + MouseMoveY() delta_y# = mouse_y# - old_mouse_y# Pitch Object Up 1, pitch_factor# * delta_y# ` Just to be neat If mouse_y# > 100.0 Then mouse_y# = 0.0 ` ******TURN and Roll**** old_mouse_x# = mouse_x# mouse_x# = mouse_x# + MouseMoveX() delta_x# = (mouse_x# - old_mouse_x#) ` Limit the roll If mouse_x# > 40.0 mouse_x# = 40.0 delta_x# = 0.0 EndIf If mouse_x# < -40.0 mouse_x# = -40.0 delta_x# = 0.0 EndIf ` Bank Roll Object Right 1, roll_factor# * delta_x# Turn Object Right 1, turn_factor# * mouse_x# * stop# If mouse_x# > 0.0 Pitch Object Up 1, mouse_x# * 0.03 * stop# Else Pitch Object Up 1, mouse_x# * 0.03 * stop# * (-1) EndIf ` Make turn recovery easier sz# = ship_z_ang# If (sz# > 160.0 and sz# < 180.0) or (sz# > 340.0 and sz# < 360.0) stop# = 0.0 If mouse_x# > 0.0 Then Dec mouse_x# If mouse_x# < 0.0 Then Inc mouse_x# Else stop# = 1.0 EndIf ` *****DISPLAY*********** Ink RGB(250,250,250),0 Text 10,20, "mouse_y# : "+str$(mouse_y#) Text 10,40, "mouse_x# : "+str$(mouse_x#) Text 10,60, "delta_y# : "+str$(delta_y#) Text 10,80, "delta_x# : "+str$(delta_x#) Text 10,100,"throttle : "+str$(throttle#) ship_x# = Object Position X(1) ship_y# = Object Position Y(1) ship_z# = Object Position Z(1) ship_x_ang# = Object Angle X(1) ship_y_ang# = Object Angle Y(1) ship_z_ang# = Object Angle Z(1) Text 400,20, "ship_x# : "+str$(ship_x#) Text 400,40, "ship_y# : "+str$(ship_y#) Text 400,60, "ship_z# : "+str$(ship_z#) Text 400,80, "ship_x_ang# : "+str$(ship_x_ang#) Text 400,100,"ship_y_ang# : "+str$(ship_y_ang#) Text 400,120,"ship_z_ang# : "+str$(sz#) Text 400,140,"stop# : "+str$(stop#) Text 400,160,"y_diff# : "+str$(y_diff#) ` *****THRUST************ If UpKey() = 1 Inc throttle#, 0.1 If throttle# > max_throttle# Then throttle# = max_throttle# EndIf If DownKey() = 1 Dec throttle#, 0.1 If throttle# < 0 Then throttle# = 0 EndIf Move Object 1,throttle# ` Check for down drift y2# = Object Position Y(1) y_diff# = ship_y#-y2# ENDFUNCTION throttle# |