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.

Perso.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "Perso.hpp"
  2. void Control ::Start()
  3. {
  4. couldown = 0;
  5. Vie=40;
  6. BarreVie=0;
  7. VieMax=40;
  8. p_epee->Disable();
  9. p_epee->AffectTag("Epee");
  10. }
  11. void Control::Teleport( int x , int y , int level )
  12. {
  13. GetEngine()->GetCurrentLevel()->DrawLevel();
  14. for(int i = 0 ; i < 190 ; i ++)
  15. {
  16. ML_line(0,i,i,0,ML_BLACK);
  17. ML_display_vram();
  18. Sleep(3);
  19. }
  20. GetEngine()->MoveObject(GetObject(),level);
  21. GetEngine()->MoveObject(p_epee,level);
  22. GetEngine()->SetCurrentLevel(level);
  23. GetObject()->GetTransform()->SetXY(x,y);
  24. }
  25. void Control::Update()
  26. {
  27. BarreVie=Vie*40/VieMax;
  28. ML_line (126,40,126,40-BarreVie,ML_BLACK);
  29. ML_rectangle(125,1,127,42,1,ML_BLACK,ML_BLACK);
  30. Object * Buffer = GetObject()->GetObjectCollisionTag("Slime");
  31. if(Buffer != NULL)
  32. {
  33. Vie--;
  34. int difx = GetObject()->GetTransform()->GetX() - Buffer->GetTransform()->GetX();
  35. int dify = GetObject()->GetTransform()->GetY() - Buffer->GetTransform()->GetY();
  36. GetObject()->GetRigidBody()->Move(difx * 2 ,dify * 2);
  37. }
  38. if (input_trigger(K_SHIFT) || couldown > 0)
  39. {
  40. couldown --;
  41. if(couldown < 0) couldown = 10;
  42. switch (Direction_p)
  43. {
  44. case 1:
  45. GetObject()->GetRender()->SetIt(7);
  46. p_epee->GetTransform()->SetXY(GetObject()->GetTransform()->GetX() + 1,GetObject()->GetTransform()->GetY() + 12);
  47. p_epee->GetRender()->SetDirection(0);
  48. break;
  49. case 2:
  50. GetObject()->GetRender()->SetIt(8);
  51. GetObject()->GetRender()->ReverseRender(true);
  52. p_epee->GetTransform()->SetXY(GetObject()->GetTransform()->GetX()+14,GetObject()->GetTransform()->GetY()-2);
  53. p_epee->GetRender()->SetDirection(270);
  54. break;
  55. case 3:
  56. GetObject()->GetRender()->SetIt(6);
  57. p_epee->GetTransform()->SetXY(GetObject()->GetTransform()->GetX() + 6,GetObject()->GetTransform()->GetY() - 12);
  58. p_epee->GetRender()->SetDirection(180);
  59. break;
  60. case 4:
  61. GetObject()->GetRender()->SetIt(8);
  62. GetObject()->GetRender()->ReverseRender(false);
  63. p_epee->GetTransform()->SetXY(GetObject()->GetTransform()->GetX() - 8,GetObject()->GetTransform()->GetY() - 3);
  64. p_epee->GetRender()->SetDirection(90);
  65. break;
  66. }
  67. p_epee->Enable();
  68. }
  69. else
  70. {
  71. p_epee->Disable();
  72. if(input_press(K_RIGHT))
  73. {
  74. GetObject()->GetRigidBody()->Move(1,0);
  75. GetObject()->GetRender()->SetIt(5);
  76. GetObject()->GetRender()->ReverseRender(true);
  77. Direction_p=2;
  78. }
  79. else if(input_press(K_LEFT))
  80. {
  81. GetObject()->GetRigidBody()->Move(-1,0);
  82. GetObject()->GetRender()->SetIt(5);
  83. GetObject()->GetRender()->ReverseRender(false);
  84. Direction_p=4;
  85. }
  86. else if(input_press(K_UP))
  87. {
  88. GetObject()->GetRigidBody()->Move (0,1);
  89. GetObject()->GetRender()->SetIt(3);
  90. Direction_p=1;
  91. }
  92. else if(input_press(K_DOWN))
  93. {
  94. GetObject()->GetRigidBody()->Move (0,-1);
  95. GetObject()->GetRender()->SetIt(1);
  96. Direction_p=3;
  97. }
  98. else
  99. {
  100. switch (Direction_p)
  101. {
  102. case 1:GetObject()->GetRender()->SetIt(2);break;
  103. case 2:GetObject()->GetRender()->SetIt(4);break;
  104. case 3:GetObject()->GetRender()->SetIt(0);break;
  105. case 4:GetObject()->GetRender()->SetIt(4);break;
  106. }
  107. }
  108. }
  109. if (input_press(K_EXIT))GetEngine()->StopGame();
  110. GetEngine()->MiddleScreen(GetObject()->GetTransform()->GetX() + 6 , GetObject()->GetTransform()->GetY() + 6);
  111. }