Start.cpp
上传用户:cncdtg88
上传日期:2013-03-14
资源大小:10474k
文件大小:20k
源码类别:

射击游戏

开发平台:

Visual C++

  1. // start.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "start.h"
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include "MainFrm.h"
  8. #include "license.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. typedef struct player_data {
  15. RECT window_rect; //The size of the window used for rendering
  16. HPEN  crosshair_pen; //The pen used for drawing the crosshair (WIN32 stuff. Nothing to do with STATE ...)
  17. DWORD weapon; //A handle to the weapon object 
  18. DWORD fire_animation; //A handle to the animation used for shooting
  19. DWORD fire_effect_polygon; // When shooting we enable this polygon to be used by the shooting-fire-animation
  20. DWORD weapon_idle_sequence; //The sequence that is used with the weapon 3D animation when not shooting
  21. DWORD weapon_shooting_sequence; //A handle to the 3d animation sequance that is used while shooting
  22. DWORD weapon_shooting_mark_bitmap; //A handle to the the bitmap we use for marking shooting holes
  23. DWORD shooting_shred; //A object handle. This is the master splinter. When we shoot we duplicate this object 
  24.   //for creating the broken pieces falling down from where the bullets hit
  25. int   is_shooting;
  26. } player_data;
  27. player_data gl_player;
  28. #define STEP 60 
  29. #define GRAVITY 100.0  
  30. #define HEIGHT_ABOVE_GROUND (50.0*WORLD_FACTOR) 
  31. #define VIEWER_SIZE  (50*WORLD_FACTOR) 
  32. #define SIZE_OF_WALKING_EFFECT 32 
  33. #define WALKING_EFFECT_HEIGHT (HEIGHT_ABOVE_GROUND*0.125) 
  34. #define MOUSE_SENSITIVITY 0.2 
  35. #define MAX_TILT 85 
  36. #define GUN_MOVING_SPEED 0.05  
  37. #define SHOOTING_MARK_RADIUS 20 
  38. #define SHRED_SPEED 20 
  39. #define SHRED_SIZE 10 
  40. #define WORLD_FACTOR 6 
  41. #define STANDING 1 
  42. #define WALKING  2
  43. #define FALLING  3
  44. #define SOUND_STEP1 0
  45. #define SOUND_STEP2 1
  46. #define SOUND_STEP3 2
  47. #define SOUND_STEP4 3
  48. #define SOUND_FALL  4
  49. #define SOUND_HIT_WALL 5
  50. #define SOUND_SHOOT 6
  51. #define NUMBER_OF_SOUNDS 7
  52. //Opponent stage constant
  53. #define OPPONENT_IDLE 1
  54. #define OPPONENT_ATTACK 2
  55. #define OPPONENT_ATTACK_DISTANCE 1000
  56. DWORD g_skyArray[100];
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CMy3DSTATE_AppWizardApp
  59. BEGIN_MESSAGE_MAP(CMy3DSTATE_AppWizardApp, CWinApp)
  60. //{{AFX_MSG_MAP(CMy3DSTATE_AppWizardApp)
  61. // NOTE - the ClassWizard will add and remove mapping macros here.
  62. //    DO NOT EDIT what you see in these blocks of generated code!
  63. //}}AFX_MSG_MAP
  64. END_MESSAGE_MAP()
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CMy3DSTATE_AppWizardApp construction
  67. CMy3DSTATE_AppWizardApp::CMy3DSTATE_AppWizardApp()
  68. {
  69. // TODO: add construction code here,
  70. // Place all significant initialization in InitInstance
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // The one and only CMy3DSTATE_AppWizardApp object
  74. CMy3DSTATE_AppWizardApp theApp;
  75. /////////////////////////////////////////////////////////////////////////////
  76. /////////////////////////////////////////////////////////////////////////////
  77. BOOL CMy3DSTATE_AppWizardApp::InitInstance()
  78. {
  79. return TRUE;
  80. }
  81. BOOL CMy3DSTATE_AppWizardApp::OnIdle(LONG lCount) 
  82. {
  83. return true; 
  84. }
  85. int CMy3DSTATE_AppWizardApp::ExitInstance() 
  86. {
  87. int res = CWinApp::ExitInstance();
  88. STATE_engine_close();
  89. return res;
  90. }
  91. void copy_vector(double dst[3], double src[3])
  92. {
  93. dst[0]=src[0];
  94. dst[1]=src[1];
  95. dst[2]=src[2];
  96. }
  97. void set_vector(double dst[3], double x, double y, double z)
  98. {
  99. dst[0]=x;
  100. dst[1]=y;
  101. dst[2]=z;
  102. }
  103. void add_vector(double dst[3], double src[3])
  104. {
  105. dst[0]+=src[0];
  106. dst[1]+=src[1];
  107. dst[2]+=src[2];
  108. }
  109. void sub_vector(double dst[3], double src[3])
  110. {
  111. dst[0]-=src[0];
  112. dst[1]-=src[1];
  113. dst[2]-=src[2];
  114. }
  115. void mul_vector(double vec[3], double factor)
  116. {
  117. vec[0]*=factor;
  118. vec[1]*=factor;
  119. vec[2]*=factor;
  120. }
  121. void camera_manage_free_falling(DWORD camera, double walking_height_effect[], int *player_stage, int *player_stage_progress, DWORD sounds[])
  122. {
  123. double location[3], bellow[3], intersection[3];
  124. STATE_camera_get_location(camera, &location[0], &location[1], &location[2]);
  125. copy_vector(bellow, location);
  126. bellow[2]=-1e10; 
  127. DWORD poly,obj;
  128. int rc=STATE_engine_is_movement_possible(location, bellow, &poly, intersection, &obj);
  129. if(rc==YES) {
  130. }
  131. else {
  132. double walking_effect=0;
  133. if( *player_stage==WALKING) 
  134. walking_effect=walking_height_effect[*player_stage_progress];
  135. double height=location[2]-intersection[2];
  136. double wanted_height_above_ground=HEIGHT_ABOVE_GROUND+walking_effect;
  137. if(height>wanted_height_above_ground+GRAVITY) {
  138. *player_stage=FALLING;
  139. location[2]-=GRAVITY;
  140. height-=GRAVITY;
  141. }
  142. else {
  143. location[2]=intersection[2]+wanted_height_above_ground;
  144. if(*player_stage==FALLING) {
  145. *player_stage=STANDING;
  146. STATE_sound_play(sounds[SOUND_FALL], SOUND_NO_LOOP);
  147. }
  148. }
  149. STATE_camera_set_location(camera, location[0], location[1], location[2]);
  150. }
  151. }
  152. void camera_move_according_to_keyboard_input(DWORD camera, int *player_stage, int *player_stage_progress, DWORD sounds[])
  153. {
  154. if(GetAsyncKeyState(VK_LEFT)<0) STATE_camera_rotate_z(camera, 5,WORLD_SPACE);
  155. if(GetAsyncKeyState(VK_RIGHT )<0) STATE_camera_rotate_z(camera, -5,WORLD_SPACE);
  156. double direction[3];
  157. STATE_camera_get_direction(camera, &direction[0], &direction[1], &direction[2]);
  158. direction[2]=0; 
  159. if(STATE_math_normalize_vector(direction)==VR_ERROR){
  160. set_vector(direction, 1,0,0);
  161. }
  162. if((*player_stage!=FALLING) && (GetAsyncKeyState(VK_UP)<0)) {
  163. *player_stage=WALKING; 
  164. mul_vector(direction,STEP);
  165. (*player_stage_progress)++;
  166. if(*player_stage_progress>=SIZE_OF_WALKING_EFFECT) {
  167. *player_stage_progress=0;
  168. }
  169. if( ((*player_stage_progress) % (SIZE_OF_WALKING_EFFECT/4))==0) {
  170. int sound_num=(*player_stage_progress)/(SIZE_OF_WALKING_EFFECT/4);
  171. STATE_sound_play(sounds[sound_num], SOUND_NO_LOOP);
  172. }
  173. }
  174. else
  175. if((*player_stage!=FALLING) && (GetAsyncKeyState(VK_DOWN)<0)) {
  176. mul_vector(direction,-STEP);
  177. *player_stage=WALKING;
  178. (*player_stage_progress)--;
  179. if((*player_stage_progress)<0) *player_stage_progress=SIZE_OF_WALKING_EFFECT-1;
  180. if( ((*player_stage_progress) % (SIZE_OF_WALKING_EFFECT/4))==0) {
  181. int sound_num=(*player_stage_progress)/(SIZE_OF_WALKING_EFFECT/4);
  182. STATE_sound_play(sounds[sound_num], SOUND_NO_LOOP);
  183. }
  184. }
  185. else {
  186. if(*player_stage!=FALLING)
  187. *player_stage=STANDING;
  188. return;
  189. }
  190. double wanted_location[3];
  191. STATE_camera_get_location(camera, &wanted_location[0], &wanted_location[1], &wanted_location[2]);
  192. add_vector(wanted_location, direction);
  193. int did_camera_move=STATE_camera_move_with_collision_detection(camera, wanted_location, VIEWER_SIZE);
  194. if(did_camera_move==NO) {
  195. if(*player_stage_progress==0) 
  196. STATE_sound_play(sounds[SOUND_HIT_WALL], SOUND_NO_LOOP);
  197. }
  198. }
  199. void camera_move_according_to_mouse_input(DWORD camera)
  200. {
  201. DWORD static first_time_flag=YES;
  202. static POINT point;
  203. if(GetCursorPos( &point)==0) 
  204. return; 
  205. int center_x=(gl_player.window_rect.right-gl_player.window_rect.left)/2;
  206. int center_y=(gl_player.window_rect.bottom-gl_player.window_rect.top)/2;
  207. SetCursorPos(center_x, center_y);
  208. if(first_time_flag==YES) {
  209. first_time_flag=NO; 
  210. return;
  211. }
  212. int diff_x=point.x-center_x;
  213. int diff_y=point.y-center_y;
  214. if(diff_x!=0)
  215. STATE_camera_rotate_z(camera, (double)-diff_x*MOUSE_SENSITIVITY,WORLD_SPACE);
  216. if(diff_y==0) return;
  217. double tilt=STATE_camera_get_tilt(camera);
  218. tilt-= (double)diff_y*MOUSE_SENSITIVITY;
  219. if(tilt>MAX_TILT) tilt=MAX_TILT;
  220. if(tilt<-MAX_TILT) tilt=-MAX_TILT;
  221. STATE_camera_set_tilt(camera, tilt);
  222. }
  223. void camera_update_location(DWORD camera, double walking_height_effect[], int *player_stage, int *player_stage_progress, DWORD sounds[])
  224. {
  225. camera_manage_free_falling(camera, walking_height_effect, player_stage, player_stage_progress, sounds);
  226. camera_move_according_to_keyboard_input(camera, player_stage, player_stage_progress, sounds);
  227. camera_move_according_to_mouse_input(camera);
  228. }
  229. void intitialize_walking_height_effect_array(double walking_height_effect[])
  230. {
  231. double step=2*M_PI/SIZE_OF_WALKING_EFFECT;
  232. double angle=0;
  233. for(int i=0; i<SIZE_OF_WALKING_EFFECT; i++) {
  234. walking_height_effect[i]=sin(angle)*WALKING_EFFECT_HEIGHT;
  235. angle+=step;
  236. }
  237. }
  238. void load_sounds(DWORD sounds[])
  239. {
  240. for(int i=0; i<4; i++) {
  241. char file_name[1000];
  242. sprintf(file_name,"sound\step%d.wav",i+1);
  243. sounds[i]=STATE_sound_load(file_name, NULL, SOUND_DISTANCE_DEFAULT);
  244. }
  245. sounds[SOUND_FALL]=STATE_sound_load("sound\fall1.wav", NULL, SOUND_DISTANCE_DEFAULT);
  246. sounds[SOUND_HIT_WALL]=STATE_sound_load("sound\hit_wall.wav", NULL, SOUND_DISTANCE_DEFAULT);
  247. sounds[SOUND_SHOOT]=STATE_sound_load("sound\shoot.wav", NULL, SOUND_DISTANCE_DEFAULT);
  248. }
  249. void create_the_weapon_fire_effect(void)
  250. {
  251. gl_player.fire_effect_polygon=STATE_polygon_create();
  252. int num_of_polygons=STATE_object_get_number_of_polygons(gl_player.weapon);
  253. DWORD *all_polygons=(DWORD *)GlobalAlloc(GPTR, num_of_polygons*sizeof(DWORD));
  254. STATE_object_get_all_polygons(gl_player.weapon, all_polygons);
  255. double edge_point[3];
  256. // find_a_point_at_the_end_of_the_weapon(all_polygons, num_of_polygons, edge_point);
  257. GlobalFree((HGLOBAL)all_polygons);
  258. double point1[6]={0,0,0, 0,0,  100};
  259. double point2[6]={0,0,0, 1,0,  100};
  260. double point3[6]={0,0,0, 1,1,  100};
  261. double point4[6]={0,0,0, 0,1,  100};
  262. double size=VIEWER_SIZE/10;
  263. set_vector(point1, edge_point[0], edge_point[1]-size, edge_point[2]+size);
  264. set_vector(point2, edge_point[0], edge_point[1]+size, edge_point[2]+size);
  265. set_vector(point3, edge_point[0], edge_point[1]+size, edge_point[2]-size);
  266. set_vector(point4, edge_point[0], edge_point[1]-size, edge_point[2]-size);
  267. STATE_polygon_add_point(gl_player.fire_effect_polygon, point1);
  268. STATE_polygon_add_point(gl_player.fire_effect_polygon, point2);
  269. STATE_polygon_add_point(gl_player.fire_effect_polygon, point3);
  270. STATE_polygon_add_point(gl_player.fire_effect_polygon, point4);
  271. STATE_object_add_polygon(gl_player.weapon, gl_player.fire_effect_polygon);
  272. STATE_polygon_set_animation(gl_player.fire_effect_polygon, gl_player.fire_animation);
  273. STATE_polygon_set_translucent(gl_player.fire_effect_polygon,LIGHT_SOURCE_GLASS);
  274. STATE_polygon_disable(gl_player.fire_effect_polygon);
  275. }
  276. DWORD create_master_shred(void)
  277. {
  278. DWORD obj=STATE_object_create("shred");
  279. DWORD poly=STATE_polygon_create();
  280. double point1[6]={0,0,0, 0,0,  100};
  281. double point2[6]={0,0,0, 1,0,  100};
  282. double point3[6]={0,0,0, 1,1,  100};
  283. double point4[6]={0,0,0, 0,1,  100};
  284. double size=SHRED_SIZE;
  285. set_vector(point1, 0, -size, size);
  286. set_vector(point2, 0, size, size);
  287. set_vector(point3, 0, size, -size);
  288. set_vector(point4, 0, -size, -size);
  289. STATE_polygon_add_point(poly, point1);
  290. STATE_polygon_add_point(poly, point2);
  291. STATE_polygon_add_point(poly, point3);
  292. STATE_polygon_add_point(poly, point4);
  293. STATE_object_add_polygon(obj, poly);
  294. STATE_polygon_set_rotated(poly, YES);
  295. DWORD mask_bitmap=STATE_bitmap_load("weapon\mask.bmp",-1);
  296. STATE_polygon_set_second_bitmap(poly, mask_bitmap);
  297. STATE_polygon_set_translucent(poly, LIGHT_SOURCE_GLASS );
  298. STATE_object_disable(obj);
  299. return(obj);
  300. }
  301. int load_weapon(void)
  302. {
  303. gl_player.weapon = STATE_object_create_from_file("weapon\weapon2.md2");
  304. if(gl_player.weapon == NULL) 
  305. return(VR_ERROR);
  306. DWORD skin = STATE_bitmap_load("weapon\weapon2.bmp",-1);
  307. STATE_object_set_bitmap(gl_player.weapon, skin);
  308. double box[2][3];
  309. STATE_object_get_bounding_box(gl_player.weapon, box);
  310. double weapon_size=box[1][0]-box[0][0];
  311. if(weapon_size==0) return(VR_ERROR); 
  312. double factor=VIEWER_SIZE/(2*weapon_size);
  313. double scale[3] = {factor,factor,factor};
  314. STATE_object_set_scale(gl_player.weapon, scale);
  315. DWORD anim3d = STATE_object_get_3D_animation(gl_player.weapon);
  316. if(anim3d != NULL) {
  317. gl_player.weapon_idle_sequence = STATE_3D_sequence_get_using_name(anim3d, "idle");
  318. STATE_object_set_3D_sequence(gl_player.weapon, gl_player.weapon_idle_sequence, 0);
  319. gl_player.weapon_shooting_sequence=STATE_3D_sequence_get_using_name(anim3d, "shot");
  320. }
  321. gl_player.fire_animation=STATE_animation_create("shoot");
  322. DWORD frame1=STATE_bitmap_load("weapon\Mflash2.bmp",-1);
  323. DWORD frame2=STATE_bitmap_load("weapon\Mflash3.bmp",-1);
  324. DWORD frame3=STATE_bitmap_load("weapon\Mflash4.bmp",-1);
  325. STATE_animation_add_bitmap(gl_player.fire_animation, BITMAP_LIST_FRONT, frame1, -1);
  326. STATE_animation_add_bitmap(gl_player.fire_animation, BITMAP_LIST_FRONT, frame2, -1);
  327. STATE_animation_add_bitmap(gl_player.fire_animation, BITMAP_LIST_FRONT, frame3, -1);
  328. DWORD times[3]={1,1,1};
  329. STATE_animation_set_times(gl_player.fire_animation, times, 3);
  330. create_the_weapon_fire_effect();
  331. gl_player.is_shooting=NO;
  332. gl_player.weapon_shooting_mark_bitmap=STATE_bitmap_load("weapon\smark.bmp",-1);
  333. gl_player.shooting_shred=create_master_shred();
  334. return(OK);
  335. }
  336. int initialize(double walking_height_effect[], DWORD sounds[])
  337. {
  338. int rc=STATE_engine_load_world("arena.STATE","", "bitmaps", USER_DEFINED_BEHAVIOR | MIPMAP_STABLE);
  339. if(rc==VR_ERROR) 
  340. return(VR_ERROR);
  341. ShowCursor(FALSE);
  342. STATE_engine_maximize_default_rendering_window();
  343. intitialize_walking_height_effect_array(walking_height_effect);
  344. DWORD camera=STATE_camera_get_default_camera();
  345. STATE_camera_set_chase_type(camera,NO_CHASE);
  346. if(load_weapon()==VR_ERROR) return(VR_ERROR);
  347. load_sounds(sounds);
  348. for (int i=0;i<100;i++)
  349. g_skyArray[i]=NULL;
  350. int sky_poly_count=0;
  351. for (DWORD poly=STATE_polygon_get_first_polygon();poly!=NULL;poly=STATE_polygon_get_next(poly))
  352. {
  353. if (!strcmp(STATE_polygon_get_name(poly),"Sky")){
  354. g_skyArray[sky_poly_count]=poly;
  355. sky_poly_count++;
  356. }
  357. }
  358. STATE_3D_card_set_full_screen_mode(800,600);
  359. GetClipCursor(&gl_player.window_rect);
  360. return(OK);
  361. }
  362. void draw_crosshair(HDC dc_handle, DWORD camera) 
  363. {
  364. int width=STATE_camera_get_width(camera);
  365. int height=STATE_camera_get_height(camera);
  366. int center_x=width/2;
  367. int center_y=height/2;
  368. SelectObject(dc_handle, GetStockObject(GRAY_BRUSH)); 
  369. SelectObject(dc_handle, gl_player.crosshair_pen); 
  370. Ellipse(dc_handle, center_x-3, center_y-3, center_x+3, center_y+3);
  371. Arc(dc_handle, center_x-12, center_y-12, center_x+12, center_y+12, center_x+12, center_y, center_x+12, center_y);
  372. MoveToEx(dc_handle, center_x-60, center_y, NULL);
  373. LineTo(dc_handle, center_x+60, center_y);
  374. MoveToEx(dc_handle, center_x, center_y-60, NULL);
  375. LineTo(dc_handle, center_x, center_y+60);
  376. }
  377. void move_sky()
  378. {
  379. int i=0;
  380. DWORD poly;
  381. while(1){
  382. poly=g_skyArray[i];
  383. if(poly==NULL)
  384. break;
  385. for (DWORD point=STATE_polygon_get_first_point(poly);point!=NULL;point=STATE_point_get_next_point(point))
  386. {
  387. double xy[2];
  388. STATE_point_get_bitmap_xy(point,xy);
  389. xy[0]+=0.005;
  390. STATE_point_set_bitmap_xy(point,poly,xy);
  391. }
  392. STATE_polygon_is_valid(poly);
  393. i++;
  394. }
  395. }
  396. void create_a_shooting_shred(double target[3], DWORD target_polygon, DWORD target_object)
  397. {
  398. if(target_object!=NULL) 
  399. return; 
  400. DWORD shred=STATE_object_duplicate(gl_player.shooting_shred, YES); 
  401. DWORD bmp=STATE_polygon_get_bitmap_handle(target_polygon);
  402. if(bmp!=NULL) {
  403. DWORD all_polys[1000]; 
  404. STATE_object_get_all_polygons(shred, all_polys); 
  405. STATE_polygon_set_bitmap_fill(all_polys[0], bmp);
  406. }
  407. double normal[4];
  408. STATE_polygon_get_plane(target_polygon, normal);
  409. mul_vector(normal, 5);
  410. add_vector(target, normal);
  411. STATE_object_set_location(shred, target[0], target[1], target[2]);
  412. STATE_object_set_chase_type(shred,CHASE_PHYSICS);
  413. STATE_object_set_max_speed(shred, SHRED_SPEED*10); 
  414. double speed[3]={rand()-RAND_MAX/2,rand()-RAND_MAX/2,rand()};
  415. STATE_object_set_speed(shred,speed);
  416. STATE_object_set_absolute_speed(shred,SHRED_SPEED);
  417. STATE_object_set_friction(shred, 0);
  418. STATE_object_set_elasticity(shred,0.4);
  419. double force[3]={0,0,-1};
  420. STATE_object_set_force(shred,force);
  421. STATE_object_set_event(shred, 5000, STATE_DELETE);
  422. }
  423. void set_weapon_direction(DWORD camera, double intersection[3], DWORD *blocking_polygon, DWORD *blocking_object)
  424. {
  425. double location[3], weapon_location[3];
  426. set_vector(location, -VIEWER_SIZE/2, VIEWER_SIZE/4, -VIEWER_SIZE/4);
  427. STATE_camera_convert_point_to_world_space(camera, location, weapon_location);
  428. STATE_object_set_location(gl_player.weapon, weapon_location[0], weapon_location[1], weapon_location[2]);
  429. double camera_location[3]={0,0,0}; 
  430. double far_ahead[3]={-10000000, 0,0}; 
  431. *blocking_polygon=NULL;
  432. *blocking_object=NULL;
  433. double direction[3];
  434. int rc=STATE_engine_is_movement_possible_camera_space(camera_location, far_ahead, blocking_polygon, intersection, blocking_object);
  435. if(rc==NO) {
  436. copy_vector(direction, intersection);
  437. sub_vector(direction, weapon_location);
  438. }
  439. else {
  440. STATE_camera_get_direction(camera, &direction[0], &direction[1], &direction[2]);
  441. }
  442. double old_direction[3];
  443. STATE_object_get_direction(gl_player.weapon, &old_direction[0], &old_direction[1], &old_direction[2]);
  444. mul_vector(direction, GUN_MOVING_SPEED);
  445. mul_vector(old_direction, (1-GUN_MOVING_SPEED));
  446. add_vector(direction, old_direction);
  447. STATE_object_set_direction(gl_player.weapon, direction[0], direction[1], direction[2]);
  448. }
  449. void manage_shooting(DWORD sounds[], double target[3], DWORD target_polygon, DWORD target_object)
  450. {
  451. int mouse_left_button= (GetAsyncKeyState(VK_LBUTTON)<0);
  452. if( (gl_player.is_shooting==NO) && mouse_left_button) {
  453. gl_player.is_shooting=YES;
  454. STATE_sound_play(sounds[SOUND_SHOOT], SOUND_NO_LOOP);
  455. STATE_polygon_enable(gl_player.fire_effect_polygon);
  456. STATE_object_set_3D_sequence(gl_player.weapon, gl_player.weapon_shooting_sequence, 0);
  457. return;
  458. }
  459. if( (gl_player.is_shooting==YES) && (mouse_left_button==0)) {
  460. gl_player.is_shooting=NO;
  461. STATE_sound_stop(sounds[SOUND_SHOOT]);
  462. STATE_polygon_disable(gl_player.fire_effect_polygon);
  463. STATE_object_set_3D_sequence(gl_player.weapon, gl_player.weapon_idle_sequence, 0);
  464. return;
  465. }
  466. if( gl_player.is_shooting==YES) {
  467. if(STATE_sound_is_sound_playing(sounds[SOUND_SHOOT])==NO) {
  468. gl_player.is_shooting=NO;
  469. STATE_polygon_disable(gl_player.fire_effect_polygon);
  470. STATE_object_set_3D_sequence(gl_player.weapon, gl_player.weapon_idle_sequence, 0);
  471. return;
  472. }
  473. // add_shooting_patch(target, target_polygon, target_object);
  474. create_a_shooting_shred(target, target_polygon, target_object);
  475. // if(target_object==gl_opponent.handle) {
  476. // gl_opponent.got_hit_flag=YES;
  477. // }
  478. }
  479. }
  480. void weapon_update(DWORD camera, DWORD sounds[])
  481. {
  482. double target[3]; 
  483. DWORD  target_polygon, target_object;
  484. if(gl_player.weapon==NULL) return;
  485. set_weapon_direction(camera, target, &target_polygon, &target_object);
  486. manage_shooting(sounds, target, target_polygon, target_object);
  487. }
  488. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR     lpCmdLine,  int nCmdShow)
  489. {
  490. int initialize(double walking_height_effect[], DWORD sounds[]);
  491. void camera_update_location(DWORD camera, double walking_height_effect[], int *player_stage, int *player_stage_progress, DWORD sounds[]);
  492. void weapon_update(DWORD camera, DWORD sounds[]);
  493. DWORD sounds[NUMBER_OF_SOUNDS];
  494. double walking_height_effect[SIZE_OF_WALKING_EFFECT];
  495. int player_stage=STANDING;
  496. int player_stage_progress=0;
  497. if(initialize(walking_height_effect, sounds)==VR_ERROR) return(VR_ERROR);
  498. DWORD camera=STATE_camera_get_default_camera();
  499. while( (GetAsyncKeyState(VK_ESCAPE)&1) ==0 ) {
  500. HDC dc_handle=STATE_engine_render_on_dc(NULL,camera);
  501. draw_crosshair(dc_handle, camera);
  502. STATE_engine_copy_image_from_dc_to_screen();
  503. camera_update_location(camera, walking_height_effect, &player_stage, &player_stage_progress, sounds);
  504. weapon_update(camera, sounds);
  505. move_sky();
  506. }
  507. STATE_engine_close();
  508. return(OK);
  509. }