Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<Windows.h>
- #include<conio.h>
- #include<time.h>
- #include<time.h>
- //C:\Program Files(x86)\Windows Kits\10\References
- using namespace std;
- enum terreno{camino,pared};
- #define COLUMNAS 20
- #define FILAS 20
- int matriz[FILAS][COLUMNAS] = {
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1},
- {1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- };
- class mapa {//////////////////////////////
- public:
- void dibujo() {
- for (int i = 0; i < FILAS; i++) {
- for (int j = 0; j < COLUMNAS; j++) {
- if (matriz[i][j] == 1) {
- cout << char(219);
- }
- if (matriz[i][j] == 0) {
- cout << " ";
- }
- }
- cout << endl;
- }
- }
- };
- #define up 72
- #define down 80
- #define right 77
- #define left 75
- void gotoxy(int x, int y) {
- HANDLE hCon;
- hCon = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD dwPos;
- dwPos.Y = y;
- dwPos.X = x;
- SetConsoleCursorPosition(hCon, dwPos);
- }
- class juego {
- // ejes de bala
- int upp=0, aux = 1;
- int xx=7, yy=8;
- int x = 6, y = 6;
- int bx, by;
- public:
- mapa* map;
- void mover(char tecla);
- void borrar();
- void mover_enemigo();
- void colision();
- void balas();
- };
- void juego::balas() {
- char tecla;
- if (_kbhit())
- {
- tecla = _getch();
- if (tecla == up) {
- bx = x; by = y;
- upp = 0;
- }
- }
- if (upp < 15-by) {
- if (matriz[by-aux ][bx] == camino) {
- cout << "@";
- gotoxy(bx - aux, by );
- cout << ".";
- upp++;
- aux++;
- }
- }
- }
- void juego::colision() {
- if (xx == x && yy == y) {
- gotoxy(5, 5);
- cout << "COLISION-COLISION-COLISION-COLISION-COLISION-COLISION-COLISION";
- cout << "COLISION-COLISION-COLISION-COLISION-COLISION-COLISION-COLISION";
- system("pause>0");
- system("cls");
- map->dibujo();
- }
- }
- void juego::mover_enemigo() {
- short a;
- a = rand() % 5;
- if (a == 0) {
- if (matriz[yy][xx + 2] == camino) {
- gotoxy(xx, yy);
- cout << " ";
- xx += 2;
- gotoxy(xx, yy);
- cout << char(999);
- }
- }
- if (a == 1) {
- if (matriz[yy][xx - 2] == camino) {
- gotoxy(xx, yy);
- cout << " ";
- xx -= 2;
- gotoxy(xx, yy);
- cout << char(999);
- }
- }
- if (a == 2) {
- if (matriz[yy + 2][xx] == camino) {
- gotoxy(xx, yy);
- cout << " ";
- yy += 2;
- gotoxy(xx, yy);
- cout << char(999);
- }
- }
- if (a == 3) {
- if (matriz[yy - 2][xx] == camino) {
- gotoxy(xx, yy);
- cout << " ";
- yy -= 2;
- gotoxy(xx, yy);
- cout << char(999);
- }
- }
- }
- void juego::borrar() {
- gotoxy(x, y);
- cout << " ";
- }
- void juego::mover(char tecla) {
- if (tecla == 'w') {
- borrar();
- if (matriz[y - 1][x] == camino) {
- y--;
- gotoxy(x, y);
- cout << "@";
- }else {
- gotoxy(x, y);
- cout << "@";
- }
- }
- else if (tecla == 's') {
- borrar();
- if (matriz[y + 1][x] == camino) {
- y++;
- gotoxy(x, y);
- cout << "@";
- }else {
- gotoxy(x, y);
- cout << "@";
- }
- }
- else if (tecla == 'a') {
- borrar();
- if (matriz[y][x-1] == camino) {
- x--;
- gotoxy(x, y);
- cout << "@";
- }
- else {
- gotoxy(x, y);
- cout << "@";
- }
- }
- else if (tecla == 'd') {
- borrar();
- if (matriz[y][x+1] == camino) {
- x++;
- gotoxy(x, y);
- cout << "@";
- }
- else {
- gotoxy(x, y);
- cout << "@";
- }
- }
- else {
- }
- }
- int main() {
- srand(time(NULL));
- juego _juego;
- char tecla;
- mapa map;
- map.dibujo();
- while (1) {
- if (_kbhit())
- {
- tecla = _getch();
- _juego.mover(tecla);
- }
- _juego.balas();
- //_juego.mover_enemigo();
- //_juego.colision();
- Sleep(100);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement