Completely fix #3

fix-mingw
Nakidai 2024-03-06 23:50:27 +03:00
parent 1c7a0ef6b2
commit bb55e690d0
Signed by: nakidai
GPG Key ID: 18AD605FDA13FE5A
5 changed files with 19 additions and 19 deletions

View File

@ -27,7 +27,7 @@ endif()
target_include_directories(csnake PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(SIZE 10 CACHE STRING "Size of game field")
set(FIELD_SIZE 10 CACHE STRING "Size of game field")
set(DEFX 0 CACHE STRING "Start x")
set(DEFY 0 CACHE STRING "Start y")
set(SLEEP 1000 CACHE STRING "Sleep between frames (ms)")

8
configure vendored
View File

@ -7,7 +7,7 @@ usage()
CFLAGS - flags for compiler
LDFLAGS - flags for linker
OUT - out file (default: csnake
SIZE - size of game field
FIELD_SIZE - size of game field
DEFX - start x
DEFY - start y
SLEEP - sleep between frames (ms)"
@ -28,7 +28,7 @@ CC=${CC:-cc}
CFLAGS=${CFLAGS:-}
LDFLAGS=${LDFLAGS:-}
OUT=${OUT:-csnake}
SIZE=${SIZE:-10}
FIELD_SIZE=${FIELD_SIZE:-10}
DEFX=${DEFX:-0}
DEFY=${DEFY:-0}
SLEEP=${SLEEP:-1000}
@ -40,7 +40,7 @@ echo "LDFLAGS: $LDFLAGS"
echo "Out file: $OUT"
echo
echo "Code configuration:"
echo "Size: $SIZE"
echo "Field size: $FIELD_SIZE"
echo "Start x: $DEFX"
echo "Start y: $DEFY"
echo "Sleep: $SLEEP"
@ -50,7 +50,7 @@ CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
OUT = $OUT" > config.mk
echo "#define SIZE $SIZE
echo "#define FIELD_SIZE $FIELD_SIZE
#define DEFX $DEFX
#define DEFY $DEFY
#define SLEEP $SLEEP" > include/config.h

View File

@ -1,4 +1,4 @@
#define SIZE ${SIZE}
#define FIELD_SIZE ${FIELD_SIZE}
#define DEFX ${DEFX}
#define DEFY ${DEFY}
#define SLEEP ${SLEEP}

View File

@ -2,7 +2,7 @@
#define __PLATFORM_SCREEN_H__
#ifdef _WIN32
#include <Windows.h>
#include <windows.h>
#else
#include <stdio.h>
#endif /* _WIN32 */

View File

@ -25,7 +25,7 @@ Food generateFood(Player player)
Food food;
do
{
food = (Food){rand() % SIZE, rand() % SIZE};
food = (Food){rand() % FIELD_SIZE, rand() % FIELD_SIZE};
} while (playerCheckFoodCollision(player, food));
return food;
}
@ -36,7 +36,7 @@ int main(int argc, char **argv)
platformGameInit();
Player player; playerCreate(&player, DOWN, DEFX, DEFY, 0);
Screen screen; screenCreate(&screen, SIZE, SIZE, ' ');
Screen screen; screenCreate(&screen, FIELD_SIZE, FIELD_SIZE, ' ');
Food food = generateFood(player);
int key = 0;
@ -53,7 +53,7 @@ int main(int argc, char **argv)
resetCoordinates();
screenShow(screen);
for (int i = 0; i < SIZE*2; ++i) putchar('-');
for (int i = 0; i < FIELD_SIZE*2; ++i) putchar('-');
printf("\nScore: %d\n", player.score);
sleepMS(SLEEP);
@ -79,12 +79,12 @@ int main(int argc, char **argv)
} key = 0;
if (stopped) continue;
if (playerDoTick(&player, food) && player.score < SIZE*SIZE - 1)
if (playerDoTick(&player, food) && player.score < FIELD_SIZE*FIELD_SIZE - 1)
food = generateFood(player);
head_x = player.head->x;
head_y = player.head->y;
if (head_x >= SIZE || head_x < 0 || head_y >= SIZE || head_y < 0 || playerCheckSelfCollision(player))
if (head_x >= FIELD_SIZE || head_x < 0 || head_y >= FIELD_SIZE || head_y < 0 || playerCheckSelfCollision(player))
{
running = false;
break;