You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

control.cpp 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include "..\C-Engine\CHeader.hpp"
  2. #include "control.hpp"
  3. void Control::Initialisation(Script_GUI * v)
  4. {
  5. SGUI = v ;
  6. }
  7. void Control::Start()
  8. {
  9. direction = 0;
  10. directionuser = 0;
  11. objectif = 0;
  12. for( int i = 0; i < GetEngine()->GetMap()->nbtiles_largeur_monde; i++)
  13. {
  14. for( int j = 0 ; j < GetEngine()->GetMap()->nbtiles_hauteur_monde; j++)
  15. {
  16. switch(GetEngine()->GetMap()->GetIdMap(i,j))
  17. {
  18. case 15: case 16: objectif ++; break;
  19. default: break;
  20. }
  21. }
  22. }
  23. }
  24. void Control::Update()
  25. {
  26. GetObject()->GetRender()->SetIt(0);
  27. switch(input_dir4())
  28. {
  29. case 2: directionuser = 3; break;
  30. case 4: directionuser = 4; break;
  31. case 6: directionuser = 2; break;
  32. case 8: directionuser = 1; break;
  33. }
  34. if(!GetObject()->GetRigibody()->CollisionDecor( GetX() + (directionuser == 2) - (directionuser == 4) , GetY() + (directionuser == 1) - (directionuser == 3) ))direction = directionuser;
  35. switch(direction)
  36. {
  37. case 1: Move(0,1); GetObject()->GetRender()->SetDirection(90);GetObject()->GetRender()->ReverseRender(false); break;
  38. case 2: Move(1,0); GetObject()->GetRender()->SetDirection(0); GetObject()->GetRender()->ReverseRender(false);break;
  39. case 3: Move(0,-1); GetObject()->GetRender()->SetDirection(270); GetObject()->GetRender()->ReverseRender(false);break;
  40. case 4: Move(-1,0); GetObject()->GetRender()->SetDirection(0); GetObject()->GetRender()->ReverseRender(true);break;
  41. }
  42. int x , y;
  43. x = GetX()/3 + 2;
  44. y = 91 - GetY()/3 - 3;
  45. switch(GetEngine()->GetMap()->GetIdMap( x , y ))
  46. {
  47. case 15 :
  48. GetEngine()->GetMap()->ReplaceIdMap(x , y, 0x00);
  49. SGUI->AddScore(200);
  50. objectif--;
  51. break;
  52. case 16:
  53. GetEngine()->GetMap()->ReplaceIdMap(x , y, 0x00);
  54. GetEngine()->GetMap()->ReplaceIdMap(x+1 , y, 0x00);
  55. GetEngine()->GetMap()->ReplaceIdMap(x , y+1, 0x00);
  56. GetEngine()->GetMap()->ReplaceIdMap(x+1 , y+1, 0x00);
  57. SGUI->AddScore(500);
  58. SGUI->SetVulnerability(8);
  59. objectif--;
  60. break;
  61. case 17:
  62. GetEngine()->GetMap()->ReplaceIdMap(x , y, 0x00);
  63. GetEngine()->GetMap()->ReplaceIdMap(x-1 , y, 0x00);
  64. GetEngine()->GetMap()->ReplaceIdMap(x , y+1, 0x00);
  65. GetEngine()->GetMap()->ReplaceIdMap(x-1 , y+1, 0x00);
  66. SGUI->AddScore(500);
  67. SGUI->SetVulnerability(8);
  68. objectif--;
  69. break;
  70. case 18:
  71. GetEngine()->GetMap()->ReplaceIdMap(x , y, 0x00);
  72. GetEngine()->GetMap()->ReplaceIdMap(x+1 , y, 0x00);
  73. GetEngine()->GetMap()->ReplaceIdMap(x , y-1, 0x00);
  74. GetEngine()->GetMap()->ReplaceIdMap(x+1 , y-1, 0x00);
  75. SGUI->AddScore(500);
  76. SGUI->SetVulnerability(8);
  77. objectif--;
  78. break;
  79. case 19:
  80. GetEngine()->GetMap()->ReplaceIdMap(x , y, 0x00);
  81. GetEngine()->GetMap()->ReplaceIdMap(x-1 , y, 0x00);
  82. GetEngine()->GetMap()->ReplaceIdMap(x , y-1, 0x00);
  83. GetEngine()->GetMap()->ReplaceIdMap(x-1 , y-1, 0x00);
  84. SGUI->AddScore(500);
  85. SGUI->SetVulnerability(8);
  86. objectif--;
  87. break;
  88. default:
  89. break;
  90. }
  91. if(objectif <= 0)
  92. {
  93. ML_clear_vram();
  94. PrintXY(30,28,"You Win",0);
  95. ML_display_vram();
  96. Sleep(1500);
  97. GetEngine()->StopGame();
  98. }
  99. Object * Ennemi = GetObject()->CollisionTagO("Ghost");
  100. if(Ennemi != NULL)
  101. {
  102. if(SGUI->GetVulnerability() <= 0)Die();
  103. else Ennemi->GetTransforms()->SetXY(116,131);
  104. }
  105. if(GetObject()->CollisionTag("TP1"))
  106. {
  107. GetObject()->GetTransforms()->SetXY(229,138);
  108. direction = 4;
  109. }
  110. if(GetObject()->CollisionTag("TP2"))
  111. {
  112. GetObject()->GetTransforms()->SetXY(2,138);
  113. direction = 2;
  114. }
  115. if(input_trigger(K_EXIT))GetEngine()->StopGame();
  116. GetEngine()->MiddleScreen(GetX() + 18 , GetY() + 8 ,false);
  117. }
  118. void Control::Die()
  119. {
  120. bool cinematic = true;
  121. GetObject()->GetRender()->SetIt(1);
  122. while(cinematic == true)
  123. {
  124. ML_clear_vram();
  125. GetEngine()->GetMap()->AfficherMap();
  126. GetObject()->GetRender()->DrawObject();
  127. ML_display_vram();
  128. if(GetObject()->GetRender()->GetisEnd())cinematic = false;
  129. Sleep(100);
  130. }
  131. ML_clear_vram();
  132. GetEngine()->GetMap()->AfficherMap();
  133. ML_display_vram();
  134. Sleep(250);
  135. GetObject()->GetRender()->SetIt(0);
  136. GetObject()->GetTransforms()->SetXY(116, 57);
  137. SGUI->DelVie(1);
  138. }