Advertisement
baadgeorge

classes1

May 31st, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.29 KB | None | 0 0
  1. #include <windows.h>
  2. #include "Classes.h"
  3. #include <math.h>
  4.  
  5. #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
  6. #define PI 3.1415926535
  7.  
  8. extern HDC hdc;
  9.  
  10. Location::Location(int _X, int _Y)
  11. {
  12. X = _X;
  13. Y = _Y;
  14. }
  15.  
  16. Location::~Location() {}
  17.  
  18. int Location::GetX()
  19. {
  20. return X;
  21. }
  22.  
  23. int Location::GetY()
  24. {
  25. return Y;
  26. }
  27.  
  28. Point::Point(int _X, int _Y) : Location(_X, _Y)
  29. {
  30. isVisible = false;
  31. }
  32.  
  33.  
  34. Point::~Point() {}
  35.  
  36. void Point::Show()
  37. {
  38. isVisible = true;
  39. SetPixel(hdc, X, Y, RGB(0, 0, 255));
  40. }
  41.  
  42. void Point::Hide()
  43. {
  44. isVisible = false;
  45. SetPixel(hdc, X, Y, RGB(255, 0, 0));
  46. }
  47.  
  48. void Point::SetX(int _X)
  49. {
  50. X = _X;
  51. }
  52. void Point::SetY(int _Y)
  53. {
  54. Y = _Y;
  55. }
  56.  
  57. void Point::MoveTo(int NewX, int NewY)
  58. {
  59. Hide();
  60. X = NewX;
  61. Y = NewY;
  62. Show();
  63. }
  64.  
  65. void Point::Drag(int Step)
  66. {
  67. int FigX, FigY;
  68. FigX = GetX();
  69. FigY = GetY();
  70.  
  71. while (1)
  72. {
  73.  
  74. if (KEY_DOWN(VK_LEFT))
  75. {
  76. FigX -= Step;
  77. MoveTo(FigX, FigY);
  78. }
  79. if (KEY_DOWN(VK_RIGHT))
  80. {
  81. FigX += Step;
  82. MoveTo(FigX, FigY);
  83. }
  84. if (KEY_DOWN(VK_DOWN))
  85. {
  86. FigY += Step;
  87. MoveTo(FigX, FigY);
  88. }
  89. if (KEY_DOWN(VK_UP))
  90. {
  91. FigY -= Step;
  92. MoveTo(FigX, FigY);
  93. }
  94. Show();
  95. Sleep(200);
  96. Hide();
  97. }
  98.  
  99. }
  100.  
  101. Grinder::Grinder(int _X, int _Y, int _Scale, double _Angle) : Point(_X, _Y), wheel(_X, _Y, _Scale)
  102. {
  103. Scale = _Scale;
  104. wheel.SetAngle(_Angle);
  105.  
  106. }
  107.  
  108. Grinder::~Grinder() {}
  109.  
  110. void Grinder::Show()
  111. {
  112. HPEN pen;
  113. pen = CreatePen(PS_SOLID, 1, RGB(0, 255, 255));
  114. SelectObject(hdc, pen);
  115. HBRUSH brush;
  116.  
  117. //MoveToEx(hdc, X, Y, NULL);
  118.  
  119.  
  120. //vent
  121. brush = CreateSolidBrush(RGB(255, 0, 0));
  122. SelectObject(hdc, brush);
  123. Rectangle(hdc, X + 440 * Scale, Y + 200 * Scale, X + 460 * Scale, Y + 100 * Scale);
  124.  
  125. //top
  126. brush = CreateSolidBrush(RGB(0, 0, 255));
  127. SelectObject(hdc, brush);
  128. POINT vertices[] = { {X + 400 * Scale, Y + 100 * Scale}, {X + 500 * Scale, Y + 200 * Scale}, {X + 300 * Scale, Y + 200 * Scale} };
  129. Polygon(hdc, vertices, sizeof(vertices) / sizeof(vertices[0]));
  130. /*
  131. // hide old wheel
  132.  
  133.  
  134. wheel.SetAngle(angle_WH - 10);
  135. wheel.Hide();
  136. */
  137. //bottom
  138. brush = CreateSolidBrush(RGB(255, 155, 0));
  139. SelectObject(hdc, brush);
  140. Rectangle(hdc, X + 305 * Scale, Y + 200 * Scale, X + 495 * Scale, Y + 320 * Scale);
  141.  
  142. //window
  143. brush = CreateSolidBrush(RGB(155, 0, 255));
  144. SelectObject(hdc, brush);
  145. Rectangle(hdc, X + 365 * Scale, Y + 230 * Scale, X + 435 * Scale, Y + 290 * Scale);
  146. SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
  147. pen = CreatePen(PS_SOLID, 2, RGB(0, 255, 255));
  148. SelectObject(hdc, pen);
  149. MoveToEx(hdc, X + 400 * Scale, Y + 230 * Scale, NULL);
  150. LineTo(hdc, X + 400 * Scale, Y + 290 * Scale);
  151. MoveToEx(hdc, X + 365 * Scale, Y + 260 * Scale, NULL);
  152. LineTo(hdc, X + 435 * Scale, Y + 260 * Scale);
  153. MoveToEx(hdc, X, Y, NULL);
  154.  
  155. //outbilding
  156. brush = CreateSolidBrush(RGB(60, 155, 30));
  157. SelectObject(hdc, brush);
  158. pen = CreatePen(PS_SOLID, 1, RGB(0, 255, 255));
  159. SelectObject(hdc, pen);
  160. Rectangle(hdc, X + 495 * Scale, Y + 320 * Scale, X + 550 * Scale, Y + 250 * Scale);
  161.  
  162.  
  163. // show new wheel
  164. //double angle_WH = wheel.GetAngle();
  165. //wheel.SetAngle(angle_WH);
  166. wheel.SetX(X + 525 * Scale);
  167. wheel.SetY(Y + 300 * Scale);
  168.  
  169. wheel.Show();
  170.  
  171. DeleteObject(pen);
  172. DeleteObject(brush);
  173. }
  174.  
  175. void Grinder::Hide()
  176. {
  177. isVisible = false;
  178. HBRUSH rubber = CreateSolidBrush(RGB(243, 243, 243));
  179. HPEN pen = CreatePen(PS_SOLID, 1, RGB(243, 243, 243));
  180. SelectObject(hdc, pen);
  181. SelectObject(hdc, rubber);
  182. MoveToEx(hdc, X, Y, NULL);
  183. Rectangle(hdc, X + 300, Y + 100 * Scale, X + 600 * Scale, Y + 360 * Scale);
  184. wheel.SetX(X + 525 * Scale);
  185. wheel.SetY(Y + 300 * Scale);
  186.  
  187. wheel.Hide();
  188. DeleteObject(pen);
  189. DeleteObject(rubber);
  190. }
  191.  
  192. double Grinder::GetAngleWH()
  193. {
  194. return wheel.GetAngle();
  195. }
  196.  
  197. void Grinder::SetAngleWH(double _Angle)
  198. {
  199. wheel.SetAngle(_Angle);
  200. }
  201.  
  202. void Grinder::ChangeSize(int delta)
  203. {
  204. Hide();
  205. Scale = delta;
  206. Show();
  207. }
  208.  
  209. Rock::Rock(int _X, int _Y, int _Scale) : Point(_X, _Y)
  210. {
  211. X = _X;
  212. Y = _Y;
  213. Scale = _Scale;
  214. }
  215.  
  216. Rock::~Rock() {}
  217.  
  218. void Rock::Show()
  219. {
  220. HPEN pen;
  221. pen = CreatePen(PS_SOLID, 1, RGB(0, 255, 155));
  222. SelectObject(hdc, pen);
  223. HBRUSH brush;
  224. MoveToEx(hdc, X, Y, NULL);
  225.  
  226. brush = CreateSolidBrush(RGB(155, 0, 0));
  227. SelectObject(hdc, brush);
  228. Ellipse(hdc, X - 150 * Scale, Y + 340 * Scale, X - 100 * Scale, Y + 380 * Scale);
  229. }
  230.  
  231. void Rock::Hide()
  232. {
  233. isVisible = false;
  234. HBRUSH rubber = CreateSolidBrush(RGB(0, 0, 150));
  235. HPEN pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 150));
  236. SelectObject(hdc, pen);
  237. SelectObject(hdc, rubber);
  238. MoveToEx(hdc, X, Y, NULL);
  239. Ellipse(hdc, X - 150 * Scale, Y + 340 * Scale, X - 100 * Scale, Y + 380 * Scale);
  240.  
  241. }
  242.  
  243. Wheel::Wheel(int _X, int _Y, int _Radius) : Point(_X, _Y)
  244. {
  245. Radius = _Radius;
  246. Angle = 0.0;
  247. }
  248.  
  249. Wheel::~Wheel()
  250. {
  251. }
  252.  
  253. void Wheel::Show()
  254. {
  255. HPEN pen;
  256. HBRUSH brush;
  257.  
  258. //wheel
  259. SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
  260. pen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
  261. SelectObject(hdc, pen);
  262. Ellipse(hdc, X - 50 * Radius, Y + 50 * Radius, X + 50 * Radius, Y - 50 * Radius);
  263.  
  264. brush = CreateSolidBrush(RGB(0, 0, 0));
  265. SelectObject(hdc, brush);
  266. Ellipse(hdc, X - 5 * Radius, Y + 5 * Radius, X + 5 * Radius, Y - 5 * Radius);
  267.  
  268. SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
  269. pen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
  270. int line = 115 * Radius;
  271. int lineRadius = line / 2;
  272.  
  273. MoveToEx(hdc, X + lineRadius * cos(Angle * PI / 180), Y + lineRadius * sin(Angle * PI / 180), NULL);
  274. LineTo(hdc, X - lineRadius * cos(Angle * PI / 180), Y - lineRadius * sin(Angle * PI / 180));
  275.  
  276. MoveToEx(hdc, X + lineRadius * cos((Angle + 90) * PI / 180), Y + lineRadius * sin((Angle + 90) * PI / 180), NULL);
  277. LineTo(hdc, X - lineRadius * cos((Angle + 90) * PI / 180), Y - lineRadius * sin((Angle + 90) * PI / 180));
  278.  
  279. DeleteObject(pen);
  280. DeleteObject(brush);
  281.  
  282. Angle += 10.0;
  283. }
  284.  
  285. void Wheel::Hide()
  286. {
  287. HBRUSH rubber = CreateSolidBrush(RGB(243, 243, 243));
  288. HPEN pen = CreatePen(PS_SOLID, 3, RGB(243, 243, 243));
  289. SelectObject(hdc, pen);
  290. SelectObject(hdc, rubber);
  291. MoveToEx(hdc, X, Y, NULL);
  292. int line = 115 * Radius;
  293. int lineRadius = line / 2;
  294.  
  295. MoveToEx(hdc, X + lineRadius * cos(Angle * PI / 180), Y + lineRadius * sin(Angle * PI / 180), NULL);
  296. LineTo(hdc, X - lineRadius * cos(Angle * PI / 180), Y - lineRadius * sin(Angle * PI / 180));
  297.  
  298. MoveToEx(hdc, X + lineRadius * cos((Angle + 90) * PI / 180), Y + lineRadius * sin((Angle + 90) * PI / 180), NULL);
  299. LineTo(hdc, X - lineRadius * cos((Angle + 90) * PI / 180), Y - lineRadius * sin((Angle + 90) * PI / 180));
  300.  
  301. DeleteObject(pen);
  302. DeleteObject(rubber);
  303.  
  304. }
  305.  
  306. void Wheel::SetAngle(double _Angle)
  307. {
  308. Angle = _Angle;
  309. }
  310.  
  311.  
  312. double Wheel::GetAngle()
  313. {
  314. return Angle;
  315. }
  316.  
  317.  
  318. River::River(int _X, int _Y, int _Scale) : Point(_X, _Y)
  319. {
  320. X = _X;
  321. Y = _Y;
  322. Scale = _Scale;
  323. }
  324.  
  325. River::~River()
  326. {
  327. }
  328.  
  329. void River::Show()
  330. {
  331. HBRUSH brush;
  332. brush = CreateSolidBrush(RGB(0, 0, 140));
  333. SelectObject(hdc, brush);
  334. Rectangle(hdc, X - 290 * Scale, Y + 320 * Scale, X + 660 * Scale, Y + 450 * Scale);
  335. }
  336.  
  337. void River::Hide()
  338. {
  339. HBRUSH brush = CreateSolidBrush(RGB(243, 243, 243));
  340. HPEN pen = CreatePen(PS_SOLID, 3, RGB(243, 243, 243));
  341. SelectObject(hdc, pen);
  342. SelectObject(hdc, brush);
  343. Rectangle(hdc, X - 290 * Scale, Y + 320 * Scale, X + 660 * Scale, Y + 450 * Scale);
  344. }
  345.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement