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 x, y;
- bool finish = true;
- int siz = 2;
- int width = 100, height = 27;
- ConsoleColor colors[] = { ConsoleColor::Red,ConsoleColor::Blue, ConsoleColor::Yellow, ConsoleColor::Green };
- void update() {
- if (y == height)finish = true;
- if (finish) {
- x = rand() % width;
- y = rand() % height;
- finish = false;
- Console::ForegroundColor = colors[rand()%4];
- }
- y++;
- }
- void render() {
- for (int i = 0; i < siz; i++) {
- Console::SetCursorPosition(x, y + i);
- cout << "*";
- }
- }
- void erase() {
- for (int i = 0; i < siz; i++) {
- Console::SetCursorPosition(x, y + i);
- cout << " ";
- }
- }
- int main()
- {
- srand(time(0));
- Console::CursorVisible = false;
- while (1) {
- erase();
- update();
- if (_kbhit()) {
- int a = _getch();
- switch (a)
- {
- case 75:
- x = max(0, x - 1);
- break;
- case 77:
- x = min(width - 1, x + 1);
- break;
- }
- }
- render();
- _sleep(100);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement