SSemen

Untitled

Nov 14th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.97 KB | None | 0 0
  1. // Глобальные для фона
  2.  
  3. // то что менять НЕЛЬЗЯ
  4. int map_size_x = 320; //  длина по х одного куска
  5. int map_size_y = 25; // ширина по у одного куска
  6.  
  7.  
  8.  
  9. //то что менять можно, но уже нельзя
  10. int x_gor = 565; // уровень линии горизонта    ОРИГИНАЛ 500
  11. int map_cx[4] = { 0, 320, 640,960};// координаты по x
  12. int map_cy = 65; // координаты по у           ОРИГИНАЛ 0
  13.  
  14.  
  15. //массив карандашей для фона
  16. #define N_hPen_map 6
  17. HPEN hPen_map[N_hPen_map] = {
  18.     CreatePen(PS_SOLID, 2, RGB(61, 18, 60)), //кисть для гор
  19.     CreatePen(PS_SOLID, 2, RGB(89,18,60)),// для холмов
  20.     CreatePen(PS_SOLID, 2, RGB(116, 35, 94)), //для земли
  21.     CreatePen(PS_SOLID, 2, RGB(255, 255, 255)),
  22.     CreatePen(PS_SOLID, 2, RGB(128,0,0)),
  23.     CreatePen(PS_SOLID, 4, RGB(64,0,0))
  24. };
  25.  
  26.  
  27. // массив кистей для фона
  28. #define N_MapBr 5
  29. HBRUSH hbrush_map[N_MapBr] = {
  30.     CreateSolidBrush(RGB(61, 18, 60)),//кисть для гор
  31.     CreateSolidBrush(RGB(89,18,60)),//для холмлв
  32.     CreateSolidBrush(RGB(116,35,94)),//для земли
  33.     CreateSolidBrush(RGB(128,38,98)),
  34.     CreateSolidBrush(RGB(128,0,0))
  35.  
  36. };
  37.  
  38.  
  39.  
  40.  ////////// НАЧАЛО ФОНА
  41.  
  42. void stars(HDC hdc, int n) {
  43.     SetPixel(hdc, map_cx[n] + 43, map_cy + 14, RGB(255, 255, 255));
  44.     SetPixel(hdc, map_cx[n] + 25, map_cy + 89, RGB(255, 255, 255));
  45.     SetPixel(hdc, map_cx[n] + 12, map_cy + 189, RGB(255, 255, 255));
  46.     SetPixel(hdc, map_cx[n] + 64, map_cy + 161, RGB(255, 255, 255));
  47.     SetPixel(hdc, map_cx[n] + 128, map_cy + 32, RGB(255, 255, 255));
  48.     SetPixel(hdc, map_cx[n] + 250, map_cy + 132, RGB(255, 255, 255));
  49.     SetPixel(hdc, map_cx[n] + 190, map_cy + 196, RGB(255, 255, 255));
  50.     SetPixel(hdc, map_cx[n] + 310, map_cy + 45, RGB(255, 255, 255));
  51.     SetPixel(hdc, map_cx[n] + 165, map_cy + 100, RGB(255, 255, 255));
  52.     SetPixel(hdc, map_cx[n] + 227, map_cy + 19, RGB(255, 255, 255));
  53.     SetPixel(hdc, map_cx[n] + 284, map_cy + 175, RGB(255, 255, 255));
  54.     SetPixel(hdc, map_cx[n] + 131, map_cy + 225, RGB(255, 255, 255));
  55.     SetPixel(hdc, map_cx[n] + 90, map_cy + 90, RGB(255, 255, 255));
  56.     SetPixel(hdc, map_cx[n] + 170, map_cy + 259, RGB(255, 255, 255));
  57. }
  58.  
  59. //СОЗДАЕМ ГРАДИЕНТНУЮ КИСТЬ ДЛЯ НЕБА - слой 1-4
  60. void HBRUSH_SKY_1(HDC hdc) {
  61.     int x = 50;
  62.     int y = 0;
  63.     int z = 150;
  64.     int i = 0;
  65.     int cx = map_cx[0];
  66.     int cy = map_cy;
  67.     while (i < 18) {
  68.         HBRUSH  hBrush = CreateSolidBrush(RGB(x, y, z));
  69.         SelectObject(hdc, hBrush);
  70.         HPEN hpen = CreatePen(PS_SOLID, 2, RGB(x, y, z));
  71.         SelectObject(hdc, hpen);
  72.         Rectangle(hdc, cx, cy, cx + map_size_x, cy + map_size_y);
  73.         DeleteObject(hBrush);
  74.         DeleteObject(hpen);
  75.         cx = map_cx[0];
  76.         cy += map_size_y;
  77.         i++;
  78.         x+=5;
  79.         y++;
  80.         z+=3;
  81.     }
  82.    
  83. }
  84.  
  85. void HBRUSH_SKY_2(HDC hdc) {
  86.     int x = 50;
  87.     int y = 0;
  88.     int z = 150;
  89.     int i = 0;
  90.     int cx = map_cx[1];
  91.     int cy = map_cy;
  92.     while (i < 18) {
  93.         HBRUSH  hBrush = CreateSolidBrush(RGB(x, y, z));
  94.         SelectObject(hdc, hBrush);
  95.         HPEN hpen = CreatePen(PS_SOLID, 2, RGB(x, y, z));
  96.         SelectObject(hdc, hpen);
  97.         Rectangle(hdc, cx, cy, cx + map_size_x, cy + map_size_y);
  98.         DeleteObject(hBrush);
  99.         DeleteObject(hpen);
  100.         cx = map_cx[1];
  101.         cy += map_size_y;
  102.         i++;
  103.         x += 5;
  104.         y++;
  105.         z += 3;
  106.     }
  107.  
  108. }
  109.  
  110.  
  111. void HBRUSH_SKY_3(HDC hdc) {
  112.     int x = 50;
  113.     int y = 0;
  114.     int z = 150;
  115.     int i = 0;
  116.     int cx = map_cx[2];
  117.     int cy = map_cy;
  118.     while (i < 18) {
  119.         HBRUSH  hBrush = CreateSolidBrush(RGB(x, y, z));
  120.         SelectObject(hdc, hBrush);
  121.         HPEN hpen = CreatePen(PS_SOLID, 2, RGB(x, y, z));
  122.         SelectObject(hdc, hpen);
  123.         Rectangle(hdc, cx, cy, cx + map_size_x, cy + map_size_y);
  124.         DeleteObject(hBrush);
  125.         DeleteObject(hpen);
  126.         cx = map_cx[2];
  127.         cy += map_size_y;
  128.         i++;
  129.         x += 5;
  130.         y++;
  131.         z += 3;
  132.     }
  133.  
  134. }
  135.  
  136. void HBRUSH_SKY_4(HDC hdc) {
  137.     int x = 50;
  138.     int y = 0;
  139.     int z = 150;
  140.     int i = 0;
  141.     int cx = map_cx[3];
  142.     int cy = map_cy;
  143.     while (i < 18) {
  144.         HBRUSH  hBrush = CreateSolidBrush(RGB(x, y, z));
  145.         SelectObject(hdc, hBrush);
  146.         HPEN hpen = CreatePen(PS_SOLID, 2, RGB(x, y, z));
  147.         SelectObject(hdc, hpen);
  148.         Rectangle(hdc, cx, cy, cx + map_size_x, cy + map_size_y);
  149.         DeleteObject(hBrush);
  150.         DeleteObject(hpen);
  151.         cx = map_cx[3];
  152.         cy += map_size_y;
  153.         i++;
  154.         x += 5;
  155.         y++;
  156.         z += 3;
  157.     }
  158.  
  159. }
  160.  
  161. // СЛОЙ 2 - горы вдали, куски 1-4
  162.  
  163.  
  164.  
  165. void decorate_1_mountain(HDC hdc) {
  166.     POINT pt[14] = {
  167.         {map_cx[0], map_cy + 260},
  168.         {map_cx[0] + 40, map_cy + 300},
  169.         {map_cx[0] + 82, map_cy + 220},
  170.         {map_cx[0] + 105, map_cy + 275},
  171.         {map_cx[0] + 115, map_cy + 260},
  172.         {map_cx[0] + 160, map_cy + 320},
  173.         {map_cx[0] + 180 , map_cy + 290 },
  174.         {map_cx[0] + 195, map_cy + 271 },
  175.         {map_cx[0] + 220, map_cy + 256 },
  176.         {map_cx[0] + 240, map_cy + 278 },
  177.         {map_cx[0] + 280, map_cy + 200 },
  178.         {map_cx[0] + map_size_x , map_cy + 250 },
  179.         {map_cx[0] + map_size_x , map_cy + x_gor},
  180.         {map_cx[0] , map_cy + x_gor}
  181.  
  182.     };
  183.     SelectObject(hdc, hPen_map[0]);
  184.     SelectObject(hdc, hbrush_map[0]);
  185.     Polygon(hdc, pt, 14);
  186.     stars(hdc, 0);
  187.    
  188.    
  189. }
  190.  
  191.  
  192. void decorate_2_mountain(HDC hdc) {
  193.     POINT pt[15] = {
  194.         {map_cx[1], map_cy + 250},
  195.         {map_cx[1] + 20, map_cy + 240},
  196.         {map_cx[1] + 47, map_cy + 255},
  197.         {map_cx[1] + 62, map_cy + 210},
  198.         {map_cx[1] + 100, map_cy + 250},
  199.         {map_cx[1] + 115, map_cy + 270},
  200.         {map_cx[1] + 160, map_cy + 290},
  201.         {map_cx[1] + 180 , map_cy + 260 },
  202.         {map_cx[1] + 195, map_cy + 241 },
  203.         {map_cx[1] + 220, map_cy + 266 },
  204.         {map_cx[1] + 240, map_cy + 278 },
  205.         {map_cx[1] + 280, map_cy + 200 },
  206.         {map_cx[1] + map_size_x , map_cy + 250 },
  207.         {map_cx[1] + map_size_x , map_cy + x_gor},
  208.         {map_cx[1] , map_cy + x_gor}
  209.  
  210.     };
  211.     SelectObject(hdc, hPen_map[0]);
  212.     SelectObject(hdc, hbrush_map[0]);
  213.     Polygon(hdc, pt, 15);
  214.     stars(hdc, 1);
  215. }
  216.  
  217.  
  218. void decorate_3_mountain(HDC hdc) {
  219.     POINT pt[11] = {
  220.         {map_cx[2], map_cy + 250},
  221.         {map_cx[2] + 80, map_cy + 320},
  222.         {map_cx[2] + 100, map_cy + 290 },
  223.         {map_cx[2] + 120, map_cy + 305},
  224.         {map_cx[2] + 160, map_cy + 270 },
  225.         {map_cx[2] + 195 , map_cy + 300},
  226.         {map_cx[2] + 230 , map_cy + 255},
  227.         {map_cx[2] + 260, map_cy + 270 },
  228.         {map_cx[2] + map_size_x, map_cy + 230 },
  229.         {map_cx[2] + map_size_x , map_cy + x_gor },
  230.         {map_cx[2] , map_cy + x_gor }
  231.  
  232.     }; 
  233.     SelectObject(hdc, hPen_map[0]);
  234.     SelectObject(hdc, hbrush_map[0]);
  235.     Polygon(hdc, pt, 11);
  236.     stars(hdc, 2);
  237. }
  238.  
  239.  
  240. void decorate_4_mountain(HDC hdc) {
  241.     POINT pt[13] = {
  242.         {map_cx[3], map_cy + 230},
  243.         {map_cx[3] + 68, map_cy + 285},
  244.         {map_cx[3] + 96, map_cy + 270 },
  245.         {map_cx[3] + 110, map_cy + 300},
  246.         {map_cx[3] + 125, map_cy + 290 },
  247.         {map_cx[3] + 170 , map_cy + 340},
  248.         {map_cx[3] + 185 , map_cy + 325},
  249.         {map_cx[3] + 195, map_cy + 333 },
  250.         {map_cx[3] + 250, map_cy + 283},
  251.         {map_cx[3] + 270, map_cy + 310 },
  252.         {map_cx[3] + map_size_x -1, map_cy + 260 },
  253.         {map_cx[3] + map_size_x -1, map_cy + x_gor},
  254.         {map_cx[3] , map_cy + x_gor}
  255.  
  256.     };
  257.     SelectObject(hdc, hPen_map[0]);
  258.     SelectObject(hdc, hbrush_map[0]);
  259.     Polygon(hdc, pt, 13);
  260.     stars(hdc, 3);
  261. }
  262.  
  263.  
  264.  
  265. // СЛОЙ 3 равнины + деревья
  266.  
  267.  
  268. /// Деревья
  269.  
  270. void Tree(HDC hdc, int x, int y, int size) {
  271.     SelectObject(hdc, hbrush_map[4]);
  272.     SelectObject(hdc, hPen_map[4]);
  273.     Ellipse(hdc, x, y, x + size, y + size);
  274.     Ellipse(hdc, x, y, x - size, y + size);
  275.     Ellipse(hdc, x - 0.5 * size, y - 0.7 * size, x + 0.5 * size, y + 0.3 * size);
  276.     SelectObject(hdc, hPen_map[5]);
  277.     MoveToEx(hdc, x, y + 0.4*size, NULL);
  278.     LineTo(hdc, x, y + 2 * size);
  279.     MoveToEx(hdc, x, y, NULL);
  280.    
  281.  
  282.  
  283. }
  284.  
  285.  
  286.  
  287. void  Fild_1(HDC hdc) {
  288.     //задний план
  289.     POINT pt2[7] = {
  290.         {map_cx[0], map_cy + 425},
  291.         {map_cx[0]+ 45, map_cy + 405},
  292.         {map_cx[0] + 140, map_cy + 440},
  293.         {map_cx[0] + 271, map_cy + 392},
  294.         {map_cx[0] + map_size_x, map_cy + 409},
  295.         {map_cx[0] + map_size_x, map_cy + x_gor + 3},
  296.         {map_cx[0], map_cy + x_gor +3}
  297.     };
  298.     SelectObject(hdc, hPen_map[1]);
  299.     SelectObject(hdc, hbrush_map[1]);
  300.     // передний план
  301.    
  302.     Polygon(hdc, pt2, 7);
  303.     POINT pt1[6] = {
  304.         {map_cx[0], map_cy + 433},
  305.         {map_cx[0] +40, map_cy + 445},
  306.         {map_cx[0] + 132, map_cy + 420},
  307.         {map_cx[0] + map_size_x, map_cy + 465},
  308.         {map_cx[0] + map_size_x, map_cy + x_gor + 3},
  309.         {map_cx[0], map_cy + x_gor + 3}
  310.     };
  311.     SelectObject(hdc, hbrush_map[2]);
  312.     Polygon(hdc, pt1, 6);
  313.     SelectObject(hdc, hPen_map[2]);
  314.     Rectangle(hdc, map_cx[0], x_gor, map_cx[0] + map_size_x, map_size_y * 7 + x_gor);
  315.     Tree(hdc, map_cx[0] + 300, x_gor - 20 , 20);
  316.     Tree(hdc, map_cx[0] + 170, x_gor - 70, 20);
  317.     Tree(hdc, map_cx[0] + 145, x_gor - 50, 10);
  318.     Tree(hdc, map_cx[0] + 60, x_gor + 80, 35);
  319. }
  320.  
  321.  
  322.  
  323. void  Fild_2(HDC hdc) {
  324.     POINT pt2[7] = {
  325.         {map_cx[1], map_cy + 410},
  326.         {map_cx[1] + 50, map_cy + 420},
  327.         {map_cx[1] + 200, map_cy + 415},
  328.         {map_cx[1] + map_size_x, map_cy + 460},
  329.         {map_cx[1] + map_size_x, map_cy + x_gor + 3},
  330.         {map_cx[1] + 123, map_cy + x_gor + 3 },
  331.         {map_cx[1], map_cy + 465}
  332.        
  333.     };
  334.     SelectObject(hdc, hPen_map[1]);
  335.     SelectObject(hdc, hbrush_map[1]);
  336.     Polygon(hdc, pt2, 7);
  337.     //продолжение переднего плана
  338.     POINT pt1[3] = {
  339.         { map_cx[1], map_cy + 467},
  340.         {map_cx[1] + 310, map_cy + x_gor + 3},
  341.         {map_cx[1] , map_cy + x_gor + 3}
  342.     };
  343.     SelectObject(hdc, hPen_map[2]);
  344.     SelectObject(hdc, hbrush_map[2]);
  345.     Polygon(hdc, pt1, 3);
  346.     Rectangle(hdc, map_cx[1],x_gor, map_cx[1] + map_size_x, map_size_y*7 + x_gor);
  347.     SelectObject(hdc, hPen_map[1]);
  348.     SelectObject(hdc, hbrush_map[1]);
  349.     MoveToEx(hdc, map_cx[1], map_cy + 466, NULL); // дорисовываем линии холмов
  350.     LineTo(hdc, map_cx[1] + 160, map_cy + 515);
  351.     MoveToEx(hdc, map_cx[1] + map_size_x, map_cy + 503, NULL);
  352.     LineTo(hdc, map_cx[1] + 280, map_cy + 510);
  353.    
  354.     Tree(hdc, map_cx[1] + 148, x_gor - 21, 10);
  355.     Tree(hdc, map_cx[1] + 160, x_gor  - 10, 5);
  356.     Tree(hdc, map_cx[1] + 130, x_gor - 15, 8);
  357. }
  358.  
  359.  
  360. void  Fild_3(HDC hdc) {
  361.     POINT pt2[3] = {
  362.         {map_cx[2], map_cy + 460},
  363.         {map_cx[2] + 220, x_gor + 30},
  364.         {map_cx[2], map_cy + x_gor + 3}
  365.     };
  366.     SelectObject(hdc, hPen_map[1]);
  367.     SelectObject(hdc, hbrush_map[1]);
  368.     Polygon(hdc, pt2, 3);
  369.     //передний план
  370.     POINT pt1[3] = {
  371.         {map_cx[2] ,  x_gor + 3},
  372.         {map_cx[2] + 180, map_cy + 460},
  373.         {map_cx[2] + map_size_x,x_gor + 3}
  374.     };
  375.  
  376.     SelectObject(hdc, hbrush_map[2]);
  377.     Polygon(hdc, pt1, 3);
  378.     SelectObject(hdc, hPen_map[2]);
  379.     Rectangle(hdc, map_cx[2], x_gor, map_cx[2] + map_size_x, map_size_y * 7 + x_gor);
  380.     SelectObject(hdc, hPen_map[1]);
  381.     MoveToEx(hdc, map_cx[2] + 28, + x_gor - 3, NULL); // дорисовываем линии холмов
  382.     LineTo(hdc, map_cx[2]-1, map_cy + 503);
  383.     MoveToEx(hdc, map_cx[2] + 300,  x_gor - 3, NULL); // дорисовываем линии холмов
  384.     LineTo(hdc, map_cx[2] + map_size_x , x_gor + 5);
  385.     Tree(hdc, map_cx[2] + 46, x_gor - 30, 15);
  386.     Tree(hdc, map_cx[2] + 246, x_gor -10, 17);
  387.     Tree(hdc, map_cx[2] + 266, x_gor +5, 10);
  388.  
  389. }
  390.  
  391. void Fild_4(HDC hdc) {
  392.     POINT pt2[3] = {
  393.         {map_cx[3] ,  x_gor },
  394.         {map_cx[3]  + 100, map_cy + 460},
  395.         {map_cx[3] + map_size_x, x_gor + 3}
  396.     };
  397.     SelectObject(hdc, hPen_map[1]);
  398.     SelectObject(hdc, hbrush_map[1]);
  399.     Polygon(hdc, pt2, 3);
  400.  
  401.     //передний план
  402.     POINT pt1[3] = {
  403.         {map_cx[3] ,  x_gor +20},
  404.         {map_cx[3] + map_size_x, map_cy + 433},
  405.         {map_cx[3] + map_size_x,  x_gor + 3}
  406.     };
  407.     SelectObject(hdc, hbrush_map[2]);
  408.     Polygon(hdc, pt1, 3);
  409.     SelectObject(hdc, hPen_map[2]);
  410.     Rectangle(hdc, map_cx[3], x_gor, map_cx[3] + map_size_x, map_size_y * 7 + x_gor);
  411.     SelectObject(hdc, hPen_map[1]);
  412.     MoveToEx(hdc, map_cx[3] + 86, x_gor - 3, NULL); // дорисовываем линии холмов
  413.     LineTo(hdc, map_cx[3], map_cy + 528);
  414.     Tree(hdc, map_cx[3] + 266, x_gor - 40 , 30);
  415.    
  416. }
  417.  
  418.  
  419.  
  420.  ////////// КОНЕЦ ФОНА
  421.  
  422.        
  423.             HBRUSH_SKY_1(hdc);
  424.             decorate_1_mountain(hdc);
  425.             Fild_1(hdc);
  426.  
  427.  
  428.             HBRUSH_SKY_2(hdc);
  429.             decorate_2_mountain(hdc);
  430.             Fild_2(hdc);
  431.  
  432.             HBRUSH_SKY_3(hdc);
  433.             decorate_3_mountain(hdc);
  434.             Fild_3(hdc);
  435.            
  436.             HBRUSH_SKY_4(hdc);
  437.             decorate_4_mountain(hdc);
  438.             Fild_4(hdc);
Add Comment
Please, Sign In to add comment