Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pragma once
- #include <windows.h>
- #include <conio.h>
- #include <iostream>
- #include <ctime>
- #include "Classes.h"
- using namespace std;
- #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)) & 0x8000 ? 1 : 0)
- void PressKey(int VkCode);
- int WheelCollision(Object** _Projectile, Grinder** _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile); //функция проверки столкновения обекта с колесом
- HDC hdc;
- int main()
- {
- int X_0 = 300; //начальные координаты по Х
- int Y_0 = 0; //начальные координаты по Y
- int Scale_0 = 1; //масштаб
- int randKey = 0; //ключ двигающегося объекта
- double Angle_0 = 30.0; //начальный угол колеса
- double current_Angle; //текущий угол колеса
- double Angle_step = 10.0; //шаг угла поворота
- int Step = 20; //шаг перемещения
- system("color F0");
- srand(time(NULL)); //задание зерна генеатора случайных чисел
- HWND hwnd = GetConsoleWindow();
- if (hwnd != NULL)
- {
- hdc = GetWindowDC(hwnd);
- if (hdc != 0)
- {
- Grinder _Grinder(X_0, Y_0, Scale_0, Angle_0); //мельница с трубой
- GrinderDamage _GrinderDamage(X_0, Y_0, Scale_0, Angle_0); //мельница без трубы
- Grinder* BufGrinder[2]; //массив мельниц
- BufGrinder[0] = &_Grinder;
- BufGrinder[1] = &_GrinderDamage;
- Grinder* pCurrGrinder = BufGrinder[0]; //указатель на текущую мельницу
- Rock _Rock(X_0, Y_0, Scale_0); //камень
- Wave _Wave(X_0, Y_0, Scale_0); //волна
- Health_mode _Health_mode(X_0, Y_0, Scale_0); //ремкомплект
- Object* BufProjectile[3]; //массив объектов
- BufProjectile[0] = &_Rock; //камень
- BufProjectile[1] = &_Wave; //волна
- BufProjectile[2] = &_Health_mode; //ремкомплект
- Object* pCurrProjectile = BufProjectile[0]; //указатель на текущий объект
- River _River(X_0, Y_0, Scale_0); //река
- Catcher _Catcher(X_0, Y_0, Scale_0); //ловец
- while (1)
- {
- if (KEY_DOWN(VK_ESCAPE))
- break;
- _River.Show(); //вывод на экран реки
- pCurrGrinder->Show(); //вывод на экран мельницы
- if (pCurrGrinder->GetRotation() == true)
- {
- current_Angle = pCurrGrinder->GetAngleWH(); //получение текущего угла поворта
- if (current_Angle < 90.0)
- {
- current_Angle += 10.0;
- }
- else current_Angle = 0;
- pCurrGrinder->SetAngleWH(current_Angle); //задание текущего угла поворта
- }
- pCurrProjectile->Show(); //отображения объекта взаимодействия
- _Catcher.Show(); //отображения ловца
- _Catcher.Drag(30); //перемещение ловца
- int res = WheelCollision(&pCurrProjectile, &pCurrGrinder, &_Catcher, randKey, Scale_0); //проверка взаимодействия
- if (res != 0) //объект столкнулся
- {
- pCurrProjectile->Hide(); //скрытие объекта
- randKey = rand() % 3; //генератор случайного числа от 0 до 2
- //выбор нового объекта
- if (randKey == 0) pCurrProjectile = BufProjectile[0];
- else if (randKey == 1) pCurrProjectile = BufProjectile[1];
- else if (randKey == 2) pCurrProjectile = BufProjectile[2];
- //перемещение нового объекта в начало координат
- pCurrProjectile->SetX(X_0);
- pCurrProjectile->SetY(Y_0);
- //объект столкнулся с мельницей
- if (res == 1)
- {
- pCurrGrinder = BufGrinder[1];
- }
- }
- pCurrProjectile->MoveTo(pCurrProjectile->GetX() + Step, pCurrProjectile->GetY()); //перпемещение объекта вправо
- Sleep(100);
- pCurrGrinder->Hide(); //скрытие мельницы
- _River.Hide(); //скрытие реки
- }
- }
- }
- }
- void PressKey(int VkCode)
- {
- while (1)
- {
- if (KEY_DOWN(VkCode))
- {
- break;
- }
- }
- }
- int WheelCollision(Object** pCurrProjectile, Grinder** _Grinder, Catcher* _Catcher, int _Key, int ScaleProjectile) //функция проверки столкновения обекта с ловцом или колесом
- {
- //проверка столкновения объекта и колеса мельницы
- if ((*pCurrProjectile)->GetX() > ((*_Grinder)->GetX())+ 600)
- {
- if (_Key == 0) (*_Grinder)->SetRotation(false);
- if (_Key == 2) (*_Grinder)->SetRotation(true);
- return 1;
- }
- int xProjectile = (*pCurrProjectile)->GetX();
- int yProjectile = (*pCurrProjectile)->GetY();
- int xCatcher = _Catcher->GetX();
- int yCatcher = _Catcher->GetY();
- int ScaleCatcher = _Catcher->GetScale();
- bool c1 = (xProjectile - 150 * ScaleProjectile) < (xCatcher + 20 * ScaleCatcher);
- bool c2 = (xProjectile - 100 * ScaleProjectile) > (xCatcher - 20 * ScaleCatcher);
- bool c3 = (yProjectile + 340 * ScaleProjectile) < (yCatcher + 390 * ScaleCatcher);
- bool c4 = (yProjectile + 380 * ScaleProjectile) > (yCatcher + 330 * ScaleCatcher);
- //проверка столкновения ловца и объекта
- if (c1 && c2 && c3 && c4)
- {
- return 2;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement