Add code configuraction in configure

pull/1/head
Nakidai 2023-10-30 03:09:32 +03:00
parent b23325bfec
commit 317622a253
Signed by untrusted user who does not match committer: nakidai
GPG Key ID: 914675D395210A97
2 changed files with 17 additions and 4 deletions

12
configure vendored
View File

@ -6,15 +6,27 @@ CFLAGS=${CFLAGS:-}
LDFLAGS=${LDFLAGS:-} LDFLAGS=${LDFLAGS:-}
OUT=${OUT:-game} OUT=${OUT:-game}
SIZE=${SIZE:-10} SIZE=${SIZE:-10}
DEFX=${DEFX:-0}
DEFY=${DEFY:-0}
echo "Makefile configuration:"
echo "Compiler: $CC" echo "Compiler: $CC"
echo "Remove: $RM" echo "Remove: $RM"
echo "CFLAGS: $CFLAGS" echo "CFLAGS: $CFLAGS"
echo "LDFLAGS: $LDFLAGS" echo "LDFLAGS: $LDFLAGS"
echo "Out file: $OUT" echo "Out file: $OUT"
echo
echo "Code configuration:"
echo "Size: $SIZE"
echo "Start x: $DEFX"
echo "Start y: $DEFY"
echo "CC = $CC echo "CC = $CC
RM = $RM RM = $RM
CFLAGS = $CFLAGS CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS LDFLAGS = $LDFLAGS
OUT = $OUT" > config/config.mk OUT = $OUT" > config/config.mk
echo "#define SIZE $SIZE
#define DEFX $DEFX
#define DEFY $DEFY" > config/config.h

View File

@ -8,6 +8,7 @@
#include "screen.h" #include "screen.h"
#include "player.h" #include "player.h"
#include "food.h" #include "food.h"
#include "config.h"
void drawPlayer(Player *player, Screen *screen) void drawPlayer(Player *player, Screen *screen)
{ {
@ -21,7 +22,7 @@ Food generateFood(Player *player)
Food food; Food food;
do do
{ {
food = (Food){random() % 10, random() % 10}; food = (Food){random() % SIZE, random() % SIZE};
} while (playerCheckFoodCollision(player, food)); } while (playerCheckFoodCollision(player, food));
return food; return food;
} }
@ -34,8 +35,8 @@ void resetCoordinates(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
srandom(time(NULL)); srandom(time(NULL));
Player *player = playerCreate(DOWN, 0, 0, 0); Player *player = playerCreate(DOWN, DEFX, DEFY, 0);
Screen *screen = screenCreate(10, 10, ' '); Screen *screen = screenCreate(SIZE, SIZE, ' ');
PlayerNode *node; PlayerNode *node;
thrd_t input_thread; thrd_t input_thread;
int i; int i;
@ -72,7 +73,7 @@ int main(int argc, char **argv)
} }
head_x = player->head->x; head_x = player->head->x;
head_y = player->head->y; 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; *running = false;
break; break;