Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctype.h>
- #include <conio.h>
- #include <time.h>
- using namespace std;
- using namespace System;
- #define ARRIBA 72
- #define ABAJO 80
- #define IZQUIERDA 75
- #define DERECHA 77
- typedef struct personaje {
- int x=40;
- int y=80;
- int pasos=0;
- void animar(char direccion) {
- borrar();
- mover(direccion);
- dibujar();
- };
- void borrar() {
- Console::SetCursorPosition(x, y);
- cout << " ";
- };
- 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, y);
- cout << " | ";
- };
- };
- void jugar() {
- personaje p;
- bool continuar = true;
- while (continuar) {
- if (kbhit()) {
- char direccion = getch();
- p.animar(direccion);
- }
- if (p.x==80) {
- p.x--;
- }
- if (p.x == 2) {
- p.x++;
- }
- }
- }
- int main() {
- Console::CursorVisible=false;
- jugar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement