Advertisement
baadgeorge

сорс ласт

Jun 4th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.43 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(Object** _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.             Rock _Rock(X_0, Y_0, Scale_0); //камень
  48.             Wave _Wave(X_0, Y_0, Scale_0); //волна
  49.             Health_mode _Health_mode(X_0, Y_0, Scale_0); //ремкомплект
  50.             Object* BufProjectile[3]; //массив объектов
  51.             BufProjectile[0] = &_Rock; //камень
  52.             BufProjectile[1] = &_Wave; //волна
  53.             BufProjectile[2] = &_Health_mode; //ремкомплект
  54.  
  55.             Object* pCurrProjectile = BufProjectile[0]; //указатель на текущий объект
  56.  
  57.             River _River(X_0, Y_0, Scale_0); //река
  58.             Catcher _Catcher(X_0, Y_0, Scale_0); //ловец
  59.  
  60.             while (1)
  61.             {
  62.  
  63.                 if (KEY_DOWN(VK_ESCAPE))
  64.                     break;
  65.                 _River.Show(); //вывод на экран реки
  66.  
  67.                 pCurrGrinder->Show(); //вывод на экран мельницы
  68.  
  69.                 if (pCurrGrinder->GetRotation() == true)
  70.                 {
  71.                     current_Angle = pCurrGrinder->GetAngleWH(); //получение текущего угла поворта
  72.  
  73.                     if (current_Angle < 90.0)
  74.                     {
  75.                         current_Angle += 10.0;
  76.                     }
  77.                     else current_Angle = 0;
  78.  
  79.                     pCurrGrinder->SetAngleWH(current_Angle); //задание текущего угла поворта
  80.                 }
  81.  
  82.                 pCurrProjectile->Show(); //отображения объекта взаимодействия
  83.                
  84.                 _Catcher.Show(); //отображения ловца
  85.                
  86.                 _Catcher.Drag(30); //перемещение ловца
  87.                
  88.                 int res = WheelCollision(&pCurrProjectile, &pCurrGrinder, &_Catcher, randKey, Scale_0); //проверка взаимодействия
  89.  
  90.                 if (res != 0) //объект столкнулся
  91.                 {
  92.                     pCurrProjectile->Hide(); //скрытие объекта
  93.                     randKey = rand() % 3; //генератор случайного числа от 0 до 2
  94.                     //выбор нового объекта
  95.                     if (randKey == 0) pCurrProjectile = BufProjectile[0];
  96.                     else if (randKey == 1) pCurrProjectile = BufProjectile[1];
  97.                     else if (randKey == 2) pCurrProjectile = BufProjectile[2];
  98.  
  99.                     //перемещение нового объекта в начало координат
  100.                     pCurrProjectile->SetX(X_0);
  101.                     pCurrProjectile->SetY(Y_0);
  102.  
  103.                     //объект столкнулся с мельницей
  104.                     if (res == 1)
  105.                     {
  106.                         pCurrGrinder = BufGrinder[1];
  107.                        
  108.                     }
  109.                 }
  110.                 pCurrProjectile->MoveTo(pCurrProjectile->GetX() + Step, pCurrProjectile->GetY()); //перпемещение объекта вправо
  111.                
  112.                 Sleep(100);
  113.                 pCurrGrinder->Hide(); //скрытие мельницы
  114.                 _River.Hide(); //скрытие реки
  115.                
  116.             }
  117.         }
  118.     }
  119. }
  120.  
  121.  
  122. void PressKey(int VkCode)
  123. {
  124.     while (1)
  125.     {
  126.         if (KEY_DOWN(VkCode))
  127.         {
  128.             break;
  129.         }
  130.     }
  131. }
  132.  
  133. int WheelCollision(Object** pCurrProjectile, Grinder** _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile) //функция проверки столкновения обекта с ловцом или колесом
  134. {
  135.     //проверка столкновения объекта и колеса мельницы
  136.     if ((*pCurrProjectile)->GetX() > ((*_Grinder)->GetX())+ 600)
  137.     {
  138.         if (_Key == 0) (*_Grinder)->SetRotation(false);
  139.         if (_Key == 2) (*_Grinder)->SetRotation(true);
  140.         return 1;
  141.     }
  142.  
  143.     int xProjectile = (*pCurrProjectile)->GetX();
  144.     int yProjectile = (*pCurrProjectile)->GetY();
  145.  
  146.     int xCatcher = _Catcher->GetX();
  147.     int yCatcher = _Catcher->GetY();
  148.  
  149.     int ScaleCatcher = _Catcher->GetScale();
  150.  
  151.     bool c1 = (xProjectile - 150 * ScaleProjectile) < (xCatcher + 20 * ScaleCatcher);
  152.     bool c2 = (xProjectile - 100 * ScaleProjectile) > (xCatcher - 20 * ScaleCatcher);
  153.     bool c3 = (yProjectile + 340 * ScaleProjectile) < (yCatcher + 390 * ScaleCatcher);
  154.     bool c4 = (yProjectile + 380 * ScaleProjectile) > (yCatcher + 330 * ScaleCatcher);
  155.  
  156.     //проверка столкновения  ловца и объекта
  157.     if (c1 && c2 && c3 && c4)
  158.     {
  159.         return 2;
  160.     }
  161.    
  162.     return 0;
  163. }
  164.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement