Napisałem prostego ponga z użyciem allegro, problem polega na tym że stworzonego po kompilacji pliku exe nie da się uruchomić.
Treść komunikatu:
Nie można uruchomić programu, ponieważ na komputerze nie znaleziono alleg44.dll...
Dziwne jest to że z poziomu deva wszystko się uruchamia.
#include<allegro.h>
volatile int speed = 0;
void increment_speed()
{
speed++;
}
END_OF_FUNCTION(increment_speed);
LOCK_VARIABLE(speed); //przydzielanie im stałego miejsca w pamięci
LOCK_FUNCTION(increment_speed);
int main()
{
allegro_init();
install_keyboard();
install_timer();
install_int_ex(increment_speed, BPS_TO_TIMER(300));
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
clear_to_color(screen, makecol(128, 128, 128));
BITMAP *player1 = NULL;
BITMAP *player2 = NULL;
BITMAP *ball = NULL;
BITMAP *buffer = NULL;
player1 = create_bitmap(10, 100);
player2 = create_bitmap(10, 100);
ball = load_bmp("ball.bmp", default_palette);
buffer = create_bitmap(800, 600);
clear_to_color(player1, makecol(0, 0, 255));
clear_to_color(player2, makecol(255, 0, 0));
int p1_y = 250, p2_y = 250, ball_x = 400, ball_y = 300;
int move_ball_x = -1, move_ball_y = 1 ;
int p1_x = 10, p2_x = 780;
int p1_score = 0, p2_score = 0;
while(!key[KEY_ESC])
{
while(speed>0)
{
if(key[KEY_W]) p1_y--;
if(key[KEY_S]) p1_y++;
if(key[KEY_UP]) p2_y--;
if(key[KEY_DOWN]) p2_y++;
//if(p2_y+(player2->h/2)>ball_y) p2_y--;
//if(p2_y+(player2->h/2)<ball_y) p2_y++;
if(p1_y<=0) p1_y++;
if(p2_y<=0) p2_y++;
if(p1_y+player1->h>=600) p1_y--;
if(p2_y+player2->h>=600) p2_y--;
if((ball_y<=0)||(ball_y+ball->h>=600)) move_ball_y = -move_ball_y; //odbicie od sciany górnej i dolnej
if((ball_y+ball->h==p1_y)&&(ball_x>=10)&&(ball_x+ball->w<=10+player1->w)) move_ball_y = -move_ball_y;
if((ball_y==p1_y+player1->h)&&(ball_x>=10)&&(ball_x+ball->w<=10+player1->w)) move_ball_y = -move_ball_y;
if((ball_y==p2_y)&&(ball_x>=780)&&(ball_x+ball->w<=780+player2->w)) move_ball_y = -move_ball_y;
if((ball_y==p2_y+player2->h)&&(ball_x>=780)&&(ball_x+ball->w<=780+player1->w)) move_ball_y = -move_ball_y;
if((ball_x == p1_x + player1->w)&&(ball_y>=p1_y)&&(ball_y+ball->h<=p1_y+player1->h)) move_ball_x = -move_ball_x;
if((ball_x+ball->w == p1_x)&&(ball_y>=p1_y)&&(ball_y+ball->h<=p1_y+player1->h)) move_ball_x = -move_ball_x;
if((ball_x == p2_x + player2->w)&&(ball_y>=p2_y)&&(ball_y+ball->h<=p2_y+player2->h)) move_ball_x = -move_ball_x;
if((ball_x+ball->w == p2_x)&&(ball_y>=p2_y)&&(ball_y+ball->h<=p2_y+player2->h)) move_ball_x = -move_ball_x;
if(ball_x == 0)
{
p2_score++;
ball_x = 400;
ball_y = 300;
system("pause");
}
if(ball_x+ball->w == 800)
{
p1_score++;
ball_x = 400;
ball_y = 300;
system("pause");
}
ball_x += move_ball_x;
ball_y += move_ball_y;
speed--;
}
clear_to_color(buffer, makecol(128, 128, 128));
textprintf_ex( buffer, font, 200, 20, makecol( 0, 0, 255 ), -1, "Gracz: %d", p1_score );
textprintf_ex( buffer, font, 400, 20, makecol( 255, 0, 0 ), -1, "Komputer: %d", p2_score );
draw_sprite(buffer, ball, ball_x, ball_y);
draw_sprite(buffer, player1, 10, p1_y);
draw_sprite(buffer, player2, 780, p2_y);
blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);
}
destroy_bitmap(player1);
destroy_bitmap(player2);
destroy_bitmap(ball);
destroy_bitmap(buffer);
allegro_exit();
return 0;
}
END_OF_MAIN();
Próbowałem też użyć Code::Blocks, ale tam po uruchomieniu występuje błąd "program przestał działać", nie wiem dlaczego.