From 317622a2531d1249cebed7b2ee46d26cea4394fd Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 03:09:32 +0300 Subject: [PATCH] Add code configuraction in configure --- configure | 12 ++++++++++++ src/main.c | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 3b726f4..83ad3df 100755 --- a/configure +++ b/configure @@ -6,15 +6,27 @@ CFLAGS=${CFLAGS:-} LDFLAGS=${LDFLAGS:-} OUT=${OUT:-game} SIZE=${SIZE:-10} +DEFX=${DEFX:-0} +DEFY=${DEFY:-0} +echo "Makefile configuration:" echo "Compiler: $CC" echo "Remove: $RM" echo "CFLAGS: $CFLAGS" echo "LDFLAGS: $LDFLAGS" echo "Out file: $OUT" +echo +echo "Code configuration:" +echo "Size: $SIZE" +echo "Start x: $DEFX" +echo "Start y: $DEFY" echo "CC = $CC RM = $RM CFLAGS = $CFLAGS LDFLAGS = $LDFLAGS OUT = $OUT" > config/config.mk + +echo "#define SIZE $SIZE +#define DEFX $DEFX +#define DEFY $DEFY" > config/config.h diff --git a/src/main.c b/src/main.c index 570ad51..eb17550 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,7 @@ #include "screen.h" #include "player.h" #include "food.h" +#include "config.h" void drawPlayer(Player *player, Screen *screen) { @@ -21,7 +22,7 @@ Food generateFood(Player *player) Food food; do { - food = (Food){random() % 10, random() % 10}; + food = (Food){random() % SIZE, random() % SIZE}; } while (playerCheckFoodCollision(player, food)); return food; } @@ -34,8 +35,8 @@ void resetCoordinates(void) int main(int argc, char **argv) { srandom(time(NULL)); - Player *player = playerCreate(DOWN, 0, 0, 0); - Screen *screen = screenCreate(10, 10, ' '); + Player *player = playerCreate(DOWN, DEFX, DEFY, 0); + Screen *screen = screenCreate(SIZE, SIZE, ' '); PlayerNode *node; thrd_t input_thread; int i; @@ -72,7 +73,7 @@ int main(int argc, char **argv) } head_x = player->head->x; head_y = player->head->y; - if (head_x >= 10 || head_x < 0 || head_y >= 10 || head_y < 0) + if (head_x >= SIZE || head_x < 0 || head_y >= SIZE || head_y < 0) { *running = false; break;