#include <allegro.h>
volatile long speed = 0;
void increment_speed()
{
speed++;
}
END_OF_FUNCTION( increment_speed );
LOCK_VARIABLE( speed );
LOCK_FUNCTION( increment_speed );
class CPlayer {
public:
int x, y;
int sila;
int obrona;
int health;
};
BITMAP * zadanie = NULL;
BITMAP * ludek = NULL;
BITMAP * hp = NULL;
BITMAP * pelne_hp = NULL;
BITMAP * eq = NULL;
BITMAP * gui = NULL;
BITMAP * teren = NULL;
BITMAP * bufor = NULL;
BITMAP * tablica = NULL;
BITMAP * czarne = NULL;
BITMAP * trollik = NULL;
BITMAP * troll_atak = NULL;
int mapa_x = 0, mapa_y = 1;
short int map[ 18 ][ 30 ] =
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 1, 0, 3, 0, 5, 1, 4, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 7, 6, 3, 0, 0, 0, 1, 0, 2, 0, 6, 8, 7, 8, 6, 7, 6, 7, 6, 7, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 7, 6, 6, 7, 6, 8, 6, 7, 6, 7, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 4, 0, 1, 0, 0, 0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y++ )
{
blit( teren, bufor,
( 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()
{
CPlayer player;
CPlayer troll;
player.x = 240;
player.y = 160;
troll.x = 360;
troll.y = 320;
player.health = 40;
troll.health = 100;
int hp_x = 505, hp_y = 70;
int eq_x = 520, eq_y = 90;
int zadanie_x = 60, zadanie_y = 40;
int tablica_x = 20, tablica_y = 375;
int scrolling_x = 0, scrolling_y = 0;
int alpha = 0;
float licznik = 0.0f;
bool kolizja_w_prawo() {
if(( player.x ==( troll.x - scrolling_x - 40 ) ) &&( player.y ==( troll.y - scrolling_y ) ) ) return true;
else return false;
}
bool kolizja_w_lewo() {
if(( player.x ==( troll.x - scrolling_x + 40 ) ) &&( player.y ==( troll.y - scrolling_y ) ) ) return true;
else return false;
}
bool kolizja_w_dol() {
if(( player.x ==( troll.x - scrolling_x ) ) &&( player.y ==( troll.y - scrolling_y - 40 ) ) ) return true;
else return false;
}
bool kolizja_w_gore() {
if(( player.x ==( troll.x - scrolling_x ) ) &&( player.y ==( troll.y - scrolling_y + 40 ) ) ) return true;
else return false;
}
bool kolizja_prawo_gora() {
if(( player.x ==( troll.x - scrolling_x + 40 ) ) &&( player.y ==( troll.y - scrolling_y - 40 ) ) ) return true;
else return false;
}
bool kolizja_prawo_dol() {
if(( player.x ==( troll.x - scrolling_x + 40 ) ) &&( player.y ==( troll.y - scrolling_y + 40 ) ) ) return true;
else return false;
}
bool kolizja_lewo_gora() {
if(( player.x ==( troll.x - scrolling_x - 40 ) ) &&( player.y ==( troll.y - scrolling_y - 40 ) ) ) return true;
else return false;
}
bool kolizja_lewo_dol() {
if(( player.x ==( troll.x - scrolling_x - 40 ) ) &&( player.y ==( troll.y - scrolling_y + 40 ) ) ) return true;
else return false;
}
allegro_init();
install_keyboard();
set_color_depth( 16 );
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 );
install_timer();
install_int_ex( increment_speed, BPS_TO_TIMER( 40 ) );
bufor = create_bitmap( 640, 480 );
if( !bufor )
{
set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
allegro_message( "Nie mogę utworzyć bufora !" );
allegro_exit();
return 0;
}
teren = load_bmp( "teren.bmp", default_palette );
ludek = load_bmp( "ludek.bmp", default_palette );
gui = load_bmp( "gui.bmp", default_palette );
hp = load_bmp( "hp.bmp", default_palette );
pelne_hp = load_bmp( "pelne_hp.bmp", default_palette );
eq = load_bmp( "eq.bmp", default_palette );
zadanie = load_bmp( "zadanie.bmp", default_palette );
tablica = load_bmp( "tablica.bmp", default_palette );
czarne = load_bmp( "czarne.bmp", default_palette );
trollik = load_bmp( "troll.bmp", default_palette );
troll_atak = load_bmp( "troll_atak.bmp", default_palette );
while( !key[ KEY_ESC ] )
{
licznik += 1.0f;
while( speed > 0 )
{
if( player.health > 0 ) {
if(( key[ KEY_RIGHT ] ) &&( mapa_x < 20 ) ) {
if(((( map[ mapa_y + 4 ][ mapa_x + 1 + 6 ] ) == 0 ) ||(( map[ mapa_y + 4 ][ mapa_x + 1 + 6 ] ) == 2 ) ||(( map[ mapa_y + 4 ][ mapa_x + 1 + 6 ] ) == 6 ) ||(( map[ mapa_y + 4 ][ mapa_x + 1 + 6 ] ) == 7 ) ||(( map[ mapa_y + 4 ][ mapa_x + 1 + 6 ] ) == 8 ) ) &&( !kolizja_w_prawo() ) ) {
mapa_x = mapa_x + 1;
scrolling_x += 40;
}
else {
mapa_x = mapa_x;
}
} else
if(( key[ KEY_LEFT ] ) &&( mapa_x > 0 ) ) {
if(((( map[ mapa_y + 4 ][ mapa_x - 1 + 6 ] ) == 0 ) ||(( map[ mapa_y + 4 ][ mapa_x - 1 + 6 ] ) == 2 ) ||(( map[ mapa_y + 4 ][ mapa_x - 1 + 6 ] ) == 6 ) ||(( map[ mapa_y + 4 ][ mapa_x - 1 + 6 ] ) == 7 ) ||(( map[ mapa_y + 4 ][ mapa_x - 1 + 6 ] ) == 8 ) ) &&( !kolizja_w_lewo() ) ) {
mapa_x = mapa_x - 1;
scrolling_x -= 40;
}
else {
mapa_x = mapa_x;
}
} else
if(( key[ KEY_DOWN ] ) &&( mapa_y < 8 ) ) {
if(((( map[ mapa_y + 1 + 4 ][ mapa_x + 6 ] ) == 0 ) ||(( map[ mapa_y + 1 + 4 ][ mapa_x + 6 ] ) == 2 ) ||(( map[ mapa_y + 1 + 4 ][ mapa_x + 6 ] ) == 6 ) ||(( map[ mapa_y + 1 + 4 ][ mapa_x + 6 ] ) == 7 ) ||(( map[ mapa_y + 1 + 4 ][ mapa_x + 6 ] ) == 8 ) ) &&( !kolizja_w_dol() ) ) {
mapa_y = mapa_y + 1;
scrolling_y += 40;
}
else {
mapa_y = mapa_y;
}
} else
if(( key[ KEY_UP ] ) &&( mapa_y > 0 ) ) {
if(((( map[ mapa_y - 1 + 4 ][ mapa_x + 6 ] ) == 0 ) ||(( map[ mapa_y - 1 + 4 ][ mapa_x + 6 ] ) == 2 ) ||(( map[ mapa_y - 1 + 4 ][ mapa_x + 6 ] ) == 6 ) ||(( map[ mapa_y - 1 + 4 ][ mapa_x + 6 ] ) == 7 ) ||(( map[ mapa_y - 1 + 4 ][ mapa_x + 6 ] ) == 8 ) ) &&( !kolizja_w_gore() ) ) {
mapa_y = mapa_y - 1;
scrolling_y -= 40;
}
else {
mapa_y = mapa_y;
}
}
}
speed -= 2;
}
clear_to_color( bufor, makecol( 150, 150, 150 ) );
wys_mape();
masked_blit( trollik, bufor, 0, 0, troll.x - scrolling_x, troll.y - scrolling_y, trollik->w, trollik->h );
masked_blit( ludek, bufor, 0, 0, player.x, player.y, ludek->w, ludek->h );
masked_blit( gui, bufor, 0, 0, 0, 0, gui->w, gui->h );
masked_blit( hp, bufor, 0, 0, hp_x, hp_y, hp->w, hp->h );
masked_blit( eq, bufor, 0, 0, eq_x, eq_y, eq->w, eq->h );
masked_blit( pelne_hp, bufor, 0, 0, hp_x, hp_y, player.health, pelne_hp->h );
if( map[ mapa_y + 4 ][ mapa_x + 6 ] == 2 ) {
blit( tablica, bufor, 0, 0, tablica_x, tablica_y, tablica->w, tablica->h );
if( key[ KEY_P ] ) {
masked_blit( zadanie, bufor, 0, 0, zadanie_x, zadanie_y, zadanie->w, zadanie->h );
}
}
if(( kolizja_w_lewo() ) ||( kolizja_w_prawo() ) ||( kolizja_w_dol() ) ||( kolizja_w_gore() ) ||( kolizja_prawo_gora() ) ||( kolizja_prawo_dol() ) ||( kolizja_lewo_gora() ) ||( kolizja_lewo_dol() ) ) {
blit( troll_atak, bufor, 0, 0, tablica_x, tablica_y, tablica->w, tablica->h );
textprintf_ex( bufor, font, tablica_x + 15, tablica_y + 40, makecol( 0, 0, 0 ), - 1, "%d / 100", troll.health );
}
textprintf_ex( bufor, font, 610, 74, makecol( 255, 255, 255 ), - 1, "%d", player.health );
textprintf_ex( bufor, font, 20, 20, makecol( 0, 0, 0 ), - 1, "ludek.x = %d, ludek.y = %d troll.x = %d, troll.y = %d", player.x, player.y, troll.x - scrolling_x, troll.y - scrolling_y );
textprintf_ex( bufor, font, 20, 40, makecol( 0, 0, 0 ), - 1, "mapa_x = %d, mapa_y = %d", mapa_x, mapa_y );
if( licznik >= 1 && alpha <= 255 )
{
alpha += 1;
licznik = 0.0f;
}
if( player.health == 0 ) {
set_trans_blender( 0, 0, 0, alpha );
draw_trans_sprite( bufor, czarne, 0, 0 );
textprintf_ex( bufor, font, 180, 180, makecol( 255, 255, 255 ), - 1, "Niestety nie zyjesz!" );
}
blit( bufor, screen, 0, 0, 0, 0, 640, 480 );
}
remove_int( increment_speed );
destroy_bitmap( teren );
destroy_bitmap( ludek );
destroy_bitmap( gui );
destroy_bitmap( hp );
destroy_bitmap( bufor );
destroy_bitmap( zadanie );
destroy_bitmap( eq );
destroy_bitmap( pelne_hp );
destroy_bitmap( trollik );
destroy_bitmap( troll_atak );
allegro_exit();
return 0;
}
END_OF_MAIN();