allegro, small problem

This is a discussion on allegro, small problem within the C++ Programming forums, part of the General Programming Boards category; Code: int allegro ( int srcx, int srcy ) { allegro_init(); install_keyboard(); install_timer() LOCK_VARIABLE ( speed_counter ); LOCK_FUNCTION ( increment_speed_counter ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    29

    allegro, small problem

    Code:
    int allegro ( int srcx, int srcy )
    {
    
    	allegro_init();
    	install_keyboard();
    	install_timer()
    	LOCK_VARIABLE ( speed_counter );
    	LOCK_FUNCTION ( increment_speed_counter )
    	install_int_ex ( increment_speed_counter, BPS_TO_TIMER ( 70 ) );//Set beat's per second 60 works well, generally.
    	set_color_depth ( 32 );
    	set_gfx_mode ( GFX_AUTODETECT,srcx,srcy,0,0 );
    	BITMAP *BG = NULL;
    	BITMAP *ALLO = NULL;
    	BITMAP *arrow = NULL;
    	ALLO = load_bitmap ( "./allgero.bmp", NULL );
    	BG = load_bitmap ( "./back.bmp", NULL );
    	arrow = load_bitmap ( "./arrow.bmp", NULL );
    	buffer = create_bitmap ( srcx,srcy );
    	if ( BG == NULL )
    	{
    		set_gfx_mode ( GFX_TEXT,0,0,0,0 ); //Set the screen mode for allegro messages
    		allegro_message ( "Could not load back.bmp" );
    		exit ( EXIT_FAILURE );
    	}
    	if ( ALLO == NULL )
    	{
    		set_gfx_mode ( GFX_TEXT,0,0,0,0 ); //Set the screen mode for allegro messages
    		allegro_message ( "Could not load allgero.bmp" );
    		exit ( EXIT_FAILURE );
    	}
    	if ( arrow == NULL )
    	{
    		set_gfx_mode ( GFX_TEXT,0,0,0,0 ); //Set the screen mode for allegro messages
    		allegro_message ( "Could not load arrow.bmp" );
    		exit ( EXIT_FAILURE );
    	}
    	short ran_before1 = 0;
    	short ran_before  = 0;
    	short ran_before2 = 0;
    	short ran_before3 = 0;
    	short ran_before4 = 0;
    	int xx = srcx/2-400;
    	int yy = srcy/2-300;
    	long buttony = 0;
    	int aa = -1;
    	int buttonx = 1;
    	/*int arrow_bb_left = xx;
    	int arrow_bb_top = yy;
    	int arrow_bb_bottom = ( arrow_bb_top + arrow->h );
    	int arrow_bb_right = ( arrow_bb_left + arrow->w );
    	int ALLO_bb_left = xxa;
    	int ALLO_bb_top = yya;
    	int ALLO_bb_right = ( ALLO_bb_left + ALLO->w );
    	int ALLO_bb_bottom = ( ALLO_bb_top + ALLO->h );*/
    	//int show_bbox = FALSE;
    	//int collision = FALSE;
    	char str[50];
    	char NUMBER1[100]="0";
    	char NUMBER[100]="0 0 0 00 0 ";
    	while ( !key[KEY_ESC] )
    	{
    		while ( speed_counter > 0 )
    		{
    			//collision = FALSE;
    			//if ( arrow_bb_top < ALLO_bb_top||arrow_bb_bottom > ALLO_bb_bottom||arrow_bb_right > ALLO_bb_right||arrow_bb_left < ALLO_bb_left )
    			//{
    			//	collision = TRUE;
    			//}
    			if ( key[KEY_UP]&&ran_before == 0&&buttony!=0 )
    			{
    				ran_before = 1;
    				buttony=buttony-1;
    			}
    			if ( !key[KEY_UP]&&ran_before == 1 )
    			{
    				ran_before = 0;
    			}
    			if ( key[KEY_DOWN]&&ran_before1 == 0)
    			{
    			cout<<"KEY_DOWN";
    					ran_before1 = 1;
    					buttony++;
    			}
    			if ( !key[KEY_DOWN]&&ran_before1 == 1 )
    			{
    			cout<<"!KEY_DOWN";
    				ran_before1 = 0;
    			}
    			if ( key[KEY_RIGHT]&&ran_before2 == 0&&buttonx!=2 )
    			{
    				buttonx++;
    				ran_before2 = 1;
    			}
    			if ( !key[KEY_RIGHT]&&ran_before2 == 1 )
    			{
    				ran_before2 = 0;
    			}
    			if ( key[KEY_LEFT]&&ran_before3 == 0&&buttonx!=0 )
    			{
    				buttonx--;
    				ran_before3 = 1;
    			}
    			if ( !key[KEY_LEFT]&&ran_before3 == 1 )
    			{
    				ran_before3 = 0;
    			}
    			if ( key[KEY_W] )
    			{
    				yy--;
    			}
    			if ( key[KEY_A] )
    			{
    				xx--;
    			}
    			if ( key[KEY_S] )
    			{
    				yy++;
    			}
    			if ( key[KEY_D] )
    			{
    				xx++;
    			}
    			if ( key[KEY_R] )
    			{
    
    				xx = srcx/2-400;
    				yy = srcy/2-300;
    			}
    			if ( key[KEY_ENTER]&&buttony == 3&&buttonx == 1&&ran_before4 == 0 )
    			{
    				buttony = 0;
    				buttonx = 0;
    				settings ( BG,ALLO,xx,yy,srcx,srcy );
    				ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&buttony == 0&&buttonx == 0&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "%d",1);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&buttony == 0&&buttonx == 1&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "%d",2);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&buttony == 0&&buttonx == 2&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "%d",3);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&buttony == 1&&buttonx == 0&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "%d",4);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&buttony == 2&&buttonx == 0&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "%d",5);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			NUMBER[aa]='\0';
    			ran_before4 = 1;
    			}
    			if ( !key[KEY_ENTER]&&ran_before4 == 1 )
    			{
    				ran_before4 = 0;
    			}
    			
    			/*arrow_bb_left = xx;
    			arrow_bb_top = yy;
    			arrow_bb_bottom = ( arrow_bb_top + arrow->h );
    			arrow_bb_right = ( arrow_bb_left + arrow->w );
    			ALLO_bb_left = xxa;
    			ALLO_bb_top = yya;
    			ALLO_bb_right = ( ALLO_bb_left + ALLO->w );
    			ALLO_bb_bottom = ( ALLO_bb_top + ALLO->h );*/
    			sprintf (str, "%d,%d,%d",xx,yy,aa);
    			speed_counter--;
    		}
    		blit ( BG, buffer, 0,0,0,0,srcx,srcy );
    		masked_blit ( ALLO, buffer, 0,0,xx,yy,800,600 );
    		draw_button ( 400-64+xx,300-128+yy, 0, "2" );
    		draw_button ( 400-64+xx,300-54+yy, 0, "5" );
    		draw_button ( 400-64+xx,320+yy, 0, "8" );
    		draw_button ( 400-64+xx,394+yy, 0, "Settings" );
    		draw_button ( 400-202+xx,300-128+yy, 0, "1" );
    		draw_button ( 400-202+xx,300-54+yy, 0, "4" );
    		draw_button ( 400-202+xx,320+yy, 0, "7" );
    		draw_button ( 474+xx,300-128+yy, 0, "3" );
    		draw_button ( 474+xx,300-54+yy, 0, "6" );
    		draw_button ( 474+xx,320+yy, 0, "9" );
    		draw_button ( 474+xx,394+yy, 0, "0" );
    		draw_rectangle ( 200+xx,75+yy,600+xx,120+yy,0,0,0 );
    		if ( buttony == 0&&buttonx == 1 )
    		{
    			draw_button ( 400-64+xx,300-128+yy, 1, "2" );
    		}
    		if ( buttony == 1&&buttonx == 1 )
    		{
    			draw_button ( 400-64+xx,300-54+yy, 1, "5" );
    		}
    		if ( buttony == 2&&buttonx == 1 )
    		{
    			draw_button ( 400-64+xx,300+20+yy, 1, "8" );
    		}
    		if ( buttony == 3&&buttonx == 1 )
    		{
    			draw_button ( 400-64+xx,300+94+yy, 1, "Settings" );
    		}
    		if ( buttony == 0&&buttonx == 0 )
    		{
    			draw_button ( 400-202+xx,300-128+yy, 1, "1" );
    		}
    		if ( buttony == 1&&buttonx == 0 )
    		{
    			draw_button ( 400-202+xx,300-54+yy, 1, "4" );
    		}
    		if ( buttony == 2&&buttonx == 0 )
    		{
    			draw_button ( 400-202+xx,300+20+yy, 1, "7" );
    		}
    		if ( buttony == 0&&buttonx == 2 )
    		{
    			draw_button ( 474+xx,300-128+yy, 1, "3" );
    		}
    		if ( buttony == 1&&buttonx == 2 )
    		{
    			draw_button ( 474+xx,300-54+yy, 1, "6" );
    		}
    		if ( buttony == 2&&buttonx == 2 )
    		{
    			draw_button ( 400+74+xx,300+20+yy, 1, "9" );
    		}
    		if ( buttony == 3&&buttonx == 2 )
    		{
    			draw_button ( 474+xx,394+yy, 1, "0" );
    		}
    		textprintf_ex ( buffer, font,0 , 0, makecol ( 0,0,0 ), -1, str );
    		textprintf_ex ( buffer, font,xx+100 , yy+80, makecol ( 0,0,0 ), -1, NUMBER);
    		textprintf_ex ( buffer, font,200 , 200, makecol ( 0,0,0 ), -1, NUMBER1);
    		blit ( buffer, screen, 0,0,0,0,srcx,srcy );
    	}
    	destroy_bitmap ( ALLO );
    	destroy_bitmap ( BG );
    	destroy_bitmap ( arrow );
    	return 0;
    }
    why dose the down key not work after i press enter.

    thanks in advanced, sorry for the question i cant seem to figure it out myself, im still a noob.

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    I heard that allegro lags a lot even when it is programmed correctly? Is there any better C++ gaming libraries?
    ★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    That code is quite impenetrable, no matter what library you use. Massive amounts of magic values and a few variables of rather arbitrary types and obscure names.

    The only thing different about KEY_DOWN code is that it doesn't check the value of buttony.

    Of course, the question is what the hell it is supposed to do (some kind of menu with buttons?) because there must be a better way to do it without all the hard-coded stuff.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Omg... That's officially the longest function I've ever seen...
    Currently research OpenGL

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Akkernight View Post
    Omg... That's officially the longest function I've ever seen...
    Whilst it's certainly longer than it needs to be, it's actually only about 250 lines - nowhere near a record of what I've seen. I once worked in a file that was 12000 lines long, and it had three (roughly equal size, give or take a couple of hundred lines) functions in them - all part of the AMD specific optimisations of 3DMark99. Now, that's a some long functions.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Quote Originally Posted by matsp View Post
    Whilst it's certainly longer than it needs to be, it's actually only about 250 lines - nowhere near a record of what I've seen. I once worked in a file that was 12000 lines long, and it had three (roughly equal size, give or take a couple of hundred lines) functions in them - all part of the AMD specific optimisations of 3DMark99. Now, that's a some long functions.

    --
    Mats
    Well, I hope you left them the second you saw them? :P
    Currently research OpenGL

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Akkernight View Post
    Well, I hope you left them the second you saw them? :P
    No, it was my task to make them work with a new infrastructure that required some extra work to be done in some of the functions (and a new function introduced). Which I did successfully - there were some other problems with the infrastructure, so after some thinking, the whole concept of processor specific optimizations was removed from the new version of 3DMark. Nowadays, there's no point, as the graphics processor in the graphics card is MUCH faster than what the CPU can do.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Sep 2007
    Posts
    29
    deleted
    Last edited by IM back!; 11-20-2008 at 02:36 PM.

  9. #9
    Registered User
    Join Date
    Sep 2007
    Posts
    29
    The only thing different about KEY_DOWN code is that it doesn't check the value of buttony.
    its unessesary i removed it in the other ifs aswell.

    That code is quite impenetrable, no matter what library you use. Massive amounts of magic values and a few variables of rather arbitrary types and obscure names.
    im new to this so i dont know any better way to do things. im open to suggestions.

    some kind of menu with buttons?
    dead on

    Code:
    #include <allegro.h>
    #include <iostream>
    #include <sstream>
    #include <stdlib.h>
    using namespace std;
    void draw_rectangle ( int xx,int yy, int xxa, int yya, int colorr, int colorg, int colorb );
    int allgero ( int srcx, int srcy );
    int char_length ( char IT[100] );
    void settings ( BITMAP *BG,BITMAP *ALLO,int xx,int yy,int srcx,int srcy );
    void draw_button ( int xx,int yy, int selected, char button_text[50] );
    volatile long speed_counter = 0;
    volatile long logic_counter = 0;
    BITMAP *buffer = NULL;
    
    
    
    void increment_speed_counter() // A function to increment the speed counter
    {
    	speed_counter++; // This will just increment the speed counter by one.
    	logic_counter++;
    }
    
    int main ( int argc, char *argv[] )
    {
    	int aa;
    	cout<<"chosse res \n 1. 1680x1050\n 2. 1280x800\n 3. 1024x786\n 4. 800x600\n 5. Custom\n";
    	cin>>aa;
    	switch ( aa )
    	{
    		case 1:
    		{
    			allgero ( 1680,1050 );
    			break;
    		}
    		case 2:
    		{
    			allgero ( 1280,800 );
    			break;
    		}
    		case 3:
    		{
    			allgero ( 1024,786 );
    			break;
    		}
    		case 4:
    		{
    			allgero ( 800,600 );
    			break;
    		}
    	}
    	return 0;
    	exit ( 0 );
    }
    END_OF_MAIN();
    
    int allgero ( int srcx, int srcy )
    {
    
    	allegro_init();
    	install_keyboard();
    	install_timer()
    	LOCK_VARIABLE ( speed_counter );
    	LOCK_FUNCTION ( increment_speed_counter )
    	install_int_ex ( increment_speed_counter, BPS_TO_TIMER ( 70 ) );//Set beat's per second 60 works well, generally.
    	set_color_depth ( 32 );
    	set_gfx_mode ( GFX_AUTODETECT,srcx,srcy,0,0 );
    	BITMAP *BG = NULL;
    	BITMAP *ALLO = NULL;
    	BITMAP *arrow = NULL;
    	ALLO = load_bitmap ( "./allgero.bmp", NULL );
    	BG = load_bitmap ( "./back.bmp", NULL );
    	arrow = load_bitmap ( "./arrow.bmp", NULL );
    	buffer = create_bitmap ( srcx,srcy );
    	if ( BG == NULL )
    	{
    		set_gfx_mode ( GFX_TEXT,0,0,0,0 ); //Set the screen mode for allegro messages
    		allegro_message ( "Could not load back.bmp" );
    		exit ( EXIT_FAILURE );
    	}
    	if ( ALLO == NULL )
    	{
    		set_gfx_mode ( GFX_TEXT,0,0,0,0 ); //Set the screen mode for allegro messages
    		allegro_message ( "Could not load allgero.bmp" );
    		exit ( EXIT_FAILURE );
    	}
    	if ( arrow == NULL )
    	{
    		set_gfx_mode ( GFX_TEXT,0,0,0,0 ); //Set the screen mode for allegro messages
    		allegro_message ( "Could not load arrow.bmp" );
    		exit ( EXIT_FAILURE );
    	}
    	short ran_before1 = 0;
    	short ran_before  = 0;
    	short ran_before2 = 0;
    	short ran_before3 = 0;
    	short ran_before4 = 0;
    	int xx = srcx/2-400;
    	int yy = srcy/2-300;
    	long button = 0;
    	int aa = -1;
    	int buttonx = 1;
    	/*int arrow_bb_left = xx;
    	int arrow_bb_top = yy;
    	int arrow_bb_bottom = ( arrow_bb_top + arrow->h );
    	int arrow_bb_right = ( arrow_bb_left + arrow->w );
    	int ALLO_bb_left = xxa;
    	int ALLO_bb_top = yya;
    	int ALLO_bb_right = ( ALLO_bb_left + ALLO->w );
    	int ALLO_bb_bottom = ( ALLO_bb_top + ALLO->h );*/
    	//int show_bbox = FALSE;
    	//int collision = FALSE;
    	char str[50];
    	char NUMBER1[100]="0";
    	char NUMBER[100]="0 0 0 00 0 ";
    	while ( !key[KEY_ESC] )
    	{
    		while ( speed_counter > 0 )
    		{
    			//collision = FALSE;
    			//if ( arrow_bb_top < ALLO_bb_top||arrow_bb_bottom > ALLO_bb_bottom||arrow_bb_right > ALLO_bb_right||arrow_bb_left < ALLO_bb_left )
    			//{
    			//	collision = TRUE;
    			//}
    			if ( key[KEY_UP]&&ran_before == 0)
    			{
    				ran_before = 1;
    				button=button-1;
    			}
    			if ( !key[KEY_UP]&&ran_before == 1 )
    			{
    				ran_before = 0;
    			}
    			if ( key[KEY_DOWN]&&ran_before1 == 0)
    			{
    			cout<<"KEY_DOWN\n";
    					ran_before1 = 1;
    					button++;
    			}
    			if ( !key[KEY_DOWN]&&ran_before1 == 1 )
    			{
    			cout<<"!KEY_DOWN\n";
    				ran_before1 = 0;
    			}
    			if ( key[KEY_RIGHT]&&ran_before2 == 0)
    			{
    				buttonx++;
    				ran_before2 = 1;
    			}
    			if ( !key[KEY_RIGHT]&&ran_before2 == 1 )
    			{
    				ran_before2 = 0;
    			}
    			if ( key[KEY_LEFT]&&ran_before3 == 0 )
    			{
    				buttonx--;
    				ran_before3 = 1;
    			}
    			if ( !key[KEY_LEFT]&&ran_before3 == 1 )
    			{
    				ran_before3 = 0;
    			}
    			if ( key[KEY_W] )
    			{
    				yy--;
    			}
    			if ( key[KEY_A] )
    			{
    				xx--;
    			}
    			if ( key[KEY_S] )
    			{
    				yy++;
    			}
    			if ( key[KEY_D] )
    			{
    				xx++;
    			}
    			if ( key[KEY_R] )
    			{
    
    				xx = srcx/2-400;
    				yy = srcy/2-300;
    			}
    			if ( key[KEY_ENTER]&&button == 3&&buttonx == 1&&ran_before4 == 0 )
    			{
    				button = 0;
    				buttonx = 0;
    				settings ( BG,ALLO,xx,yy,srcx,srcy );
    				ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&button == 0&&buttonx == 0&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "&#37;d",1);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&button == 0&&buttonx == 1&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "%d",2);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&button == 0&&buttonx == 2&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "%d",3);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&button == 1&&buttonx == 0&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "%d",4);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			ran_before4 = 1;
    			}
    			if ( key[KEY_ENTER]&&button == 2&&buttonx == 0&&ran_before4 == 0 )
    			{
    			sprintf (NUMBER1, "%d",5);
    			NUMBER[aa]=NUMBER1[0];
    			aa++;
    			NUMBER[aa]='\0';
    			ran_before4 = 1;
    			}
    			if ( !key[KEY_ENTER]&&ran_before4 == 1 )
    			{
    				ran_before4 = 0;
    			}
    			
    			/*arrow_bb_left = xx;
    			arrow_bb_top = yy;
    			arrow_bb_bottom = ( arrow_bb_top + arrow->h );
    			arrow_bb_right = ( arrow_bb_left + arrow->w );
    			ALLO_bb_left = xxa;
    			ALLO_bb_top = yya;
    			ALLO_bb_right = ( ALLO_bb_left + ALLO->w );
    			ALLO_bb_bottom = ( ALLO_bb_top + ALLO->h );*/
    			sprintf (str, "%d,%d,%d",xx,yy,aa);
    			speed_counter--;
    		}
    		blit ( BG, buffer, 0,0,0,0,srcx,srcy );
    		masked_blit ( ALLO, buffer, 0,0,xx,yy,800,600 );
    		draw_button ( 400-64+xx,300-128+yy, 0, "2" );
    		draw_button ( 400-64+xx,300-54+yy, 0, "5" );
    		draw_button ( 400-64+xx,320+yy, 0, "8" );
    		draw_button ( 400-64+xx,394+yy, 0, "Settings" );
    		draw_button ( 400-202+xx,300-128+yy, 0, "1" );
    		draw_button ( 400-202+xx,300-54+yy, 0, "4" );
    		draw_button ( 400-202+xx,320+yy, 0, "7" );
    		draw_button ( 474+xx,300-128+yy, 0, "3" );
    		draw_button ( 474+xx,300-54+yy, 0, "6" );
    		draw_button ( 474+xx,320+yy, 0, "9" );
    		draw_button ( 474+xx,394+yy, 0, "0" );
    		draw_rectangle ( 200+xx,75+yy,600+xx,120+yy,0,0,0 );
    		if ( button == 0&&buttonx == 1 )
    		{
    			draw_button ( 400-64+xx,300-128+yy, 1, "2" );
    		}
    		if ( button == 1&&buttonx == 1 )
    		{
    			draw_button ( 400-64+xx,300-54+yy, 1, "5" );
    		}
    		if ( button == 2&&buttonx == 1 )
    		{
    			draw_button ( 400-64+xx,300+20+yy, 1, "8" );
    		}
    		if ( button == 3&&buttonx == 1 )
    		{
    			draw_button ( 400-64+xx,300+94+yy, 1, "Settings" );
    		}
    		if ( button == 0&&buttonx == 0 )
    		{
    			draw_button ( 400-202+xx,300-128+yy, 1, "1" );
    		}
    		if ( button == 1&&buttonx == 0 )
    		{
    			draw_button ( 400-202+xx,300-54+yy, 1, "4" );
    		}
    		if ( button == 2&&buttonx == 0 )
    		{
    			draw_button ( 400-202+xx,300+20+yy, 1, "7" );
    		}
    		if ( button == 0&&buttonx == 2 )
    		{
    			draw_button ( 474+xx,300-128+yy, 1, "3" );
    		}
    		if ( button == 1&&buttonx == 2 )
    		{
    			draw_button ( 474+xx,300-54+yy, 1, "6" );
    		}
    		if ( button == 2&&buttonx == 2 )
    		{
    			draw_button ( 400+74+xx,300+20+yy, 1, "9" );
    		}
    		if ( button == 3&&buttonx == 2 )
    		{
    			draw_button ( 474+xx,394+yy, 1, "0" );
    		}
    		textprintf_ex ( buffer, font,0 , 0, makecol ( 0,0,0 ), -1, str );
    		textprintf_ex ( buffer, font,xx+100 , yy+80, makecol ( 0,0,0 ), -1, NUMBER);
    		textprintf_ex ( buffer, font,200 , 200, makecol ( 0,0,0 ), -1, NUMBER1);
    		blit ( buffer, screen, 0,0,0,0,srcx,srcy );
    	}
    	destroy_bitmap ( ALLO );
    	destroy_bitmap ( BG );
    	destroy_bitmap ( arrow );
    	return 0;
    }
    
    void settings ( BITMAP *BG,BITMAP *ALLO,int xx,int yy,int srcx,int srcy )
    {
    	short ran_before1 = 0;
    	short ran_before  = 0;
    	int buttony = 0;
    	while ( !(key[KEY_ENTER]&&buttony == 2))
    	{
    		while ( speed_counter > 0 )
    		{
    			if ( key[KEY_UP]&&ran_before == 0&&buttony!=0 )
    			{
    				ran_before = 1;
    				buttony=buttony-1;
    			}
    			if ( !key[KEY_UP]&&ran_before == 1 )
    			{
    				ran_before = 0;
    			}
    			if ( key[KEY_DOWN]&&ran_before1 == 0 )
    			{
    				ran_before1 = 1;
    				buttony=buttony+1;
    			}
    			if ( !key[KEY_DOWN]&&ran_before1 == 1 )
    			{
    				ran_before1 = 0;
    			}
    			if ( key[KEY_W] )
    			{
    				yy--;
    			}
    			if ( key[KEY_A] )
    			{
    				xx--;
    			}
    			if ( key[KEY_S] )
    			{
    				yy++;
    			}
    			if ( key[KEY_D] )
    			{
    				xx++;
    			}
    			speed_counter--;
    		}
    		blit ( BG, buffer, 0,0,0,0,srcx,srcy );
    		masked_blit ( ALLO, buffer, 0,0,xx,yy,800,600 );
    		draw_button ( 400-64+xx,300-128+yy, 0, "button 1" );
    		draw_button ( 400-64+xx,300-54+yy, 0, "button 2" );
    		draw_button ( 400-64+xx,300+20+yy, 0, "Back" );
    		if ( buttony == 0)
    		{
    			draw_button ( 400-64+xx,300-128+yy, 1, "button 1" );
    		}
    		if ( buttony == 1)
    		{
    			draw_button ( 400-64+xx,300-54+yy, 1, "button 2" );
    		}
    		if ( buttony == 2)
    		{
    			draw_button ( 400-64+xx,300+20+yy, 1, "Back" );
    		}
    		blit ( buffer, screen, 0,0,0,0,srcx,srcy );
    	}
    }
    
    void draw_button ( int xx,int yy, int selected, char button_text[50] )
    {
    	textprintf_ex ( buffer, font,xx+64-char_length ( button_text ) *4 , yy+30, makecol ( 0,0,0 ), -1, button_text );
    	if ( selected == 1 )
    	{
    		draw_rectangle ( xx,yy,xx+128,yy+64,0,0,255 );
    		draw_rectangle ( xx-1,yy-1,xx+129,yy+65,0,0,255 );
    	}
    	else
    	{
    		draw_rectangle ( xx,yy,xx+128,yy+64,0,0,0 );
    	}
    }
    
    void draw_rectangle ( int xx,int yy, int xxa, int yya, int colorr, int colorg, int colorb )
    {
    	line ( buffer,xx,yy,xx,yya,makecol ( colorr,colorg,colorb ) );
    	line ( buffer,xxa,yya,xx,yya,makecol ( colorr,colorg,colorb )  );
    	line ( buffer,xxa,yy,xx,yy, makecol ( colorr,colorg,colorb )  );
    	line ( buffer,xxa,yya,xxa,yy,makecol ( colorr,colorg,colorb )  );
    }
    
    int char_length ( char IT[100] )
    {
    	int aa = 0;
    	while ( IT[aa]!='\0' )
    	{
    		aa++;
    	}
    	return aa;
    }
    Last edited by IM back!; 11-20-2008 at 02:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a very small problem, i'm new... please help?
    By Uberverse in forum C++ Programming
    Replies: 9
    Last Post: 11-10-2007, 10:44 AM
  2. Problem with Allegro Grabber
    By Nero_Martin in forum Game Programming
    Replies: 3
    Last Post: 09-26-2007, 11:19 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. Small program big problem :-(
    By Fibre Optic in forum C++ Programming
    Replies: 4
    Last Post: 09-20-2005, 09:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21