Some movements
parent
e2d01db144
commit
cf71b4d57d
14
src/main.c
14
src/main.c
|
@ -32,29 +32,30 @@ Food generateFood(Player player)
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
srand((unsigned int)time(NULL));
|
srand((unsigned int)time(NULL));
|
||||||
|
|
||||||
Player player; playerCreate(&player, DOWN, DEFX, DEFY, 0);
|
Player player; playerCreate(&player, DOWN, DEFX, DEFY, 0);
|
||||||
Screen screen; screenCreate(&screen, SIZE, SIZE, ' ');
|
Screen screen; screenCreate(&screen, SIZE, SIZE, ' ');
|
||||||
int i;
|
|
||||||
int head_x, head_y;
|
|
||||||
Food food = generateFood(player);
|
Food food = generateFood(player);
|
||||||
|
|
||||||
bool running = true;
|
|
||||||
int key = 0;
|
int key = 0;
|
||||||
|
bool running = true;
|
||||||
bool stopped = false;
|
bool stopped = false;
|
||||||
InputArgs input_args = (InputArgs){ &key, &running };
|
int head_x, head_y;
|
||||||
|
|
||||||
threadCreate(input, &input_args);
|
threadCreate(input, &(InputArgs){ &key, &running });
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
screenSet(screen, ' ');
|
screenSet(screen, ' ');
|
||||||
drawPlayer(player, screen);
|
drawPlayer(player, screen);
|
||||||
*screenGetPoint(screen, food.x, food.y) = '@';
|
*screenGetPoint(screen, food.x, food.y) = '@';
|
||||||
|
|
||||||
resetCoordinates();
|
resetCoordinates();
|
||||||
screenShow(screen);
|
screenShow(screen);
|
||||||
for (i = 0; i < 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);
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case 'q':
|
case 'q':
|
||||||
|
@ -78,6 +79,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (playerDoTick(&player, food) && player.score < SIZE*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 >= SIZE || head_x < 0 || head_y >= SIZE || head_y < 0 || playerCheckSelfCollision(player))
|
if (head_x >= SIZE || head_x < 0 || head_y >= SIZE || head_y < 0 || playerCheckSelfCollision(player))
|
||||||
|
|
Loading…
Reference in New Issue