我不知道如何在CSFML上缩短代码

时间:2019-12-01 20:38:00

标签: c

好吧,标题说明了一切,我必须将此代码设置成20行,我真的很挣扎。我可以根据需要创建任意数量的函数,但它们最多只能有20行。如果有人可以帮助我,我将不胜感激。

int window_creator()
{
    sfVideoMode mode = {800, 600, 32};
    sfRenderWindow *window = sfRenderWindow_create(mode, "MyHunter",
    sfResize | sfClose, NULL);
    sfEvent event;
    sfIntRect rect = {0, 0, 110, 110};
    sfTexture *tbackground = sfTexture_createFromFile
    ("home/user/Projects/Typeo/duck_hunt/resources/background.png",
     NULL);
    sfSprite *sbackground = sfSprite_create();
    sfTexture *tduck = sfTexture_createFromFile
    ("home/user/Projects/Typeo/duck_hunt/resources/duck_sprites.png",
     NULL);
    sfSprite *sduck = sfSprite_create();

    sfSprite_setTexture(sbackground, tbackground, sfTrue);
    sfSprite_setTexture(sduck, tduck, sfTrue);

    while (sfRenderWindow_isOpen(window)) {
        analyse_events(event, window);
        sfRenderWindow_clear(window, sfBlack);
        flying(&rect, 110, 220);
        sfSprite_setTextureRect(sduck, rect);
        sfRenderWindow_drawSprite(window, sbackground, NULL);
        sfRenderWindow_drawSprite(window, sduck, NULL);
        sfSprite_move(sduck, (sfVector2f) {0.1, 0});
        sfRenderWindow_display(window);
    }
    sfSprite_destroy(sduck);
    sfTexture_destroy(tduck);
    sfSprite_destroy(sbackground);
    sfTexture_destroy(tbackground);
    sfRenderWindow_destroy(window);
}

0 个答案:

没有答案