Compare commits
No commits in common. "ba0fc142d448c4278623a4a26023b5ef394d8e72" and "d995de91164831ad8f99ef96669aa17f90c77f02" have entirely different histories.
ba0fc142d4
...
d995de9116
|
@ -27,7 +27,7 @@ endif()
|
||||||
|
|
||||||
target_include_directories(csnake PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
target_include_directories(csnake PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
set(FIELD_SIZE 10 CACHE STRING "Size of game field")
|
set(SIZE 10 CACHE STRING "Size of game field")
|
||||||
set(DEFX 0 CACHE STRING "Start x")
|
set(DEFX 0 CACHE STRING "Start x")
|
||||||
set(DEFY 0 CACHE STRING "Start y")
|
set(DEFY 0 CACHE STRING "Start y")
|
||||||
set(SLEEP 1000 CACHE STRING "Sleep between frames (ms)")
|
set(SLEEP 1000 CACHE STRING "Sleep between frames (ms)")
|
||||||
|
|
|
@ -7,7 +7,7 @@ usage()
|
||||||
CFLAGS - flags for compiler
|
CFLAGS - flags for compiler
|
||||||
LDFLAGS - flags for linker
|
LDFLAGS - flags for linker
|
||||||
OUT - out file (default: csnake
|
OUT - out file (default: csnake
|
||||||
FIELD_SIZE - size of game field
|
SIZE - size of game field
|
||||||
DEFX - start x
|
DEFX - start x
|
||||||
DEFY - start y
|
DEFY - start y
|
||||||
SLEEP - sleep between frames (ms)"
|
SLEEP - sleep between frames (ms)"
|
||||||
|
@ -28,7 +28,7 @@ CC=${CC:-cc}
|
||||||
CFLAGS=${CFLAGS:-}
|
CFLAGS=${CFLAGS:-}
|
||||||
LDFLAGS=${LDFLAGS:-}
|
LDFLAGS=${LDFLAGS:-}
|
||||||
OUT=${OUT:-csnake}
|
OUT=${OUT:-csnake}
|
||||||
FIELD_SIZE=${FIELD_SIZE:-10}
|
SIZE=${SIZE:-10}
|
||||||
DEFX=${DEFX:-0}
|
DEFX=${DEFX:-0}
|
||||||
DEFY=${DEFY:-0}
|
DEFY=${DEFY:-0}
|
||||||
SLEEP=${SLEEP:-1000}
|
SLEEP=${SLEEP:-1000}
|
||||||
|
@ -40,7 +40,7 @@ echo "LDFLAGS: $LDFLAGS"
|
||||||
echo "Out file: $OUT"
|
echo "Out file: $OUT"
|
||||||
echo
|
echo
|
||||||
echo "Code configuration:"
|
echo "Code configuration:"
|
||||||
echo "Field size: $FIELD_SIZE"
|
echo "Size: $SIZE"
|
||||||
echo "Start x: $DEFX"
|
echo "Start x: $DEFX"
|
||||||
echo "Start y: $DEFY"
|
echo "Start y: $DEFY"
|
||||||
echo "Sleep: $SLEEP"
|
echo "Sleep: $SLEEP"
|
||||||
|
@ -50,7 +50,7 @@ CFLAGS = $CFLAGS
|
||||||
LDFLAGS = $LDFLAGS
|
LDFLAGS = $LDFLAGS
|
||||||
OUT = $OUT" > config.mk
|
OUT = $OUT" > config.mk
|
||||||
|
|
||||||
echo "#define FIELD_SIZE $FIELD_SIZE
|
echo "#define SIZE $SIZE
|
||||||
#define DEFX $DEFX
|
#define DEFX $DEFX
|
||||||
#define DEFY $DEFY
|
#define DEFY $DEFY
|
||||||
#define SLEEP $SLEEP" > include/config.h
|
#define SLEEP $SLEEP" > include/config.h
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#define FIELD_SIZE ${FIELD_SIZE}
|
#define SIZE ${SIZE}
|
||||||
#define DEFX ${DEFX}
|
#define DEFX ${DEFX}
|
||||||
#define DEFY ${DEFY}
|
#define DEFY ${DEFY}
|
||||||
#define SLEEP ${SLEEP}
|
#define SLEEP ${SLEEP}
|
||||||
|
|
|
@ -2,13 +2,7 @@
|
||||||
#define __PLATFORM_SCREEN_H__
|
#define __PLATFORM_SCREEN_H__
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif /* __MINGW32__ */
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
10
src/main.c
10
src/main.c
|
@ -25,7 +25,7 @@ Food generateFood(Player player)
|
||||||
Food food;
|
Food food;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
food = (Food){rand() % FIELD_SIZE, rand() % FIELD_SIZE};
|
food = (Food){rand() % SIZE, rand() % SIZE};
|
||||||
} while (playerCheckFoodCollision(player, food));
|
} while (playerCheckFoodCollision(player, food));
|
||||||
return food;
|
return food;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ int main(int argc, char **argv)
|
||||||
platformGameInit();
|
platformGameInit();
|
||||||
|
|
||||||
Player player; playerCreate(&player, DOWN, DEFX, DEFY, 0);
|
Player player; playerCreate(&player, DOWN, DEFX, DEFY, 0);
|
||||||
Screen screen; screenCreate(&screen, FIELD_SIZE, FIELD_SIZE, ' ');
|
Screen screen; screenCreate(&screen, SIZE, SIZE, ' ');
|
||||||
Food food = generateFood(player);
|
Food food = generateFood(player);
|
||||||
|
|
||||||
int key = 0;
|
int key = 0;
|
||||||
|
@ -53,7 +53,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
resetCoordinates();
|
resetCoordinates();
|
||||||
screenShow(screen);
|
screenShow(screen);
|
||||||
for (int i = 0; i < FIELD_SIZE*2; ++i) putchar('-');
|
for (int i = 0; i < SIZE*2; ++i) putchar('-');
|
||||||
printf("\nScore: %d\n", player.score);
|
printf("\nScore: %d\n", player.score);
|
||||||
|
|
||||||
sleepMS(SLEEP);
|
sleepMS(SLEEP);
|
||||||
|
@ -79,12 +79,12 @@ int main(int argc, char **argv)
|
||||||
} key = 0;
|
} key = 0;
|
||||||
if (stopped) continue;
|
if (stopped) continue;
|
||||||
|
|
||||||
if (playerDoTick(&player, food) && player.score < FIELD_SIZE*FIELD_SIZE - 1)
|
if (playerDoTick(&player, food) && player.score < SIZE*SIZE - 1)
|
||||||
food = generateFood(player);
|
food = generateFood(player);
|
||||||
|
|
||||||
head_x = player.head->x;
|
head_x = player.head->x;
|
||||||
head_y = player.head->y;
|
head_y = player.head->y;
|
||||||
if (head_x >= FIELD_SIZE || head_x < 0 || head_y >= FIELD_SIZE || head_y < 0 || playerCheckSelfCollision(player))
|
if (head_x >= SIZE || head_x < 0 || head_y >= SIZE || head_y < 0 || playerCheckSelfCollision(player))
|
||||||
{
|
{
|
||||||
running = false;
|
running = false;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue