diff --git a/main.c b/main.c index 9e5b714..e78a444 100644 --- a/main.c +++ b/main.c @@ -16,13 +16,18 @@ int main() fscanf(level, "%i %i", &x, &y); fscanf(level, "%i %i", &x_player, &y_player); fscanf(level, "%u", &camfov); + + // Normalize + y_player = y - y_player; + x_player = x_player - 1; + if(x <= 0 || y <= 0) { fclose(level); printf("\nInvalid world dimensions."); return 0; } - if(x_player > x || (y - y_player) > y || x_player <= 0 || (y - y_player) <= 0) + if(x_player > x || y_player > y || x_player < 0 || y_player < 0) { fclose(level); printf("\nOut of bounds position."); diff --git a/makefile b/makefile index 7c26c92..4119760 100644 --- a/makefile +++ b/makefile @@ -1,2 +1,16 @@ game: main.c render.c - gcc -o game -g main.c render.c \ No newline at end of file + gcc -o game -O2 main.c render.c +gameDEBUG: main.c render.c + gcc -o gameDEBUG -g main.c render.c + +gameX64: main.c render.c + gcc -m64 -o gameX64 -O2 main.c render.c +gameX64DEBUG: main.c render.c + gcc -m64 -o gameX64DEBUG -g main.c render.c + +gameX32: main.c render.c + gcc -m32 -o gameX32 -O2 main.c render.c +gameX32DEBUG: main.c render.c + gcc -m32 -o gameX32DEBUG -g main.c render.c + +all: gameX64 gameX64DEBUG game gameDEBUG diff --git a/render.c b/render.c index 35387d6..1786874 100644 --- a/render.c +++ b/render.c @@ -14,6 +14,8 @@ #define CYAN "\x1b[46m" #define RESET "\x1b[0m" +char *color[] = { BLACK, WHITE, RED, GREEN, YELLOW, BROWN, PINK }; + /* . - green color , - yellow color @@ -25,13 +27,16 @@ Maybe will make output as colored dots only // Maybe give an input value +// General variables extern int x, y; extern int x_player, y_player; extern unsigned int camfov; -void print(int up, int down, int left, int right, char a[y][x]) +int up, down, left, right; + +void print(char a[y][x]) { - int i, j; + int i, j, colori; for(j = up; j <= down; j++) { @@ -41,22 +46,25 @@ void print(int up, int down, int left, int right, char a[y][x]) switch (a[j][i]) { case '.': - printf(GREEN " " RESET); + colori = 3; break; case ',': - printf(YELLOW " " RESET); + colori = 4; break; case '#': - printf(BROWN " " RESET); + colori = 5; break; case '@': - printf(PINK " " RESET); + colori = 6; break; default: - printf(BLACK " " RESET); + colori = 0; break; } + + printf(color[colori]); + printf(" " RESET); } printf("\n"); } @@ -66,69 +74,66 @@ void print(int up, int down, int left, int right, char a[y][x]) void camera(char a[y][x]) { - // If world is smaller than camera fov - if(x <= camfov - 1 || y <= camfov - 1) - { - // + 1 in order to set correct matrix size - print(0, y - 1, 0, x - 1, a); - return; - } - // Math coordonates to array index - x_player--; - // ypos--; - - int up_bound, down_bound; - int left_bound, right_bound; - - /* - If camera FOV is positive (10x10 screen) - then place coordonates in top-left pixel. - - In the future, if the player will be able - to move, move camera if they leave the - middle 2x2 zone (center). - */ - + // x_player--; + // y_player--; // Y bounds - up_bound = y_player - (camfov/2); - down_bound = y_player + (camfov/2); + up = y_player - (camfov/2); + down = y_player + (camfov/2); // X bounds - left_bound = x_player - (camfov/2); - right_bound = x_player + (camfov/2); + left = x_player - (camfov/2); + right = x_player + (camfov/2); - if(camfov % 2 == 0) + // Up and Down camera bounds + if(up < 0) { - up_bound++; - left_bound++; + down = camfov; + up = 0; } - - // Back to bounds math: Negative shift - if(up_bound < 0) + else if(down >= y) { - down_bound = camfov - 1; - up_bound = 0; + up = y - camfov; + down = y; } - if(left_bound < 0) + // Left and Right camera bounds + if(left < 0) { - right_bound = camfov - 1; - left_bound = 0; + right = camfov; + left = 0; + } + else if(right >= x) + { + left = x - camfov; + right = x; } - // Positive shift - if(down_bound >= y) + // If camera FOV is bigger than world + if(x <= camfov || y <= camfov) { - up_bound = y - camfov + 1; - down_bound = y; + right = x - 1; + down = y - 1; + print(a); + return; } - if(right_bound >= x) + + /* + If camera FOV is positive (10x10 screen) + then place coordonates in top-left pixel. + + In the future, if the player will be able + to move, move camera if they leave the + middle 2x2 zone (center). + */ + if(camfov % 2 == 0) { - left_bound = x - camfov; - right_bound = x; + up++; + left++; } - print(up_bound, down_bound, left_bound, right_bound, a); + + + print(a); return; } \ No newline at end of file