Alexander said:
You may wish to review some of the basic C functions, such as printf to utilize some of allegros functioning.
In C, you can define tokens, and then arbitrarily list them afterwards in an variable parameter list:
printf("%c %i %f", 0x65, 12, 3.1415);
You will need to use Allegro's version of this function to print to the screen (adjust as required):
[FONT=courier new]// x, y on screen
textprintf(buffer, font, 0, 0, makecol(255, 255, 255),"x = %i, %y = %i", x, y);[/FONT]
I played around with it and inserted it to one of my games. But I don't know if the clear bitmap or the rest is messing it up or probably the whole while loop.
Here is where i placed it.
masked_blit ( walking, buffer, ImageX, ImageY, x, y, 32, 32);
blit ( buffer, screen , 0, 0, 0, 0, 640, 480 );
rest(60);
textprintf(cordinates, font, 0, 10 , makecol(255, 255, 255), "x = %ix , y= %iy ", ix, iy);
blit(cordinates, screen,0, 0, 0, 0, 640, 480 );
clear_bitmap(buffer);
}
destroy_bitmap(background);
destroy_bitmap(buffer);
destroy_bitmap(walking);
destroy_bitmap(cordinates);
return 0;
This is the whole thing
#define down 0 // These define fuctions will later be used with [ ImageY] Do not confuse it
#define left 32
#define right 64
#define up 96
#include <Allegro.h>
//#include <sstream>
//#include <string>
//#include <cstring>
//using namespace std;
int main ()
{
allegro_init();
install_keyboard();
install_mouse();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640 , 480 , 0 , 0) ;
FONT * font1 = load_font ("Virtualdj font for allegro.pcx", NULL, NULL);
set_window_title("Vairon's game");
BITMAP * buffer = create_bitmap (640 , 480);
BITMAP* background = load_bitmap ("background.bmp", NULL );
BITMAP * walking = load_bitmap ("Character.bmp", NULL );
BITMAP * cordinates = create_bitmap( 640 , 480);
bool done = false; // bool is just a loop which expresses if something is true or false
int x,y, ImageX, ImageY;
x = 320, y = 400 , ImageX = 32 , ImageY = down;
int ix, iy;
while (done == false) {
if (key[KEY_ESC])
done = true;
if (key[KEY_RIGHT]){
ImageY = right;
x +=5;
}
else if (key[KEY_LEFT]){
ImageY= left;
x -= 5;
}
if (key[KEY_DOWN]){
ImageY = down;
y += 5;
}
else if (key[KEY_UP]){
ImageY=up;
y -= 5;
}
if (!key[KEY_UP] && !key[KEY_DOWN] && !key[KEY_RIGHT] && !key[KEY_LEFT])
ImageX = 32;
else
ImageX += 32; // or Imagex = ImageX + 32;
if (ImageX > 64) // Value not avaliable in the image / will be out of screen
ImageX = 0;
if (x >= 610)
x = 610;
if(x <=1 )
x= 1;
if ( y >= 450)
y = 450;
if ( y <= 1)
y=1;
ix = x;
iy = y;
///////////
// blit (background , buffer , 0 , 0, 0, 0, 640, 480 );
masked_blit ( walking, buffer, ImageX, ImageY, x, y, 32, 32);
blit ( buffer, screen , 0, 0, 0, 0, 640, 480 );
rest(60);
textprintf(cordinates, font, 0, 10 , makecol(255, 255, 255), "x = %ix , y= %iy ", ix, iy);
blit(cordinates, screen,0, 0, 0, 0, 640, 480 );
clear_bitmap(buffer);
}
destroy_bitmap(background);
destroy_bitmap(buffer);
destroy_bitmap(walking);
destroy_bitmap(cordinates);
return 0;
}
END_OF_MAIN()