Helico.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "Helico.h"
  2. Helico::Helico(SDL_Surface* ecran) : Ennemy(0,ecran),m_vitesse(5+takeRand(5))
  3. {
  4. m_helico = SDL_LoadBMP("Images/Helicopter.bmp");
  5. SDL_SetColorKey(m_helico,SDL_SRCCOLORKEY,SDL_MapRGB(m_helico->format,255,255,255));//On met le fond (blanc) en invisible !
  6. m_positionHelico.x=takeRand(620);
  7. m_positionHelico.y=40+takeRand(350);
  8. }
  9. Helico::Helico(SDL_Surface* ecran,int vie) : Ennemy(0,ecran,vie),m_vitesse(5+takeRand(5))
  10. {
  11. m_helico=SDL_LoadBMP("Images/Helicopter.bmp");
  12. SDL_SetColorKey(m_helico,SDL_SRCCOLORKEY,SDL_MapRGB(m_helico->format,255,255,255));//On met le fond (blanc) en invisible !
  13. }
  14. Helico::Helico(SDL_Surface* ecran, int vie, int antiLatence) : Ennemy(0,ecran,vie),m_vitesse(5+takeRand(5,antiLatence))
  15. {
  16. m_helico = SDL_LoadBMP("Images/Helicopter.bmp");
  17. SDL_SetColorKey(m_helico,SDL_SRCCOLORKEY,SDL_MapRGB(m_helico->format,255,255,255));//On met le fond (blanc) en invisible !
  18. m_positionHelico.x=takeRand(620,antiLatence);
  19. m_positionHelico.y=40+takeRand(350,antiLatence);
  20. }
  21. Helico::~Helico()
  22. {
  23. SDL_FreeSurface(m_helico);
  24. }
  25. void Helico::afficher()
  26. {
  27. if (m_positionHelico.x<640)
  28. {
  29. m_positionHelico.x=m_positionHelico.x+=m_vitesse;
  30. }
  31. else
  32. {
  33. m_positionHelico.x=0;
  34. }
  35. SDL_BlitSurface(m_helico,NULL,m_ecran,&m_positionHelico);
  36. if (m_tempsFire==0)
  37. {
  38. if (m_positionHelico.x+64>m_xFire&&m_xFire>m_positionHelico.x && m_positionHelico.y+32>m_yFire&&m_yFire>m_positionHelico.y)
  39. {
  40. switch(m_typeFire)
  41. {
  42. case 0:
  43. this->recevoirDegats(11);
  44. break;
  45. case 1:
  46. this->recevoirDegats(5);
  47. break;
  48. case 2:
  49. this->recevoirDegats(3);
  50. break;
  51. }//Switch
  52. }//Verification position
  53. }//Si tir
  54. }
  55. ///////////////////////////////////////////////////////////////////////////////////////////////////
  56. BossOne::BossOne(SDL_Surface* ecran,Joueur* cible) : Ennemy(cible,ecran,100)
  57. {
  58. m_bossOne=SDL_LoadBMP("Images/HelicopterBossUn.bmp");
  59. m_tir=SDL_LoadBMP("Images/HelicopterBossUnTir.bmp");
  60. SDL_SetColorKey(m_bossOne,SDL_SRCCOLORKEY,SDL_MapRGB(m_bossOne->format,255,255,255));
  61. SDL_SetColorKey(m_tir,SDL_SRCCOLORKEY,SDL_MapRGB(m_tir->format,255,255,255));
  62. m_positionBoss.x=100;
  63. m_positionBoss.y=50;
  64. m_vaVersLeBas=true;
  65. m_vaVersLaDroite=true;
  66. m_armeCycle=100;
  67. }
  68. BossOne::~BossOne()
  69. {
  70. SDL_FreeSurface(m_bossOne);
  71. }
  72. void BossOne::afficher()
  73. {
  74. //Deplacement
  75. if (m_vaVersLeBas)
  76. {
  77. m_positionBoss.y++;
  78. if (m_positionBoss.y>324)//480-76-80
  79. {
  80. m_vaVersLeBas=false;
  81. }
  82. }
  83. else
  84. {
  85. m_positionBoss.y--;
  86. if (m_positionBoss.y<0)
  87. {
  88. m_vaVersLeBas=true;
  89. }
  90. }
  91. if (m_vaVersLaDroite)
  92. {
  93. m_positionBoss.x++;
  94. if (m_positionBoss.x>512)
  95. {
  96. m_vaVersLaDroite=false;
  97. }
  98. }
  99. else
  100. {
  101. m_positionBoss.x--;
  102. if (m_positionBoss.x<0)
  103. {
  104. m_vaVersLaDroite=true;
  105. }
  106. }
  107. //Collage
  108. SDL_BlitSurface(m_bossOne,NULL,m_ecran,&m_positionBoss);
  109. //Gestion des tirs du joueur
  110. if (m_tempsFire==0)
  111. {
  112. if (m_positionBoss.x+128>m_xFire&&m_xFire>m_positionBoss.x && m_positionBoss.y+80>m_yFire&&m_yFire>m_positionBoss.y)
  113. {
  114. this->recevoirDegats(10);
  115. }
  116. }
  117. //Gestion des tirs d'helico
  118. if (!takeRand(50,m_armeCycle))
  119. {
  120. m_armeCycle=0;
  121. m_cible->recevoirDegats(1);
  122. }
  123. if (m_armeCycle<5)
  124. {
  125. SDL_Rect positionTir;
  126. positionTir.x=m_positionBoss.x+m_bossOne->w/2-m_tir->w/2;
  127. positionTir.y=m_positionBoss.y+m_bossOne->h/2-m_tir->h/2;
  128. SDL_BlitSurface(m_tir,NULL,m_ecran,&positionTir);
  129. }
  130. m_armeCycle++;
  131. }