Advertisement
sebasvp2005

Untitled

Jun 5th, 2024
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include "enemigo.h"
  4. #include <conio.h>
  5. using namespace std;
  6. using namespace System;
  7.  
  8.  
  9. int width = 100, height = 27;
  10.  
  11. int pos[6][2];
  12. ConsoleColor co[6];
  13. int delta[6][2];
  14. int sizes[6];
  15. int n;
  16.  
  17. int tim = 1;
  18. ConsoleColor colors[] = { ConsoleColor::Red,ConsoleColor::Blue, ConsoleColor::Yellow, ConsoleColor::Green };
  19.  
  20. int x = 30;
  21.  
  22. void update() {
  23.     for (int i = 0; i < n; i++) {
  24.  
  25.        
  26.         if (pos[i][0] + delta[i][0] > width || pos[i][0] + delta[i][0] < 0) delta[i][0] *= -1;
  27.         if (pos[i][1] + delta[i][1] > height || pos[i][1] + delta[i][1] < 0) delta[i][1] *= -1;
  28.  
  29.         pos[i][0] += delta[i][0];
  30.         pos[i][1] += delta[i][1];
  31.         if (pos[i][1] == height - 2 && pos[i][0] <= x && x <= pos[i][0] + sizes[i] - 1) {
  32.  
  33.             if(delta[i][0] < 0) delta[i][0] = max(-5, delta[i][0]  -1 );
  34.             else delta[i][0] = min( 5, delta[i][0] + 1);
  35.  
  36.             if (delta[i][1] < 0) delta[i][1] = max(-5, delta[i][1] - 1);
  37.             else delta[i][1] = min(5, delta[i][1] + 1);
  38.  
  39.         }
  40.     }
  41.  
  42.  
  43. }
  44. void render() {
  45.     for (int i = 0; i < n; i++) {
  46.         for (int j = 0; j < sizes[i]; j++) {
  47.  
  48.             Console::SetCursorPosition(pos[i][0] + j, pos[i][1]);
  49.             Console::ForegroundColor = co[i];
  50.             cout << "*";
  51.         }
  52.     }
  53.  
  54.     Console::ForegroundColor = ConsoleColor::Yellow;
  55.     Console::SetCursorPosition(x, height - 2);
  56.     cout << char(219);
  57.  
  58. }
  59. void erase() {
  60.     for (int i = 0; i < n; i++) {
  61.         for (int j = 0; j < sizes[i]; j++) {
  62.             Console::SetCursorPosition(pos[i][0] + j, pos[i][1]);
  63.             cout << " ";
  64.         }
  65.     }
  66.  
  67. }
  68.  
  69.  
  70.  
  71. int main()
  72. {
  73.     srand(time(0));
  74.     Console::CursorVisible = false;
  75.  
  76.  
  77.  
  78.     n = rand() % 4 + 3;
  79.     for (int i = 0; i < n; i++) {
  80.         pos[i][0] = rand() % width;
  81.         pos[i][1] = rand() % height;
  82.         co[i] = colors[rand() % 4];
  83.         delta[i][0] = rand() % 3 + 1; // 1 2 3
  84.         delta[i][1] = rand() % 3 + 1;
  85.         sizes[i] = rand() % 3 + 2;
  86.     }
  87.  
  88.     Console::ForegroundColor = ConsoleColor::Yellow;
  89.     Console::SetCursorPosition(x, height - 2);
  90.     cout << char(219);
  91.  
  92.     while (1) {
  93.         erase();
  94.         update();
  95.  
  96.         if (_kbhit()) {
  97.             int a = _getch();
  98.             switch (a)
  99.             {
  100.             case 75:
  101.                 Console::SetCursorPosition(x, height-2);
  102.                 cout << " ";
  103.                 x = max(0, x - 1);
  104.  
  105.                 break;
  106.             case 77:
  107.                 Console::SetCursorPosition(x, height-2);
  108.                 cout << " ";
  109.                 x = min(width - 1, x + 1);
  110.  
  111.                 break;
  112.             }
  113.            
  114.         }
  115.         render();
  116.         tim++;
  117.         _sleep(100);
  118.     }
  119.  
  120.  
  121.  
  122.     return 0;
  123. }
  124.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement