Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include "enemigo.h"
- #include <conio.h>
- using namespace std;
- using namespace System;
- int width = 100, height = 27;
- int pos[6][2];
- ConsoleColor co[6];
- int delta[6][2];
- int sizes[6];
- int n;
- int tim = 1;
- ConsoleColor colors[] = { ConsoleColor::Red,ConsoleColor::Blue, ConsoleColor::Yellow, ConsoleColor::Green };
- int x = 30;
- void update() {
- for (int i = 0; i < n; i++) {
- if (pos[i][0] + delta[i][0] > width || pos[i][0] + delta[i][0] < 0) delta[i][0] *= -1;
- if (pos[i][1] + delta[i][1] > height || pos[i][1] + delta[i][1] < 0) delta[i][1] *= -1;
- pos[i][0] += delta[i][0];
- pos[i][1] += delta[i][1];
- if (pos[i][1] == height - 2 && pos[i][0] <= x && x <= pos[i][0] + sizes[i] - 1) {
- if(delta[i][0] < 0) delta[i][0] = max(-5, delta[i][0] -1 );
- else delta[i][0] = min( 5, delta[i][0] + 1);
- if (delta[i][1] < 0) delta[i][1] = max(-5, delta[i][1] - 1);
- else delta[i][1] = min(5, delta[i][1] + 1);
- }
- }
- }
- void render() {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < sizes[i]; j++) {
- Console::SetCursorPosition(pos[i][0] + j, pos[i][1]);
- Console::ForegroundColor = co[i];
- cout << "*";
- }
- }
- Console::ForegroundColor = ConsoleColor::Yellow;
- Console::SetCursorPosition(x, height - 2);
- cout << char(219);
- }
- void erase() {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < sizes[i]; j++) {
- Console::SetCursorPosition(pos[i][0] + j, pos[i][1]);
- cout << " ";
- }
- }
- }
- int main()
- {
- srand(time(0));
- Console::CursorVisible = false;
- n = rand() % 4 + 3;
- for (int i = 0; i < n; i++) {
- pos[i][0] = rand() % width;
- pos[i][1] = rand() % height;
- co[i] = colors[rand() % 4];
- delta[i][0] = rand() % 3 + 1; // 1 2 3
- delta[i][1] = rand() % 3 + 1;
- sizes[i] = rand() % 3 + 2;
- }
- Console::ForegroundColor = ConsoleColor::Yellow;
- Console::SetCursorPosition(x, height - 2);
- cout << char(219);
- while (1) {
- erase();
- update();
- if (_kbhit()) {
- int a = _getch();
- switch (a)
- {
- case 75:
- Console::SetCursorPosition(x, height-2);
- cout << " ";
- x = max(0, x - 1);
- break;
- case 77:
- Console::SetCursorPosition(x, height-2);
- cout << " ";
- x = min(width - 1, x + 1);
- break;
- }
- }
- render();
- tim++;
- _sleep(100);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement