PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/creathemup_sdl/src/CPlayerBehaviour.cpp

http://creathemup.googlecode.com/
C++ | 604 lines | 414 code | 105 blank | 85 comment | 35 complexity | 4c24c80032cecfe7e42a61369808c186 MD5 | raw file
  1. #include "../include/CPlayerBehaviour.h"
  2. #include "../include/CDefaultShotBehaviour.h"
  3. #include "../include/CBombShotBehaviour.h"
  4. #include "../include/CSpriteAnimation.h"
  5. #include <SDL/SDL.h>
  6. #define STRAIGHT_SHOT_SPEED 15
  7. #define MIDDLE_SHOT_SPEED 10
  8. #define SIDE_SHOT_SPEED 7
  9. //**************************
  10. //Description : Constructor
  11. //Parameters : Value for m_iX, m_iY,
  12. // m_iSpeedX, m_iSpeedY,
  13. // m_iWidth, m_iHeight,
  14. // the ratio for the collision box
  15. // the type of colision
  16. // and m_iLives
  17. //Note : None
  18. //**************************
  19. CPlayerBehaviour::CPlayerBehaviour(int _iX, int _iY,
  20. int _iSpeedX, int _iSpeedY,
  21. int _iWidth, int _iHeight,
  22. float _fRatioW, float _fRatioH,
  23. TYPE_COLLISION _iTypeCollision,
  24. int _iLives)
  25. : IMovableEntityBehaviour(_iX, _iY,
  26. _iSpeedX, _iSpeedY,
  27. _iWidth, _iHeight,
  28. _fRatioW, _fRatioW,
  29. _iTypeCollision,
  30. _iLives),
  31. m_lCurrentScore(0),
  32. m_iEnemiesKilled(0)
  33. {
  34. m_iPrimaryShot = DEFAULTSHOT;
  35. m_iSecondaryShot = BOMB;
  36. m_iTimeBetweenPrimaryShot = 100;
  37. m_iTimeBetweenSecondaryShot = 800;
  38. m_iNBShots = new int[2]();
  39. for (int i = 0; i < 2; i++)
  40. m_iNBShots[i] = 1;
  41. for (int i = 0; i < MAX_SHOTS; i++)
  42. m_DirectionShots[i] = new Rect[i+1]();
  43. //1 shot
  44. m_DirectionShots[0][0].iX = 0;
  45. m_DirectionShots[0][0].iY = 0;
  46. m_DirectionShots[0][0].iSpeedX = 0;
  47. m_DirectionShots[0][0].iSpeedY = -STRAIGHT_SHOT_SPEED;
  48. //2shots
  49. m_DirectionShots[1][0].iX = -10;
  50. m_DirectionShots[1][0].iY = 0;
  51. m_DirectionShots[1][0].iSpeedX = 0;
  52. m_DirectionShots[1][0].iSpeedY = -STRAIGHT_SHOT_SPEED;
  53. m_DirectionShots[1][1].iX = 10;
  54. m_DirectionShots[1][1].iY = 0;
  55. m_DirectionShots[1][1].iSpeedX = 0;
  56. m_DirectionShots[1][1].iSpeedY = -STRAIGHT_SHOT_SPEED;
  57. //3 shots
  58. m_DirectionShots[2][0].iX = 0;
  59. m_DirectionShots[2][0].iY = 0;
  60. m_DirectionShots[2][0].iSpeedX = -SIDE_SHOT_SPEED;
  61. m_DirectionShots[2][0].iSpeedY = -STRAIGHT_SHOT_SPEED;
  62. m_DirectionShots[2][1].iX = 0;
  63. m_DirectionShots[2][1].iY = 0;
  64. m_DirectionShots[2][1].iSpeedX = 0;
  65. m_DirectionShots[2][1].iSpeedY = -STRAIGHT_SHOT_SPEED;
  66. m_DirectionShots[2][2].iX = 0;
  67. m_DirectionShots[2][2].iY = 0;
  68. m_DirectionShots[2][2].iSpeedX = SIDE_SHOT_SPEED;
  69. m_DirectionShots[2][2].iSpeedY = -STRAIGHT_SHOT_SPEED;
  70. //4 shots
  71. m_DirectionShots[3][0].iX = 0;
  72. m_DirectionShots[3][0].iY = 0;
  73. m_DirectionShots[3][0].iSpeedX = -MIDDLE_SHOT_SPEED;
  74. m_DirectionShots[3][0].iSpeedY = -STRAIGHT_SHOT_SPEED;
  75. m_DirectionShots[3][1].iX = 0;
  76. m_DirectionShots[3][1].iY = 0;
  77. m_DirectionShots[3][1].iSpeedX = 0;
  78. m_DirectionShots[3][1].iSpeedY = -STRAIGHT_SHOT_SPEED;
  79. m_DirectionShots[3][2].iX = 0;
  80. m_DirectionShots[3][2].iY = 0;
  81. m_DirectionShots[3][2].iSpeedX = MIDDLE_SHOT_SPEED;
  82. m_DirectionShots[3][2].iSpeedY = -STRAIGHT_SHOT_SPEED;
  83. m_DirectionShots[3][3].iX = 0;
  84. m_DirectionShots[3][3].iY = 0;
  85. m_DirectionShots[3][3].iSpeedX = 0;
  86. m_DirectionShots[3][3].iSpeedY = STRAIGHT_SHOT_SPEED;
  87. //5 shots
  88. m_DirectionShots[4][0].iX = 0;
  89. m_DirectionShots[4][0].iY = 0;
  90. m_DirectionShots[4][0].iSpeedX = -STRAIGHT_SHOT_SPEED;
  91. m_DirectionShots[4][0].iSpeedY = -STRAIGHT_SHOT_SPEED;
  92. m_DirectionShots[4][1].iX = 0;
  93. m_DirectionShots[4][1].iY = 0;
  94. m_DirectionShots[4][1].iSpeedX = 0;
  95. m_DirectionShots[4][1].iSpeedY = -STRAIGHT_SHOT_SPEED;
  96. m_DirectionShots[4][2].iX = 0;
  97. m_DirectionShots[4][2].iY = 0;
  98. m_DirectionShots[4][2].iSpeedX = STRAIGHT_SHOT_SPEED;
  99. m_DirectionShots[4][2].iSpeedY = -STRAIGHT_SHOT_SPEED;
  100. m_DirectionShots[4][3].iX = 0;
  101. m_DirectionShots[4][3].iY = 0;
  102. m_DirectionShots[4][3].iSpeedX = -SIDE_SHOT_SPEED;
  103. m_DirectionShots[4][3].iSpeedY = STRAIGHT_SHOT_SPEED;
  104. m_DirectionShots[4][4].iX = 0;
  105. m_DirectionShots[4][4].iY = 0;
  106. m_DirectionShots[4][4].iSpeedX = SIDE_SHOT_SPEED;
  107. m_DirectionShots[4][4].iSpeedY = STRAIGHT_SHOT_SPEED;
  108. //6 shots
  109. m_DirectionShots[5][0].iX = -10;
  110. m_DirectionShots[5][0].iY = 0;
  111. m_DirectionShots[5][0].iSpeedX = -STRAIGHT_SHOT_SPEED;
  112. m_DirectionShots[5][0].iSpeedY = -STRAIGHT_SHOT_SPEED;
  113. m_DirectionShots[5][1].iX = -10;
  114. m_DirectionShots[5][1].iY = 0;
  115. m_DirectionShots[5][1].iSpeedX = 0;
  116. m_DirectionShots[5][1].iSpeedY = -STRAIGHT_SHOT_SPEED;
  117. m_DirectionShots[5][2].iX = 10;
  118. m_DirectionShots[5][2].iY = 0;
  119. m_DirectionShots[5][2].iSpeedX = 0;
  120. m_DirectionShots[5][2].iSpeedY = -STRAIGHT_SHOT_SPEED;
  121. m_DirectionShots[5][3].iX = 10;
  122. m_DirectionShots[5][3].iY = 0;
  123. m_DirectionShots[5][3].iSpeedX = STRAIGHT_SHOT_SPEED;
  124. m_DirectionShots[5][3].iSpeedY = -STRAIGHT_SHOT_SPEED;
  125. m_DirectionShots[5][4].iX = 0;
  126. m_DirectionShots[5][4].iY = 0;
  127. m_DirectionShots[5][4].iSpeedX = -SIDE_SHOT_SPEED;
  128. m_DirectionShots[5][4].iSpeedY = STRAIGHT_SHOT_SPEED;
  129. m_DirectionShots[5][5].iX = 0;
  130. m_DirectionShots[5][5].iY = 0;
  131. m_DirectionShots[5][5].iSpeedX = SIDE_SHOT_SPEED;
  132. m_DirectionShots[5][5].iSpeedY = STRAIGHT_SHOT_SPEED;
  133. //7 shots
  134. m_DirectionShots[6][0].iX = -10;
  135. m_DirectionShots[6][0].iY = 0;
  136. m_DirectionShots[6][0].iSpeedX = -STRAIGHT_SHOT_SPEED;
  137. m_DirectionShots[6][0].iSpeedY = -STRAIGHT_SHOT_SPEED;
  138. m_DirectionShots[6][1].iX = -10;
  139. m_DirectionShots[6][1].iY = 0;
  140. m_DirectionShots[6][1].iSpeedX = 0;
  141. m_DirectionShots[6][1].iSpeedY = -STRAIGHT_SHOT_SPEED;
  142. m_DirectionShots[6][2].iX = 10;
  143. m_DirectionShots[6][2].iY = 0;
  144. m_DirectionShots[6][2].iSpeedX = 0;
  145. m_DirectionShots[6][2].iSpeedY = -STRAIGHT_SHOT_SPEED;
  146. m_DirectionShots[6][3].iX = 10;
  147. m_DirectionShots[6][3].iY = 0;
  148. m_DirectionShots[6][3].iSpeedX = STRAIGHT_SHOT_SPEED;
  149. m_DirectionShots[6][3].iSpeedY = -STRAIGHT_SHOT_SPEED;
  150. m_DirectionShots[6][4].iX = 0;
  151. m_DirectionShots[6][4].iY = 0;
  152. m_DirectionShots[6][4].iSpeedX = -MIDDLE_SHOT_SPEED;
  153. m_DirectionShots[6][4].iSpeedY = STRAIGHT_SHOT_SPEED;
  154. m_DirectionShots[6][5].iX = 0;
  155. m_DirectionShots[6][5].iY = 0;
  156. m_DirectionShots[6][5].iSpeedX = 0;
  157. m_DirectionShots[6][5].iSpeedY = STRAIGHT_SHOT_SPEED;
  158. m_DirectionShots[6][6].iX = 0;
  159. m_DirectionShots[6][6].iY = 0;
  160. m_DirectionShots[6][6].iSpeedX = MIDDLE_SHOT_SPEED;
  161. m_DirectionShots[6][6].iSpeedY = STRAIGHT_SHOT_SPEED;
  162. //8 shots
  163. m_DirectionShots[7][0].iX = 0;
  164. m_DirectionShots[7][0].iY = 0;
  165. m_DirectionShots[7][0].iSpeedX = -STRAIGHT_SHOT_SPEED;
  166. m_DirectionShots[7][0].iSpeedY = -STRAIGHT_SHOT_SPEED;
  167. m_DirectionShots[7][1].iX = 0;
  168. m_DirectionShots[7][1].iY = 0;
  169. m_DirectionShots[7][1].iSpeedX = -SIDE_SHOT_SPEED;
  170. m_DirectionShots[7][1].iSpeedY = -STRAIGHT_SHOT_SPEED;
  171. m_DirectionShots[7][2].iX = 0;
  172. m_DirectionShots[7][2].iY = 0;
  173. m_DirectionShots[7][2].iSpeedX = 0;
  174. m_DirectionShots[7][2].iSpeedY = -STRAIGHT_SHOT_SPEED;
  175. m_DirectionShots[7][3].iX = 0;
  176. m_DirectionShots[7][3].iY = 0;
  177. m_DirectionShots[7][3].iSpeedX = SIDE_SHOT_SPEED;
  178. m_DirectionShots[7][3].iSpeedY = -STRAIGHT_SHOT_SPEED;
  179. m_DirectionShots[7][4].iX = 0;
  180. m_DirectionShots[7][4].iY = 0;
  181. m_DirectionShots[7][4].iSpeedX = STRAIGHT_SHOT_SPEED;
  182. m_DirectionShots[7][4].iSpeedY = -STRAIGHT_SHOT_SPEED;
  183. m_DirectionShots[7][5].iX = 0;
  184. m_DirectionShots[7][5].iY = 0;
  185. m_DirectionShots[7][5].iSpeedX = -MIDDLE_SHOT_SPEED;
  186. m_DirectionShots[7][5].iSpeedY = STRAIGHT_SHOT_SPEED;
  187. m_DirectionShots[7][6].iX = 0;
  188. m_DirectionShots[7][6].iY = 0;
  189. m_DirectionShots[7][6].iSpeedX = 0;
  190. m_DirectionShots[7][6].iSpeedY = STRAIGHT_SHOT_SPEED;
  191. m_DirectionShots[7][7].iX = 0;
  192. m_DirectionShots[7][7].iY = 0;
  193. m_DirectionShots[7][7].iSpeedX = MIDDLE_SHOT_SPEED;
  194. m_DirectionShots[7][7].iSpeedY = STRAIGHT_SHOT_SPEED;
  195. //9 shots
  196. m_DirectionShots[8][0].iX = -10;
  197. m_DirectionShots[8][0].iY = 0;
  198. m_DirectionShots[8][0].iSpeedX = -STRAIGHT_SHOT_SPEED;
  199. m_DirectionShots[8][0].iSpeedY = -STRAIGHT_SHOT_SPEED;
  200. m_DirectionShots[8][1].iX = -10;
  201. m_DirectionShots[8][1].iY = 0;
  202. m_DirectionShots[8][1].iSpeedX = -SIDE_SHOT_SPEED;
  203. m_DirectionShots[8][1].iSpeedY = -STRAIGHT_SHOT_SPEED;
  204. m_DirectionShots[8][2].iX = -10;
  205. m_DirectionShots[8][2].iY = 0;
  206. m_DirectionShots[8][2].iSpeedX = 0;
  207. m_DirectionShots[8][2].iSpeedY = -STRAIGHT_SHOT_SPEED;
  208. m_DirectionShots[8][3].iX = 10;
  209. m_DirectionShots[8][3].iY = 0;
  210. m_DirectionShots[8][3].iSpeedX = 0;
  211. m_DirectionShots[8][3].iSpeedY = -STRAIGHT_SHOT_SPEED;
  212. m_DirectionShots[8][4].iX = 10;
  213. m_DirectionShots[8][4].iY = 0;
  214. m_DirectionShots[8][4].iSpeedX = SIDE_SHOT_SPEED;
  215. m_DirectionShots[8][4].iSpeedY = -STRAIGHT_SHOT_SPEED;
  216. m_DirectionShots[8][5].iX = 1;
  217. m_DirectionShots[8][5].iY = 0;
  218. m_DirectionShots[8][5].iSpeedX = STRAIGHT_SHOT_SPEED;
  219. m_DirectionShots[8][5].iSpeedY = -STRAIGHT_SHOT_SPEED;
  220. m_DirectionShots[8][6].iX = 0;
  221. m_DirectionShots[8][6].iY = 0;
  222. m_DirectionShots[8][6].iSpeedX = -MIDDLE_SHOT_SPEED;
  223. m_DirectionShots[8][6].iSpeedY = STRAIGHT_SHOT_SPEED;
  224. m_DirectionShots[8][7].iX = 0;
  225. m_DirectionShots[8][7].iY = 0;
  226. m_DirectionShots[8][7].iSpeedX = 0;
  227. m_DirectionShots[8][7].iSpeedY = STRAIGHT_SHOT_SPEED;
  228. m_DirectionShots[8][8].iX = 0;
  229. m_DirectionShots[8][8].iY = 0;
  230. m_DirectionShots[8][8].iSpeedX = MIDDLE_SHOT_SPEED;
  231. m_DirectionShots[8][8].iSpeedY = STRAIGHT_SHOT_SPEED;
  232. }
  233. //**************************
  234. //Description : Copy Constructor
  235. //Parameters : A CPlayerBehaviour
  236. //Note : None
  237. //**************************
  238. CPlayerBehaviour::CPlayerBehaviour(CPlayerBehaviour & _Player)
  239. : IMovableEntityBehaviour(_Player),
  240. m_lCurrentScore(_Player.m_lCurrentScore),
  241. m_iEnemiesKilled(_Player.m_iEnemiesKilled)
  242. {
  243. m_iNBShots = new int[2]();
  244. for (int i = 0; i < 2; i++)
  245. m_iNBShots[i] = _Player.m_iNBShots[i];
  246. for (int i = 0; i < MAX_SHOTS; i++)
  247. {
  248. m_DirectionShots[i] = new Rect[i+1]();
  249. for (int j = 0; j <= i; j++)
  250. {
  251. m_DirectionShots[i][j].iSpeedX = _Player.m_DirectionShots[i][j].iSpeedX;
  252. m_DirectionShots[i][j].iSpeedY = _Player.m_DirectionShots[i][j].iSpeedY;
  253. m_DirectionShots[i][j].iX = _Player.m_DirectionShots[i][j].iX;
  254. m_DirectionShots[i][j].iY = _Player.m_DirectionShots[i][j].iY;
  255. }
  256. }
  257. }
  258. //**************************
  259. //Description : Destructor
  260. //Parameters : None
  261. //Note : None
  262. //**************************
  263. CPlayerBehaviour::~CPlayerBehaviour()
  264. {
  265. if ( m_iNBShots != NULL )
  266. delete[] m_iNBShots;
  267. for (int i = 0; i < MAX_SHOTS; i++)
  268. {
  269. if ( m_DirectionShots[i] != NULL )
  270. delete[] m_DirectionShots[i];
  271. }
  272. }
  273. //**************************
  274. //Description : The player can throw 2 more shots at a time
  275. //Parameters : The type of shot that is powered up
  276. //Return Value : None
  277. //Note : None
  278. //**************************
  279. void CPlayerBehaviour::ShotsUp(int _iTypeOfShot)
  280. {
  281. if ( _iTypeOfShot >= 0 && _iTypeOfShot < 2 )
  282. {
  283. if ( m_iNBShots[_iTypeOfShot] + 1 <= MAX_SHOTS )
  284. m_iNBShots[_iTypeOfShot]++;
  285. }
  286. }
  287. //**************************
  288. //Description : Add _iNbPoints to the score of the player
  289. //Parameters : The number of points to add
  290. //Return Value : None
  291. //Note : None
  292. //**************************
  293. void CPlayerBehaviour::AddPoints(long _iNbPoints)
  294. {
  295. m_lCurrentScore += _iNbPoints;
  296. if (m_lCurrentScore < 0)
  297. m_lCurrentScore = 0;
  298. }
  299. //**************************
  300. //Description : Return the score of the player
  301. //Parameters : None
  302. //Return Value : The score of the player
  303. //Note : None
  304. //**************************
  305. long CPlayerBehaviour::GetPoints() const
  306. {
  307. return m_lCurrentScore;
  308. }
  309. //**************************
  310. //Description : Set the number of shots for each shots
  311. //Parameters : The tab of the number of shots
  312. //Return Value : None
  313. //Note : None
  314. //**************************
  315. void CPlayerBehaviour::SetNbShots(int * _iNbShots)
  316. {
  317. for (int i = 0; i < 2; i++)
  318. {
  319. if ( m_iNBShots == NULL )
  320. m_iNBShots = new int[2]();
  321. m_iNBShots[i] = _iNbShots[i];
  322. }
  323. }
  324. //**************************
  325. //Description : Return the number of shots of each type of shot
  326. //Parameters : None
  327. //Return Value : The tab of nb shots
  328. //Note : None
  329. //**************************
  330. int * CPlayerBehaviour::GetNbShots() const
  331. {
  332. return m_iNBShots;
  333. }
  334. //**************************
  335. //Description : Add an enemy to the number of killed enemy
  336. //Parameters : The number of ennemies
  337. //Return Value : None
  338. //Note : None
  339. //**************************
  340. void CPlayerBehaviour::AddEnemiesKilled(int _iNbEnemiesKilled)
  341. {
  342. m_iEnemiesKilled += _iNbEnemiesKilled;
  343. }
  344. //**************************
  345. //Description : Return the number of enemies that the player killed
  346. //Parameters : None
  347. //Return Value : The number of enemies that the player killed
  348. //Note : None
  349. //**************************
  350. int CPlayerBehaviour::GetEnemiesKilled() const
  351. {
  352. return m_iEnemiesKilled;
  353. }
  354. //**************************
  355. //Description : The entity shoot
  356. //Parameters : The tab of animations shot and the screen
  357. //Return Value : True if the enemy has shot, otherwise false
  358. //Note : Virtual because the way of shooting depends on the entity
  359. //**************************
  360. bool CPlayerBehaviour::Shoot(CSpriteAnimation * _SpriteAnimationShot, SDL_Surface * _screen)
  361. {
  362. //we get the state of the key board
  363. Uint8* keys;
  364. keys = SDL_GetKeyState(NULL);
  365. //we test the keys in order to know what shot create
  366. if ( keys[SDLK_SPACE] && ( (Uint32)(m_lLastPrimaryShoot + m_iTimeBetweenPrimaryShot) < SDL_GetTicks() ) )
  367. {
  368. CDefaultShotBehaviour * Shot;
  369. switch ( m_iPrimaryShot )
  370. {
  371. case DEFAULTSHOT:
  372. {
  373. for (int i = 0; i < m_iNBShots[0]; i++)
  374. {
  375. Shot = new CDefaultShotBehaviour(m_iX+m_DirectionShots[m_iNBShots[0]-1][i].iX,
  376. m_iY+m_DirectionShots[m_iNBShots[0]-1][i].iY,
  377. m_DirectionShots[m_iNBShots[0]-1][i].iSpeedX,
  378. m_DirectionShots[m_iNBShots[0]-1][i].iSpeedY,
  379. _SpriteAnimationShot[DEFAULTSHOT].GetWidth(),
  380. _SpriteAnimationShot[DEFAULTSHOT].GetHeight());
  381. Shot->SetSprite( &_SpriteAnimationShot[DEFAULTSHOT], _screen );
  382. m_vShots->push_back( Shot );
  383. }
  384. break;
  385. }
  386. case BOMB:
  387. {
  388. for (int i = 0; i < m_iNBShots[0]; i++)
  389. {
  390. Shot = new CBombShotBehaviour(m_iX+m_DirectionShots[m_iNBShots[0]-1][i].iX,
  391. m_iY+m_DirectionShots[m_iNBShots[0]-1][i].iY,
  392. m_DirectionShots[m_iNBShots[0]-1][i].iSpeedX,
  393. m_DirectionShots[m_iNBShots[0]-1][i].iSpeedY,
  394. _SpriteAnimationShot[BOMB].GetWidth(),
  395. _SpriteAnimationShot[BOMB].GetHeight());
  396. Shot->SetSprite( &_SpriteAnimationShot[BOMB], _screen );
  397. m_vShots->push_back( Shot );
  398. }
  399. break;
  400. }
  401. default:
  402. {
  403. Shot = new CDefaultShotBehaviour(m_iX, m_iY,
  404. 0, -2,
  405. _SpriteAnimationShot[DEFAULTSHOT].GetWidth(),
  406. _SpriteAnimationShot[DEFAULTSHOT].GetHeight());
  407. Shot->SetSprite( &_SpriteAnimationShot[DEFAULTSHOT], _screen );
  408. m_vShots->push_back( Shot );
  409. }
  410. }
  411. m_lLastPrimaryShoot = SDL_GetTicks();
  412. return true;
  413. }
  414. if ( keys[SDLK_b] && ( (Uint32)(m_lLastSecondaryShoot + m_iTimeBetweenSecondaryShot) < SDL_GetTicks() ) )
  415. {
  416. CDefaultShotBehaviour * Shot;
  417. switch ( m_iSecondaryShot )
  418. {
  419. case DEFAULTSHOT:
  420. {
  421. for (int i = 0; i < m_iNBShots[1]; i++)
  422. {
  423. Shot = new CDefaultShotBehaviour(m_iX+m_DirectionShots[m_iNBShots[1]-1][i].iX,
  424. m_iY+m_DirectionShots[m_iNBShots[1]-1][i].iY,
  425. m_DirectionShots[m_iNBShots[1]-1][i].iSpeedX,
  426. m_DirectionShots[m_iNBShots[1]-1][i].iSpeedY,
  427. _SpriteAnimationShot[DEFAULTSHOT].GetWidth(),
  428. _SpriteAnimationShot[DEFAULTSHOT].GetHeight());
  429. Shot->SetSprite( &_SpriteAnimationShot[DEFAULTSHOT], _screen );
  430. m_vShots->push_back( Shot );
  431. }
  432. break;
  433. }
  434. case BOMB:
  435. {
  436. for (int i = 0; i < m_iNBShots[1]; i++)
  437. {
  438. Shot = new CBombShotBehaviour(m_iX+m_DirectionShots[m_iNBShots[1]-1][i].iX,
  439. m_iY+m_DirectionShots[m_iNBShots[1]-1][i].iY,
  440. m_DirectionShots[m_iNBShots[1]-1][i].iSpeedX,
  441. m_DirectionShots[m_iNBShots[1]-1][i].iSpeedY,
  442. _SpriteAnimationShot[BOMB].GetWidth(),
  443. _SpriteAnimationShot[BOMB].GetHeight());
  444. Shot->SetSprite( &_SpriteAnimationShot[BOMB], _screen );
  445. m_vShots->push_back( Shot );
  446. }
  447. break;
  448. }
  449. default:
  450. {
  451. Shot = new CBombShotBehaviour(m_iX, m_iY,
  452. 0, -2,
  453. _SpriteAnimationShot[BOMB].GetWidth(),
  454. _SpriteAnimationShot[BOMB].GetHeight());
  455. Shot->SetSprite( &_SpriteAnimationShot[BOMB], _screen );
  456. m_vShots->push_back( Shot );
  457. break;
  458. }
  459. }
  460. m_lLastSecondaryShoot = SDL_GetTicks();
  461. return true;
  462. }
  463. return false;
  464. }
  465. //**************************
  466. //Description : Update the trajectory of the entity
  467. //Parameters : None
  468. //Return Value : None
  469. //Note : Virtual because actions depends on the entity type
  470. //**************************
  471. void CPlayerBehaviour::EntityTrajectory()
  472. {
  473. Uint8* keys;
  474. keys = SDL_GetKeyState(NULL);
  475. if ( keys[SDLK_UP] )
  476. {
  477. m_iY -= m_iSpeedY;
  478. if ( !IsInTheScreen() )
  479. m_iY += m_iSpeedY;
  480. }
  481. if ( keys[SDLK_DOWN] )
  482. {
  483. m_iY += m_iSpeedY;
  484. if ( !IsInTheScreen() )
  485. m_iY -= m_iSpeedY;
  486. }
  487. if ( keys[SDLK_LEFT] )
  488. {
  489. m_iX -= m_iSpeedX;
  490. if ( !IsInTheScreen() )
  491. m_iX += m_iSpeedX;
  492. }
  493. if ( keys[SDLK_RIGHT] )
  494. {
  495. m_iX += m_iSpeedX;
  496. if ( !IsInTheScreen() )
  497. m_iX -= m_iSpeedX;
  498. }
  499. }