Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include<ctype.h>
- #define ARRIBA 'W'
- #define ABAJO 'S'
- #define DERECHA 'D'
- #define IZQUIERDA 'A'
- using namespace std;
- using namespace System;
- struct personaje {
- short pasos;
- short x;
- short y;
- personaje(short a = 30, short b = 39, short c = 0) {
- x = a;
- y = b;
- pasos = c;
- }
- void mover(char direccion) {
- switch (direccion) {
- case ARRIBA: y--; pasos++; break;
- case ABAJO: y++; pasos++; break;
- case IZQUIERDA: x--; pasos++; break;
- case DERECHA: x++; pasos++; break;
- }
- }
- void dibujar() {
- Console::SetCursorPosition(x + 1, y);
- cout << " 8 ";
- Console::SetCursorPosition(x, y + 1);
- cout << " V[*]V ";
- Console::SetCursorPosition(x, y + 2);
- cout << "Vv[*]vV";
- }
- void borrar() {
- Console::SetCursorPosition(x + 1, y);
- cout << " ";
- Console::SetCursorPosition(x, y + 1);
- cout << " ";
- Console::SetCursorPosition(x, y + 2);
- cout << " ";
- }
- void animar(char direccion) {
- borrar();
- mover(direccion);
- restriccion();
- dibujar();
- }
- void restriccion() {
- if (x == -1) {
- x = 0;
- }
- else if (y == -1) {
- y = 0;
- }
- else if (x == 60) {
- x--;
- }
- else if (y == 40) {
- y--;
- }
- }
- };
- struct avispa {
- short pasos;
- short x;
- short y;
- short mx = 1;
- short my = 1;
- short t = 0;
- avispa(short a = 20, short b = 20, short c = 0) {
- x = a;
- y = b;
- pasos = c;
- }
- void mover() {
- if (x == 0 || x == 60) {
- mx *= -1;
- }
- else if (y == 0 || y == 20) {
- my *= -1;
- }
- x += mx;
- y += my;
- }
- void dibujar() {
- Console::SetCursorPosition(x, y);
- system("color 0C");
- cout << "(8/*/8)";
- }
- void borrar() {
- Console::SetCursorPosition(x, y);
- cout << " ";
- }
- void animar() {
- if (t == 1000) {
- borrar();
- mover();
- restriccion();
- dibujar();
- t = 0;
- }
- t++;
- }
- void restriccion() {
- if (x == -1) {
- x = 0;
- }
- else if (y == -1) {
- y = 0;
- }
- }
- };
- void juego() {
- Console::CursorVisible = false;
- Random r;
- personaje* p = new personaje[1];
- avispa* a = new avispa[4];
- for (int i = 0; i < 4; i++) {
- a[i].x = r.Next(0, 40);
- a[i].y = r.Next(0, 20);
- }
- bool gameover = true;
- while (gameover) {
- if (toupper(_kbhit())) {
- char direccion = _getch();
- p[0].animar(direccion);
- }
- for (int i = 0; i < 4; i++) {
- a[i].animar();
- }
- if (p[0].pasos == 30) {
- gameover = false;
- }
- }
- system("pause>0");
- delete p, a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement