Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- using namespace std;
- using namespace System;
- #define ARRIBA 72
- #define IZQUIERDA 75
- #define ABAJO 80
- #define DERECHA 77
- typedef struct personaje {
- short x;
- short y;
- char imagen;
- personaje(short _x = 10, short _y = 10, char _imagen = '*') {
- x = _x;
- y = _y;
- imagen = _imagen;
- }
- void animar(short direccion) {
- borrar();
- mover(direccion);
- dibujar();
- }
- void borrar() {
- Console::SetCursorPosition(x, y);
- cout << " ";
- }
- void mover(short direccion) {
- switch (direccion) {
- case ARRIBA : y--; break;
- case ABAJO : y++; break;
- case IZQUIERDA: x--; break;
- case DERECHA : x++; break;
- }
- }
- void dibujar() {
- Console::SetCursorPosition(x, y);
- cout << imagen;
- }
- };
- typedef struct enemigo {
- short x;
- short y;
- short dx;
- char imagen;
- enemigo(short _x = 10, short _y = 10, char _imagen = '*') {
- x = _x;
- y = _y;
- dx = 1;
- imagen = _imagen;
- }
- void animar() {
- borrar();
- mover();
- dibujar();
- }
- void borrar() {
- Console::SetCursorPosition(x, y);
- cout << " ";
- }
- void mover() {
- if (x == 0 || x == 40) {
- dx *= -1;
- y++;
- }
- x += dx;
- }
- void dibujar() {
- Console::SetCursorPosition(x, y);
- cout << imagen;
- }
- };
- void jugar() {
- personaje p1;
- short n;
- cout << "Ingrese la cantidad de enemigos: ";
- cin >> n;
- enemigo* enemigos = new enemigo[n];
- for (short i = 0; i < n; i++) {
- short x = Random::Random().Next(0, 40);
- short y = Random::Random().Next(0, 5);
- enemigos[i].x = x;
- enemigos[i].y = y;
- _sleep(250);
- }
- while (true) {
- if (kbhit()) {
- short direccion = getch();
- p1.animar(direccion);
- }
- for (short i = 0; i < n; i++)
- enemigos[i].animar();
- _sleep(250);
- }
- }
- int main() {
- Console::CursorVisible = false;
- jugar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement