Проблемы с движением, пропуск полей - PullRequest
0 голосов
/ 29 мая 2019

Я делаю игру, в которой вы (игрок) представлены числом в двумерной матрице. Проблема в том, что когда я перемещаю плеер, он пропускает поля и не очень хорошо реагирует. Движение очень неточное. Если бы вы могли запустить программу, вы могли бы лучше понять проблему. Как я могу решить эту проблему?

#include <stdio.h>
#include <windows.h>
#include <time.h>

void delay(unsigned int mseconds)
{
    clock_t goal = mseconds + clock();
    while (goal > clock())
        ;
}

int map[5][5] = {{0, 0, 0, 0, 0},
                 {0, 0, 0, 0, 0},
                 {0, 0, 0, 0, 0},
                 {0, 0, 0, 0, 0},
                 {0, 0, 0, 0, 0}};

int mUpdate(int x)
{
    int i, j;
    for (i = 0; i < 5; i++)
    {
        for (j = 0; j < 5; j++)
        {
            printf("%d     ", map[i][j]);
        }
        printf("\n");
    }
}

int mRefresh(int x)
{
    int i, j;
    for (i = 0; i < 5; i++)
    {
        for (j = 0; j < 5; j++)
        {
            if (map[i][j] > 0)
            {
                map[i][j] = 0;
            }
        }
    }
}

int main()
{
    int c;
    int i, j;
    int p_num;
    printf("Hey! Choose a number from 1-9 that will represent you!: ");
    scanf("%d", &p_num);
    printf("Choose a starting position by inputting two coordinates from 1-4!:  ");
    scanf("%d %d", &i, &j);
    printf("\nVery well, this is your starting position!\n");
    map[i][j] = p_num;
    mUpdate(map[i][j]);
    printf("\nYou are now the number %d !\n", p_num);
    printf("\nPlease wait for the map to load!");
    printf("\nMap loading will start soon!");
    delay(3000);
    for (c = 0; c < 5; c++)
    {
        printf("\nLoading.");
        delay(500);
        system("cls");
        printf("\nLoading..");
        delay(500);
        system("cls");
        printf("\nLoading...");
        delay(500);
        system("cls");
    }
    printf("Map loaded!\n");
    printf("\nUse arrow keys to move thru the matrix!\n");
    mUpdate(map[i][j]);

    int game_running = true;
    while (game_running = true)
    {
        if (GetAsyncKeyState(VK_DOWN))
        {
            // delay(200);
            map[i++][j] = p_num;
            system("cls");
            mUpdate(map[i][j]);
            mRefresh(map[i][j]);
        }
        else if (GetAsyncKeyState(VK_UP))
        {
            // delay(200);
            map[i--][j] = p_num;
            system("cls");
            mUpdate(map[i][j]);
            mRefresh(map[i][j]);
        }
        else if (GetAsyncKeyState(VK_RIGHT))
        {
            // delay(1000);
            map[i][j++] = p_num;
            system("cls");
            mUpdate(map[i][j]);
            mRefresh(map[i][j]);
        }
        else if (GetAsyncKeyState(VK_LEFT))
        {
            // delay(200);
            map[i][j--] = p_num;
            system("cls");
            mUpdate(map[i][j]);
            mRefresh(map[i][j]);
        }
    }
    system("cls");
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...