Compare commits
No commits in common. "21e1f14990a3fd89de61ba8e797c3675b4a23446" and "d6b4f0be328fd5b10ef5c5d910d21cc51f6def50" have entirely different histories.
21e1f14990
...
d6b4f0be32
7
Makefile
7
Makefile
|
@ -1,6 +1,9 @@
|
|||
include config.mk
|
||||
|
||||
OUT = game
|
||||
CFLAGS =
|
||||
LDFLAGS =
|
||||
INCLUDE = -Iinclude
|
||||
CC = cc
|
||||
LD = ld
|
||||
RM = rm -f
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [[ "$*" == *"--help"* ]] || [[ "$*" == *"-h"* ]]
|
||||
then
|
||||
echo "Use environment variables to pass values:
|
||||
CC - compiler (default: cc)
|
||||
CFLAGS - flags for compiler
|
||||
LDFLAGS - flags for linker
|
||||
OUT - out file (default: game
|
||||
SIZE - size of game field
|
||||
DEFX - start x
|
||||
DEFY - start y"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CC=${CC:-cc}
|
||||
CFLAGS=${CFLAGS:-}
|
||||
LDFLAGS=${LDFLAGS:-}
|
||||
OUT=${OUT:-game}
|
||||
SIZE=${SIZE:-10}
|
||||
DEFX=${DEFX:-0}
|
||||
DEFY=${DEFY:-0}
|
||||
|
||||
echo "Makefile configuration:"
|
||||
echo "Compiler: $CC"
|
||||
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
|
||||
CFLAGS = $CFLAGS
|
||||
LDFLAGS = $LDFLAGS
|
||||
OUT = $OUT" > config.mk
|
||||
|
||||
echo "#define SIZE $SIZE
|
||||
#define DEFX $DEFX
|
||||
#define DEFY $DEFY" > include/config.h
|
|
@ -1,3 +0,0 @@
|
|||
#define SIZE 10
|
||||
#define DEFX 0
|
||||
#define DEFY 0
|
11
src/main.c
11
src/main.c
|
@ -8,7 +8,6 @@
|
|||
#include "screen.h"
|
||||
#include "player.h"
|
||||
#include "food.h"
|
||||
#include "config.h"
|
||||
|
||||
void drawPlayer(Player *player, Screen *screen)
|
||||
{
|
||||
|
@ -22,7 +21,7 @@ Food generateFood(Player *player)
|
|||
Food food;
|
||||
do
|
||||
{
|
||||
food = (Food){random() % SIZE, random() % SIZE};
|
||||
food = (Food){random() % 10, random() % 10};
|
||||
} while (playerCheckFoodCollision(player, food));
|
||||
return food;
|
||||
}
|
||||
|
@ -35,8 +34,8 @@ void resetCoordinates(void)
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
srandom(time(NULL));
|
||||
Player *player = playerCreate(DOWN, DEFX, DEFY, 0);
|
||||
Screen *screen = screenCreate(SIZE, SIZE, ' ');
|
||||
Player *player = playerCreate(DOWN, 0, 0, 0);
|
||||
Screen *screen = screenCreate(10, 10, ' ');
|
||||
PlayerNode *node;
|
||||
thrd_t input_thread;
|
||||
int i;
|
||||
|
@ -73,7 +72,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
head_x = player->head->x;
|
||||
head_y = player->head->y;
|
||||
if (head_x >= SIZE || head_x < 0 || head_y >= SIZE || head_y < 0)
|
||||
if (head_x >= 10 || head_x < 0 || head_y >= 10 || head_y < 0)
|
||||
{
|
||||
*running = false;
|
||||
break;
|
||||
|
@ -84,7 +83,7 @@ int main(int argc, char **argv)
|
|||
*screenGetPoint(screen, food.x, food.y) = '@';
|
||||
resetCoordinates();
|
||||
screenShow(screen);
|
||||
for (i = 0; i < SIZE*2; ++i) putchar('-');
|
||||
for (i = 0; i < 20; ++i) putchar('-');
|
||||
printf("\nScore: %d\n", player->score);
|
||||
|
||||
thrd_sleep(&(struct timespec){.tv_sec=1}, NULL);
|
||||
|
|
Loading…
Reference in New Issue