player.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #include "player.hpp"
  2. player::player() : game_object(C/2, R-1, 1)
  3. {
  4. length=8;
  5. weaponclass=0;
  6. weaponclassrkt=0;
  7. rocketlauncher=FALSE;
  8. commands[0]='a'; //left
  9. commands[1]='d'; //right
  10. commands[2]='w'; //up
  11. commands[3]='s'; //down
  12. godmode=false;
  13. }
  14. player::player(int Length) : game_object(C/2, R, 1)
  15. {
  16. length=(Length<2?2:(Length>20?20:Length));
  17. weaponclass=0;
  18. weaponclassrkt=0;
  19. rocketlauncher=FALSE;
  20. commands[0]='a'; //left
  21. commands[1]='d'; //right
  22. commands[2]='w'; //up
  23. commands[3]='s'; //down
  24. godmode=false;
  25. }
  26. void player::set_commands(int* _commands){
  27. for(int i=0;i<4;i++)
  28. commands[i]=_commands[i];
  29. }
  30. void player::next_pos(int command)
  31. {
  32. if((command==commands[0] || command==KEY_LEFT) && x>0) x-=2;
  33. if((command==commands[1] || command==KEY_RIGHT) && x<C-length) x+=2;
  34. if((command==commands[2] || command==KEY_UP) && y>0) y--;
  35. if((command==commands[3] || command==KEY_DOWN) && y<R-1) y++;
  36. }
  37. void player::shoot(std::list<bullet> & bullets)
  38. {
  39. static int thiscannon=0;
  40. if(weaponclass==0){
  41. if(thiscannon)
  42. {
  43. bullet new_bullet(x+(int)(length/2.),y,2);
  44. bullets.push_back(new_bullet);
  45. }
  46. else
  47. {
  48. bullet new_bullet(x+(int)(length/2.)-1,y,2);
  49. bullets.push_back(new_bullet);
  50. }
  51. thiscannon= ~thiscannon;
  52. }
  53. else if(weaponclass==1){
  54. bullet new_bullet1(x+(int)(length/2.),y,2);
  55. bullets.push_back(new_bullet1);
  56. bullet new_bullet2(x+(int)(length/2.)-1,y,2);
  57. bullets.push_back(new_bullet2);
  58. }
  59. else if(weaponclass==2){
  60. if(thiscannon)
  61. {
  62. bullet new_bullet(x+(int)(length/2.),y,2);
  63. bullets.push_back(new_bullet);
  64. }
  65. else
  66. {
  67. bullet new_bullet(x+(int)(length/2.)-1,y,2);
  68. bullets.push_back(new_bullet);
  69. }
  70. thiscannon= ~thiscannon;
  71. if(length>2){
  72. bullet new_bullet1(x+1,y,2);
  73. bullets.push_back(new_bullet1);
  74. bullet new_bullet3(x+(length-2>(int)(length/2.)?length-2:((int)(length/2.)+1>length?length-1:(int)(length/2.)+1)),y,2);
  75. bullets.push_back(new_bullet3);
  76. }
  77. }
  78. else if(weaponclass==3){
  79. bullet new_bullet(x+(int)(length/2.),y,2);
  80. bullets.push_back(new_bullet);
  81. bullet new_bullet2(x+(int)(length/2.)-1,y,2);
  82. bullets.push_back(new_bullet2);
  83. if(length>2){
  84. bullet new_bullet1(x+1,y,2);
  85. bullets.push_back(new_bullet1);
  86. bullet new_bullet3(x+(length-2>(int)(length/2.)?length-2:((int)(length/2.)+1>length?length-1:(int)(length/2.)+1)),y,2);
  87. bullets.push_back(new_bullet3);
  88. }
  89. }
  90. else if(weaponclass==4){
  91. bullet new_bullet4(x+(int)(length/2.)-1,y,2);
  92. bullets.push_back(new_bullet4);
  93. bullet new_bullet5(x+(int)(length/2.),y,2);
  94. bullets.push_back(new_bullet5);
  95. if(length>2){
  96. bullet new_bullet6(x+(int)(length/2.)+1,y,2);
  97. bullets.push_back(new_bullet6);
  98. bullet new_bullet2(x+(length-2>(int)(length/2.)+1?length-2:length-1),y,2);
  99. bullets.push_back(new_bullet2);
  100. bullet new_bullet3(x+(1<(int)(length/2.)-2?1:0),y,2);
  101. bullets.push_back(new_bullet3);
  102. }
  103. if(length>4){
  104. bullet new_bullet7(x+(int)(length/2.)-2,y,2);
  105. bullets.push_back(new_bullet7);
  106. }
  107. }
  108. else if(weaponclass==5){
  109. for(int i=0;i<length;i++){
  110. bullet new_bullet(x+i,y,2);
  111. bullets.push_back(new_bullet);
  112. }
  113. }
  114. }
  115. void player::shootrkt(std::list<rocket>& rockets)
  116. {
  117. static int thiscannon=0;
  118. if(weaponclassrkt==0){
  119. if(thiscannon)
  120. {
  121. rocket new_rocket(x+(int)(length/2.),y,1);
  122. rockets.push_back(new_rocket);
  123. }
  124. else
  125. {
  126. rocket new_rocket(x+(int)(length/2.)-1,y,-1);
  127. rockets.push_back(new_rocket);
  128. }
  129. thiscannon= ~thiscannon;
  130. }
  131. else if(weaponclassrkt==1){
  132. rocket new_rocket1(x+(int)(length/2.),y,1);
  133. rockets.push_back(new_rocket1);
  134. rocket new_rocket2(x+(int)(length/2.)-1,y,-1);
  135. rockets.push_back(new_rocket2);
  136. }
  137. else if(weaponclassrkt==2){
  138. if(thiscannon)
  139. {
  140. rocket new_rocket(x+(int)(length/2.),y,1);
  141. rockets.push_back(new_rocket);
  142. }
  143. else
  144. {
  145. rocket new_rocket(x+(int)(length/2.)-1,y,-1);
  146. rockets.push_back(new_rocket);
  147. }
  148. thiscannon= ~thiscannon;
  149. if(length>2){
  150. rocket new_rocket1(x+1,y,1);
  151. rockets.push_back(new_rocket1);
  152. rocket new_rocket3(x+(length-2>(int)(length/2.)?length-2:((int)(length/2.)+1>length?length-1:(int)(length/2.)+1)),y,-1);
  153. rockets.push_back(new_rocket3);
  154. }
  155. }
  156. else if(weaponclassrkt==3){
  157. rocket new_rocket(x+(int)(length/2.),y,1);
  158. rockets.push_back(new_rocket);
  159. rocket new_rocket2(x+(int)(length/2.)-1,y,-1);
  160. rockets.push_back(new_rocket2);
  161. if(length>2){
  162. rocket new_rocket1(x+1,y,1);
  163. rockets.push_back(new_rocket1);
  164. rocket new_rocket3(x+(length-2>(int)(length/2.)?length-2:((int)(length/2.)+1>length?length-1:(int)(length/2.)+1)),y,-1);
  165. rockets.push_back(new_rocket3);
  166. }
  167. }
  168. else if(weaponclassrkt==4){
  169. rocket new_rocket4(x+(int)(length/2.)-1,y,1);
  170. rockets.push_back(new_rocket4);
  171. rocket new_rocket5(x+(int)(length/2.),y,-1);
  172. rockets.push_back(new_rocket5);
  173. if(length>2){
  174. rocket new_rocket6(x+(int)(length/2.)+1,y,1);
  175. rockets.push_back(new_rocket6);
  176. rocket new_rocket2(x+(length-2>(int)(length/2.)+1?length-2:length-1),y,-1);
  177. rockets.push_back(new_rocket2);
  178. rocket new_rocket3(x+(1<(int)(length/2.)-2?1:0),y,1);
  179. rockets.push_back(new_rocket3);
  180. }
  181. if(length>4){
  182. rocket new_rocket7(x+(int)(length/2.)-2,y,-1);
  183. rockets.push_back(new_rocket7);
  184. }
  185. }
  186. else if(weaponclassrkt==5){
  187. for(int i=0;i<length;i++){
  188. rocket new_rocket(x+i,y,pow(-1.,(double)i));
  189. rockets.push_back(new_rocket);
  190. }
  191. }
  192. }