From 3acb74d372418a47781eb16567781042d2b089a4 Mon Sep 17 00:00:00 2001 From: LBindustries Date: Mon, 28 Dec 2015 17:10:11 +0100 Subject: [PATCH] Aggiunto giocatore e movimento del giocatore. --- main.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index e96149a..7e137e2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #define X_MAX 80 #define Y_MAX 23 @@ -9,11 +10,65 @@ #define WALL 0xB2 #define EMPTY 0xFF +#define PLAYER 0x02 using namespace std; +void move(unsigned char map[X_MAX][Y_MAX], int player[2]) +{ + int player_x = player[0]; + int player_y = player[1]; + bool waiting = true; + while(waiting) + { + if(getch() == 224) + { + switch(getch()) + { + case 72: //Freccia su + if(map[player_x][player_y-1] == EMPTY) + { + map[player_x][player_y] = EMPTY; + map[player_x][player_y-1] = PLAYER; + player_y--; + waiting = false; + } + break; + case 80: //Freccia giù + if(map[player_x][player_y+1] == EMPTY) + { + map[player_x][player_y] = EMPTY; + map[player_x][player_y+1] = PLAYER; + player_y++; + waiting = false; + } + break; + case 75: //Freccia sinistra + if(map[player_x-1][player_y] == EMPTY) + { + map[player_x][player_y] = EMPTY; + map[player_x-1][player_y] = PLAYER; + player_x--; + waiting = false; + } + break; + case 77: //Freccia destra + if(map[player_x+1][player_y] == EMPTY) + { + map[player_x][player_y] = EMPTY; + map[player_x+1][player_y] = PLAYER; + player_x++; + waiting = false; + } + break; + } + } + } + player[0] = player_x; + player[1] = player_y; +} //Aggiorna la console con la situazione corrente del gioco. -void draw(char map[X_MAX][Y_MAX]) +void draw(unsigned char map[X_MAX][Y_MAX]) { for(int y=0; y