Compare commits
8 Commits
e9e503d5b2
...
f89b46a60d
Author | SHA1 | Date |
---|---|---|
Nakidai | f89b46a60d | |
Nakidai | 42bddb2ee4 | |
Nakidai | b51afc628f | |
Nakidai | d241321aff | |
Nakidai | 40dc962d5e | |
Nakidai | ad64867b40 | |
Nakidai | 35669794a7 | |
Nakidai | d6eef4c404 |
|
@ -1,2 +1,3 @@
|
||||||
obj/
|
obj/
|
||||||
game
|
game
|
||||||
|
config/
|
||||||
|
|
4
Makefile
4
Makefile
|
@ -1,7 +1,9 @@
|
||||||
|
include config/config.mk
|
||||||
|
|
||||||
OUT = game
|
OUT = game
|
||||||
CFLAGS =
|
CFLAGS =
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
INCLUDE = -Iinclude
|
INCLUDE = -Iinclude -Iconfig
|
||||||
CC = cc
|
CC = cc
|
||||||
LD = ld
|
LD = ld
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#!/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}
|
||||||
|
RM=${RM:-rm -f}
|
||||||
|
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"
|
||||||
|
|
||||||
|
if ! test -d config; then
|
||||||
|
if test -f config; then
|
||||||
|
rm config
|
||||||
|
fi
|
||||||
|
mkdir config
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
|
@ -9,6 +9,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)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +23,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;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +31,8 @@ Food generateFood(Player *player)
|
||||||
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;
|
||||||
pthread_t input_thread;
|
pthread_t input_thread;
|
||||||
int head_x, head_y;
|
int head_x, head_y;
|
||||||
|
@ -68,7 +69,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;
|
||||||
|
|
Loading…
Reference in New Issue