Advertisement
sebasvp2005

Untitled

Jun 5th, 2024
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 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 x, y;
  10. bool finish = true;
  11. int siz = 2;
  12. int width = 100, height = 27;
  13.  
  14.  
  15. ConsoleColor colors[] = { ConsoleColor::Red,ConsoleColor::Blue, ConsoleColor::Yellow, ConsoleColor::Green };
  16.  
  17. void update() {
  18.     if (y == height)finish = true;
  19.  
  20.     if (finish) {
  21.         x = rand() % width;
  22.         y = rand() % height;
  23.         finish = false;
  24.         Console::ForegroundColor = colors[rand()%4];
  25.     }
  26.     y++;
  27.  
  28. }
  29. void render() {
  30.     for (int i = 0; i < siz; i++) {
  31.         Console::SetCursorPosition(x, y + i);
  32.         cout << "*";
  33.     }
  34.  
  35. }
  36. void erase() {
  37.     for (int i = 0; i < siz; i++) {
  38.         Console::SetCursorPosition(x, y + i);
  39.         cout << " ";
  40.     }
  41. }
  42.  
  43.  
  44.  
  45. int main()
  46. {
  47.     srand(time(0));
  48.     Console::CursorVisible = false;
  49.  
  50.     while (1) {
  51.         erase();
  52.         update();
  53.         if (_kbhit()) {
  54.             int a = _getch();
  55.             switch (a)
  56.             {
  57.             case 75:
  58.                 x = max(0, x - 1);
  59.                 break;
  60.             case 77:
  61.                 x = min(width - 1, x + 1);
  62.                 break;
  63.             }
  64.            
  65.         }
  66.         render();
  67.        
  68.         _sleep(100);
  69.     }
  70.  
  71.  
  72.  
  73.     return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement