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

射击游戏

开发平台:

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. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. //////////////////////////////////////////////////////////////////////
  14. EnermyPlace::EnermyPlace(Manager *mgr)
  15. {
  16. mManager=mgr;
  17. RefreshStress();
  18. }
  19. EnermyPlace::~EnermyPlace()
  20. {
  21. list<Brock*>::iterator b,bk;;
  22. b=BrockList.begin();
  23. bk=BrockList.end();
  24. while(b!=bk)
  25. {
  26. delete *b;
  27. b++;
  28. }
  29. }
  30. Brock* EnermyPlace::GetOneBrock()
  31. {
  32. BrockFind=-1;
  33. BrockValue=BrockList.size();
  34. if(BrockValue==0)
  35. return NULL;
  36. oNowBrock=BrockList.end();
  37. return GetTwoBrock();
  38. }
  39. Brock* EnermyPlace::GetTwoBrock()
  40. {
  41. BrockFind++;
  42. oNowBrock++;
  43. while((BrockFind<BrockValue)&&(*oNowBrock)->Work==false)
  44. {
  45. delete *oNowBrock;
  46. BrockValue--;
  47. oNowBrock=BrockList.erase(oNowBrock);
  48. }
  49. if(oNowBrock==BrockList.end())
  50. return NULL;
  51. else
  52. return *oNowBrock;
  53. }
  54. //创建新敌机
  55. void EnermyPlace::NewBrock(int x,int y)
  56. {
  57. int i,j;
  58. Brock::BROCKSTYLE BrockStyle=(Brock::BROCKSTYLE)(rand() % Brock::BROCKVALUE);
  59. Brock *bBrock;
  60. switch(BrockStyle)
  61. {
  62. case Brock::BROCKA:
  63. bBrock=new BrockA(mManager,x+80,y-80);
  64. BrockList.push_back(bBrock);
  65. break;
  66. case Brock::BROCKB:
  67.   bBrock=new BrockB(mManager,x+80,y-80);
  68.       BrockList.push_back(bBrock);
  69. break;
  70. case Brock::BROCKC:
  71. if(rand()%3>0)break;
  72. j=rand()%4+1;
  73. switch(rand()%4)
  74. {
  75. case 0:
  76. if(x+j*50>Manager::Imglong)
  77. x=Manager::Imglong-j*50;
  78. for(i=0;i<j;i++)
  79. {
  80. bBrock=new BrockC(mManager,x+i*50,y-i*50);
  81. BrockList.push_back(bBrock);
  82. }
  83. break;
  84. case 1:
  85. if(x<j*50)
  86. x=j*50;
  87. for(i=0;i<j;i++)
  88. {
  89. bBrock=new BrockC(mManager,x-i*50,y-i*50);
  90. BrockList.push_back(bBrock);
  91. }
  92. break;
  93. case 2:
  94. for(i=0;i<j;i++)
  95. {
  96. bBrock=new BrockC(mManager,x,y-i*70);
  97. BrockList.push_back(bBrock);
  98. }
  99. break;
  100. case 3:
  101. if(x+j*50>Manager::Imglong)
  102. x=Manager::Imglong-j*50;
  103. for(i=0;i<j;i++)
  104. {
  105. bBrock=new BrockC(mManager,x+i*70,y);
  106. BrockList.push_back(bBrock);
  107. }
  108. }
  109. case Brock::BROCKD:
  110. bBrock=new BrockD(mManager,x+80,y-80);
  111. BrockList.push_back(bBrock);
  112. break;
  113. case Brock::BROCKE:
  114. bBrock=new BrockE(mManager,x+100,y-100);
  115. BrockList.push_back(bBrock);
  116. break;
  117.     case Brock::BROCKF:
  118. bBrock=new BrockF(mManager,x+120,y-120);
  119. BrockList.push_back(bBrock);
  120. break;
  121. }
  122. }
  123. void EnermyPlace::Update()
  124. {
  125. if(rand()<stress)
  126. NewBrock(rand()%mManager->Imglong,-1);
  127. //刷新敌机
  128. Brock *bBrock=GetOneBrock();
  129. while(bBrock)
  130. {
  131. bBrock->Update();
  132. bBrock=GetTwoBrock();
  133. }
  134. }
  135. void EnermyPlace::AddStress()
  136. {
  137. stress=(int)(stress*1.6);
  138. }
  139. void EnermyPlace::RefreshStress()
  140. {
  141. stress=500;
  142. }