Na jako takim poziomie umiem C++ [do zadań maturalnych]. Dziś wziąłem się za "allegro".
Wszystko szło fajnie jak w tutach. Ale gdy chciałem wyświetlić mapę to nic się nie pokazuje :/
#include <allegro.h>
#include <conio.h>
#include <stdio.h>
volatile long speed = 0;
void increment_speed()
{
speed++;
}
int mapa_x = 0, mapa_y = 0;
BITMAP * teren = NULL;
BITMAP * bufor2 = NULL;
short int map[ 10 ][ 20 ] =
{
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 6, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 4, 9, 10, 10, 10, 8, 3, 5, 15, 0, 2, 2, 2, 1, 15,
2, 1, 15, 15, 15, 15, 7, 10, 10, 10, 6, 15, 15, 15, 7, 10, 10, 10, 6, 15,
10, 6, 15, 15, 15, 15, 4, 9, 10, 10, 6, 15, 15, 15, 4, 3, 3, 3, 5, 15,
10, 12, 2, 1, 15, 15, 15, 7, 10, 8, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15,
10, 10, 10, 6, 15, 15, 15, 4, 3, 5, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2,
10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2, 13, 10, 10,
3, 3, 3, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 10, 10, 10, 8, 3,
15, 15, 15, 15, 15, 0, 1, 15, 15, 15, 15, 15, 0, 2, 13, 10, 10, 10, 6, 15,
15, 15, 15, 15, 15, 4, 5, 15, 15, 15, 15, 15, 7, 10, 10, 10, 10, 10, 6, 15
};
void wys_mape()
{
int licznik_x, licznik_y;
for( licznik_x = 0; licznik_x < 10; licznik_x++ )
{
for( licznik_y = 0; licznik_y < 5; licznik_y++ )
{
blit( teren, bufor2,
( map[ licznik_y + mapa_y ][ licznik_x + mapa_x ] % 4 ) * 40,
( map[ licznik_y + mapa_y ][ licznik_x + mapa_x ] / 4 ) * 40,
licznik_x * 40, licznik_y * 40, 40, 40 );
}
}
};
int main()
{
allegro_init();
install_keyboard();
set_color_depth( 32 );
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 1024, 720, 0, 0 );
clear_to_color( screen, makecol( 128, 128, 128 ) );
BITMAP * menu = NULL;
menu = load_tga( "gfx\\menu\\menu.tga", default_palette );
if( !menu )
{
set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
allegro_message( "Nie mozna zaladowac menu!" );
allegro_exit();
return 0;
}
blit( menu, screen, 0, 0, 0, 0, menu->w, menu->h );
do {
if( key[ KEY_1 ] )
{
END_OF_FUNCTION( increment_speed );
LOCK_VARIABLE( speed );
LOCK_FUNCTION( increment_speed );
install_timer();
install_int_ex( increment_speed, BPS_TO_TIMER( 40 ) );
set_color_depth( 16 );
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 1024, 720, 0, 0 );
BITMAP * bufor = NULL;
BITMAP * mario0 = NULL;
BITMAP * mario1 = NULL;
bufor = create_bitmap( 1024, 720 );
if( !bufor )
{
set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
allegro_message( "Nie mogę utworzyć bufora !" );
allegro_exit();
return 0;
}
mario0 = load_tga( "gfx\\renders\\mario\\mario00.tga", default_palette );
mario1 = load_tga( "gfx\\renders\\mario\\mario01.tga", default_palette );
int mario_x = 100, mario_y = 100;
int frame = 0;
while( !key[ KEY_ESC ] )
{
while( speed > 0 )
{
if( key[ KEY_LEFT ] ) mario_x--;
if( key[ KEY_RIGHT ] ) mario_x++;
if( key[ KEY_UP ] ) mario_y--;
if( key[ KEY_DOWN ] ) mario_y++;
speed--;
frame++;
if( frame > 40 ) frame = 0;
}
clear_to_color( bufor, makecol( 150, 150, 150 ) );
if( frame < 20 ) { draw_sprite( bufor, mario0, mario_x, mario_y ); }
else if( frame >= 20 && frame < 40 ) { draw_sprite( bufor, mario1, mario_x, mario_y ); }
blit( bufor, screen, 0, 0, 0, 0, 1024, 720 );
}
remove_int( increment_speed );
destroy_bitmap( mario0 );
destroy_bitmap( mario1 );
destroy_bitmap( bufor );
}
if( key[ KEY_2 ] )
{
textout_ex( screen, font, "Starowanie:", 20, 20, makecol( 0, 0, 0 ), - 1 );
textout_ex( screen, font, "- Lewo : <", 20, 35, makecol( 0, 0, 0 ), - 1 );
textout_ex( screen, font, "- Prawo : >", 20, 50, makecol( 0, 0, 0 ), - 1 );
textout_ex( screen, font, "- Skok : ^", 20, 65, makecol( 0, 0, 0 ), - 1 );
textout_ex( screen, font, "- Dol : v", 20, 80, makecol( 0, 0, 0 ), - 1 );
textout_ex( screen, font, "- Strzal : spacja", 20, 95, makecol( 0, 0, 0 ), - 1 );
textout_ex( screen, font, "- Powrot : ESC", 20, 110, makecol( 0, 0, 0 ), - 1 );
}
if( key[ KEY_3 ] )
{
}
} while( !key[ KEY_4 ] );
readkey();
destroy_bitmap( menu );
allegro_exit();
return 0;
}
END_OF_MAIN();
To co mam odznaczone kreskami to mi nie działa :/ tylko czarny ekran.
Nie orientuje się jeszcze w tym tak dobrze.