gpt4 book ai didi

c - Allegro 5中Allegro 4的功能

转载 作者:太空宇宙 更新时间:2023-11-04 02:55:24 24 4
gpt4 key购买 nike

我有一个用 Allegro 4 编写的代码,我正在将其转换为 Allegro 5,但是我遇到了一些严重的问题,其中一些函数不再存在于 allegro 5 中,其中之一是“blit”

BITMAP *bTile; // Bitmap do tile;
BITMAP *bMapa; // Bitmap do mapa;
BITMAP *bTexturas[20]; // Vetor de bitmap das texturas;
BITMAP *bChar; // Bitmap do personagem;
BITMAP *bMario[3];
// ##########################################################

int main()
{
int vResolucao_x = 640;
int vResolucao_y = 480;

init(vResolucao_x, vResolucao_y);

BITMAP *buffer = create_bitmap(vResolucao_x, vResolucao_y);

bTile = load_bitmap("Tiles/tile.bmp", NULL);
bChar = load_bitmap("Tiles/mario.bmp", NULL);
bMapa = create_bitmap(vResolucao_x, vResolucao_y);

// ############# - Carrega imagens do mario - ############
bMario[0] = create_bitmap(vTile,vTile);
bMario[1] = create_bitmap(vTile,vTile);
bMario[2] = create_bitmap(vTile,vTile);
blit(bChar, bMario[0], 0, 0, 0, 0, vTile, vTile);
blit(bChar, bMario[1], 33, 0, 0, 0, vTile, vTile);
blit(bChar, bMario[2], 66, 0, 0, 0, vTile, vTile);
// #######################################################

install_int(fGravidade,5);

fCarrega_Sprites_Mapa();
fCarrega_Mapa();
fMostra_Mapa();

draw_sprite(screen, bMapa, 0, 0 );

while (!key[KEY_ESC]) {

我的旧代码几乎没有任何东西适用于 Allegro 5,所以我正在尽我所能进行转换,但是这个 blit 函数在 allegro 5 中找不到它,另一个我找不到你的模拟函数是:install_int (...)

最佳答案

Allegro 5 本质上是一个全新的库。这是一个逐行翻译,尽可能做到最好。请注意,Allegro 5 使用了一个根本不同的概念(事件循环),在开始尝试转换您的代码之前,您真的应该花时间了解它是如何工作的。

ALLEGRO_BITMAP *bMario[3];
// ##########################################################

int main()
{
int vResolucao_x = 640;
int vResolucao_y = 480;

init(vResolucao_x, vResolucao_y);

ALLEGRO_BITMAP *buffer = al_create_bitmap(vResolucao_x, vResolucao_y);

bTile = al_load_bitmap("Tiles/tile.bmp");
bChar = al_load_bitmap("Tiles/mario.bmp");
bMapa = al_create_bitmap(vResolucao_x, vResolucao_y);

// ############# - Carrega imagens do mario - ############
bMario[0] = al_create_bitmap(vTile,vTile);
bMario[1] = al_create_bitmap(vTile,vTile);
bMario[2] = al_create_bitmap(vTile,vTile);

al_set_target_bitmap(bMario[0]);
al_draw_bitmap(bchar, 0, 0, 0);

al_set_target_bitmap(bMario[1]);
al_draw_bitmap(bchar, 33, 0, 0);

al_set_target_bitmap(bMario[2]);
al_draw_bitmap(bchar, 66, 0, 0);

al_set_target_backbuffer(display);
// #######################################################

fGravidade = al_create_timer(5 / 1000.0); // ALLEGRO_TIMER*

ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
al_register_event_source(queue, al_get_timer_event_source(gfGravidade));
al_register_event_source(queue, al_get_keyboard_event_source());

fCarrega_Sprites_Mapa();
fCarrega_Mapa();
fMostra_Mapa();

al_draw_bitmap(bMapa, 0, 0, 0);
al_flip_display();

while (true) {
ALLEGRO_EVENT event;
al_wait_for_event(queue, &event);

if (event.type == ALLEGRO_EVENT_TIMER) {
// fGravidade ticked
}
else if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
break;
}
}
}

关于c - Allegro 5中Allegro 4的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18175528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com