ObjectHit.cpp
上传用户:semy2100
上传日期:2013-01-22
资源大小:3633k
文件大小:4k
源码类别:

射击游戏

开发平台:

Visual C++

  1. /********************************************************************
  2. *                        空运爆发                                    *
  3. *                       Version 2.0                                  *
  4. * 本游戏全部代码由:                                                 *
  5. *                   冲天实验室   梁锋 编写                           *
  6. *                    邮箱:lenwine@126.com                           *
  7. *                bbs: http://free2.e-168.cn/lenwind (正在开发中...)  *
  8. **********************************************************************/
  9. ////////////////////////////////////////////////////
  10. #include "stdafx.h"
  11. #include "MusicPlace.h"
  12. ////////////////////////////////////////////////////
  13. int ObjectHit::i=0;
  14. ObjectHit::ObjectHit(Manager *mgr)
  15. {
  16. oPeratorPlace=mgr->oPeratorPlace;
  17. oPeratorPlace2=mgr->oPeratorPlace2;
  18. oEnermyPlace=mgr->oEnermyPlace;
  19. oPeratorbomb=mgr->oPeratorbomb;
  20. oEnermybomb=mgr->oEnermybomb;
  21. //==================================================
  22. _getcwd( muspath, sizeof(muspath));
  23. strcpy(bplay, "play ");
  24. strcat(bplay, muspath);
  25. strcat(bplay, "\cs.wav");
  26. strcpy(bclose, "close ");
  27. strcat(bclose, muspath);
  28. strcat(bclose, "\cs.wav");
  29. //==================================================
  30. }
  31. ObjectHit::~ObjectHit()
  32. {
  33. }
  34. void ObjectHit::Update()
  35. {
  36. Brock *bBrock;
  37. Bomb   *bBomb;
  38. bBrock=oEnermyPlace->GetOneBrock();
  39. while(bBrock)
  40. {   
  41. //检查敌机与操作者的碰撞
  42. WatchHit(oPeratorPlace,bBrock);
  43. WatchHit(oPeratorPlace2,bBrock);
  44. bBomb=oPeratorbomb->GetOneBomb();
  45. while(bBomb)
  46. {
  47. WatchHit(bBrock,bBomb);
  48. bBomb=oPeratorbomb->GetTwoBomb();
  49. }
  50. bBrock=oEnermyPlace->GetTwoBrock();
  51. }
  52. bBomb=oEnermybomb->GetOneBomb();
  53. while(bBomb)
  54. {
  55. WatchHit(oPeratorPlace,bBomb);
  56. WatchHit(oPeratorPlace2,bBomb);
  57. bBomb=oEnermybomb->GetTwoBomb();
  58. }
  59. }
  60. //检查敌机的子弹与操作者的子弹是否有碰撞
  61. void ObjectHit::WatchHit(Brock *lpBrockPlace,Bomb *bBomb)
  62. {
  63. if(lpBrockPlace->alive<=0 || bBomb->alive<=0)return;
  64. if(lpBrockPlace->GetX()+lpBrockPlace->rx+lpBrockPlace->rlong>bBomb->GetX()+bBomb->rx && 
  65. lpBrockPlace->GetY()+lpBrockPlace->ry+lpBrockPlace->rtall>bBomb->GetY()+bBomb->rtall &&
  66. lpBrockPlace->GetX()+lpBrockPlace->rx<bBomb->GetX()+bBomb->rx+bBomb->rlong &&
  67. lpBrockPlace->GetY()+lpBrockPlace->ry<bBomb->GetY()+bBomb->ry+bBomb->rtall)
  68. {
  69. char buf[256];
  70. lpBrockPlace->alive-=bBomb->shootpower;
  71. bBomb->alive=0;
  72. oPeratorPlace->result+=lpBrockPlace->alive;
  73. if(lpBrockPlace->alive<=0)
  74. {
  75. oPeratorPlace->decedent++;
  76. }
  77. mciSendString(bplay, buf, sizeof(buf), NULL);
  78. }
  79. }
  80. //碰撞检测:操作者与敌方子弹
  81. void ObjectHit::WatchHit(OperatorPlace *lpOperatorPlace,Bomb *bBomb)
  82. {
  83. if(lpOperatorPlace->alive<=0 || bBomb->alive<=0)return;
  84. if(lpOperatorPlace->GetX()+lpOperatorPlace->rx+lpOperatorPlace->rlong>bBomb->GetX()+bBomb->rx &&
  85.    lpOperatorPlace->GetY()+lpOperatorPlace->ry+lpOperatorPlace->rtall>bBomb->GetY()+bBomb->rtall &&
  86.        lpOperatorPlace->GetX()+lpOperatorPlace->rx<bBomb->GetX()+bBomb->rx+bBomb->rlong  &&
  87.    lpOperatorPlace->GetY()+lpOperatorPlace->ry<bBomb->GetY()+bBomb->ry+bBomb->rtall)
  88. {
  89. char buf[256];
  90. lpOperatorPlace->alive-=bBomb->shootpower;
  91. bBomb->alive=0;
  92. mciSendString(bplay, buf, sizeof(buf), NULL);
  93. }
  94. }
  95. //碰撞检测:操作者与敌机
  96. void ObjectHit::WatchHit(OperatorPlace *oPeratorPlace,Brock *bBrock)
  97. {
  98.  if(oPeratorPlace->alive<=0||bBrock->alive<=0)return;
  99.  if(oPeratorPlace->GetX()+oPeratorPlace->rx+oPeratorPlace->rlong > bBrock->GetX()+bBrock->rx &&
  100. oPeratorPlace->GetY()+oPeratorPlace->ry+oPeratorPlace->rtall > bBrock->GetY()+bBrock->rtall &&
  101. oPeratorPlace->GetX()+oPeratorPlace->rx < bBrock->GetX()+bBrock->rx+bBrock->rlong &&
  102. oPeratorPlace->GetY()+oPeratorPlace->ry < bBrock->GetY()+bBrock->ry+bBrock->rtall)
  103. {
  104.         char buf[256];
  105. oPeratorPlace->alive-=5;
  106. oPeratorPlace->decedent++;
  107. oPeratorPlace->result+=bBrock->alive;
  108. /* 如果碰撞了敌人活率减小*/
  109. bBrock->alive=0;
  110. mciSendString(bplay, buf, sizeof(buf), NULL);
  111. }
  112. }