Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- using namespace System;
- struct obj {
- int x, y;
- int dx, dy;
- };
- int matr[20][20] = { {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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
- { 1,0,0,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,1,1,1,1,1,1,1,1,1,1,1,1 } };
- void gotoxy(int x, int y ) {
- Console::SetCursorPosition(x, y);
- }
- void dibujarObj(obj Persona) {
- Console::BackgroundColor = ConsoleColor::Green;
- gotoxy(Persona.x+1, Persona.y);
- cout << " ";
- gotoxy(Persona.x, Persona.y + 1);
- cout << " ";
- }
- void borrarObj(obj Persona) {
- if (matr[Persona.y][Persona.x] == 1) {
- Console::BackgroundColor = ConsoleColor::Red;
- }
- else {
- Console::BackgroundColor = ConsoleColor::White;
- }
- gotoxy(Persona.x, Persona.y);
- cout << " ";
- gotoxy(Persona.x, Persona.y + 1);
- cout << " ";
- }
- void desplazar_fichar(obj Persona) {
- for (int i = 0; ; i++) {
- if (i % 10000000 == 0) {
- if (Persona.dx > 0 && matr[Persona.y][Persona.x + Persona.dx + 2 ] == 1) {
- Persona.dx *= -1;
- }
- else if (Persona.dx < 0 && matr[Persona.y][Persona.x + Persona.dx] == 1) {
- Persona.dx *= -1;
- }
- borrarObj(Persona);
- Persona.x += Persona.dx;
- dibujarObj(Persona);
- }
- }
- }
- int main() {
- obj Personaje;
- Personaje.x = 1;
- Personaje.y = 1;
- Personaje.dx = 1;
- for (int i = 0; i < 20; i++) {
- for (int j = 0; j < 20; j++) {
- if (matr[i][j] == 1) {
- Console::BackgroundColor = ConsoleColor::Red;
- }
- else {
- Console::BackgroundColor = ConsoleColor::White;
- }
- cout << " ";
- }
- cout << endl;
- }
- desplazar_fichar(Personaje);
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement