Advertisement
baadgeorge

source

Jun 4th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. # pragma once
  2. #include <windows.h>
  3. #include <conio.h>
  4. #include <iostream>
  5. #include <ctime>
  6. #include "Classes.h"
  7.  
  8. using namespace std;
  9.  
  10. #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)) & 0x8000 ? 1 : 0)
  11.  
  12. void PressKey(int VkCode);
  13.  
  14. int WheelCollision(Point** _Projectile, Grinder* _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile); //функция проверки столкновения обекта с колесом
  15.  
  16. HDC hdc;
  17.  
  18. int main()
  19. {
  20. int X_0 = 300; //начальные координаты по Х
  21. int Y_0 = 0; //начальные координаты по Y
  22. int Scale_0 = 1; //масштаб
  23. int randKey = 0; //ключ двигающегося объекта
  24. double Angle_0 = 30.0; //начальный угол колеса
  25. double current_Angle; //текущий угол колеса
  26. double Angle_step = 10.0; //шаг угла поворота
  27. int Step = 20; //шаг перемещения
  28. system("color F0");
  29.  
  30. srand(time(NULL)); // задание зерна генеатора случайных чисел
  31.  
  32. HWND hwnd = GetConsoleWindow();
  33.  
  34. if (hwnd != NULL)
  35. {
  36. hdc = GetWindowDC(hwnd);
  37. if (hdc != 0)
  38. {
  39. Grinder _Grinder(X_0, Y_0, Scale_0, Angle_0);
  40. GrinderDamage _GrinderDamage(X_0, Y_0, Scale_0, Angle_0);
  41. Grinder* BufGrinder[2];
  42. BufGrinder[0] = &_Grinder;
  43. BufGrinder[1] = &_GrinderDamage;
  44.  
  45. Grinder* pCurrGrinder = BufGrinder[0];
  46.  
  47. //Point* _Projectile = NULL; //указатель на объект взаимодействи
  48. Point* BufProjectile[3];
  49. BufProjectile[0] = (Point*) new Rock(X_0, Y_0, Scale_0);
  50. BufProjectile[1] = (Point*) new Wave(X_0, Y_0, Scale_0);
  51. BufProjectile[2] = (Point*) new Health_mode(X_0, Y_0, Scale_0);
  52. Point* pCurrProjectile = BufProjectile[0];
  53.  
  54. River _River(X_0, Y_0, Scale_0);
  55. Catcher _Catcher(X_0, Y_0, Scale_0);
  56.  
  57. while (1)
  58. {
  59.  
  60. if (KEY_DOWN(VK_ESCAPE))
  61. break;
  62. _River.Show(); //вывод на экран реки
  63.  
  64. pCurrGrinder->Show(); //вывод на экран мельницы
  65.  
  66. if (pCurrGrinder->GetRotation() == true)
  67. {
  68. current_Angle = pCurrGrinder->GetAngleWH(); //получение текущего угла поворта
  69.  
  70. if (current_Angle < 90.0)
  71. {
  72. current_Angle += 10.0;
  73. }
  74. else current_Angle = 0;
  75.  
  76. pCurrGrinder->SetAngleWH(current_Angle); //задание текущего угла поворта
  77. }
  78.  
  79. pCurrProjectile->Show(); //отображения объекта взаимодействия
  80.  
  81. _Catcher.Show(); //отображения ловца
  82.  
  83. _Catcher.Drag(30); //перемещение ловца
  84.  
  85. if (pCurrProjectile != NULL) pCurrProjectile->MoveTo(pCurrProjectile->GetX() + Step, pCurrProjectile->GetY());
  86.  
  87. int res = WheelCollision(&pCurrProjectile, pCurrGrinder, &_Catcher, randKey, Scale_0); //проверка взаимодействия
  88.  
  89. if (res == 1)
  90. {
  91. //pCurrGrinder = BufGrinder[1];
  92. pCurrProjectile->Hide();
  93. randKey = rand() % 3; //генератор случайного числа от 0 до 2
  94. if (randKey == 0) pCurrProjectile = BufProjectile[0];
  95. else if (randKey == 1) pCurrProjectile = BufProjectile[1];
  96. else if (randKey == 2) pCurrProjectile = BufProjectile[2];
  97. }
  98. if (res == 2)
  99. {
  100. }
  101.  
  102.  
  103.  
  104. Sleep(100);
  105. pCurrGrinder->Hide(); //скрытие меьницы
  106. _River.Hide(); //скрытие реки
  107. //if (_Projectile != NULL) _Projectile->Hide(); //скрытие объекта взаимодествия, если он существует
  108. }
  109. }
  110. }
  111. }
  112.  
  113.  
  114. void PressKey(int VkCode)
  115. {
  116. while (1)
  117. {
  118. if (KEY_DOWN(VkCode))
  119. {
  120. break;
  121. }
  122. }
  123. }
  124.  
  125. int WheelCollision(Point** pCurrProjectile, Grinder* _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile) //функция проверки столкновения обекта с ловцом или колесом
  126. {
  127. if ((*pCurrProjectile)->GetX() > 890)
  128. {
  129. if (_Key == 0) _Grinder->SetRotation(false);
  130. if (_Key == 2) _Grinder->SetRotation(true);
  131. //delete (*pCurrProjectile);
  132. //(*pCurrProjectile) = NULL;
  133. return 1;
  134. }
  135.  
  136. int xProjectile = (*pCurrProjectile)->GetX();
  137. int yProjectile = (*pCurrProjectile)->GetY();
  138.  
  139. int xCatcher = _Catcher->GetX();
  140. int yCatcher = _Catcher->GetY();
  141.  
  142. int ScaleCatcher = _Catcher->GetScale();
  143.  
  144. bool c1 = (xProjectile - 150 * ScaleProjectile) < (xCatcher + 20 * ScaleCatcher);
  145. bool c2 = (xProjectile - 100 * ScaleProjectile) > (xCatcher - 20 * ScaleCatcher);
  146. bool c3 = (yProjectile + 340 * ScaleProjectile) < (yCatcher + 390 * ScaleCatcher);
  147. bool c4 = (yProjectile + 380 * ScaleProjectile) > (yCatcher + 330 * ScaleCatcher);
  148.  
  149. if (c1 && c2 && c3 && c4) //если области ловца и объекта наложились
  150. {
  151. return 2;
  152. }
  153.  
  154. return 2;
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement