Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : main project file.
- #include <iostream>"
- #include "conio.h"
- #include "iostream"
- #include <Windows.h>
- using namespace System;
- using namespace std;
- #define WIDTH 80
- #define HEIGHT 40
- #define DERECHA 77
- #define IZQUIERDA 75
- #define ARRIBA 72
- #define ABAJO 80
- void ubicacion(int x, int y) { Console::SetCursorPosition(x, y); }
- void jugador(int x, int y)
- {
- cout << " * "; y++; Console::SetCursorPosition(x, y);
- cout << "***"; y++; Console::SetCursorPosition(x, y);
- cout << " * "; y++;
- }
- void borrar(int x, int y)
- {
- cout << " " << endl; y++; Console::SetCursorPosition(x, y);
- cout << " " << endl; y++; Console::SetCursorPosition(x, y);
- cout << " ";
- }
- //PROGRAMA PRINCIPAL
- int main()
- {
- Console::SetWindowSize(WIDTH, HEIGHT);
- int x = WIDTH / 2, y = HEIGHT / 2;
- ubicacion(x, y); jugador(x,y);
- char tecla;
- while (1)
- {
- if (_kbhit())//detecta si se pulsa una tecla
- {
- tecla = _getch(); //identifica la tecla pulsada
- //BORRAR
- ubicacion(x, y); borrar(x,y);
- //CAMBIA POSICION
- if (x < 77)
- {
- if (tecla == DERECHA) x++;
- }
- if (x > 0)
- {
- if (tecla == IZQUIERDA) x--;
- }
- if (y>0)
- {
- if (tecla == ARRIBA) y--;
- }
- if (y < 38)
- {
- if (tecla == ABAJO) y++;
- }
- //DIBUJAR
- ubicacion(x, y); jugador(x,y);
- }
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement