Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Allegro - Printing X & Y coordinates to the screen

printing

  • Please log in to reply
5 replies to this topic

#1 vaironl

vaironl

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 138 posts
  • Programming Language:Java
  • Learning:Java, Objective-C, Python, JavaScript

Posted 12 August 2011 - 09:05 AM

Hello forum, right now I'm challenging myself to make a good allegro basic circle movement without any tutorials .
So there is one thing that I want to implement into my code and that is, printing the x and y coordinates to the screen. For multiple purposes .

I tried the textout but I really don't know how to make the program print the variable , here is what I tried.



textout(buffer, font, "this is x" << x , "this is y" << y , 0, 0, makecol(0, 250, 30) , -1);

  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 12 August 2011 - 05:05 PM

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]

  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#3 vaironl

vaironl

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 138 posts
  • Programming Language:Java
  • Learning:Java, Objective-C, Python, JavaScript

Posted 15 August 2011 - 02:59 PM

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]


Allright ill search online tutorials
  • 0

#4 vaironl

vaironl

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 138 posts
  • Programming Language:Java
  • Learning:Java, Objective-C, Python, JavaScript

Posted 16 August 2011 - 09:19 AM

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()

  • 0

#5 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 16 August 2011 - 05:10 PM

You appear to be placing ix and iy as arguments, they must be valid variables.

%i will be replaced with an integer, so, "x = %i, y = %i", x, y will do what you want.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#6 vaironl

vaironl

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 138 posts
  • Programming Language:Java
  • Learning:Java, Objective-C, Python, JavaScript

Posted 16 August 2011 - 05:12 PM

You appear to be placing ix and iy as arguments, they must be valid variables.

%i will be replaced with an integer, so, "x = %i, y = %i", x, y will do what you want.


I'm sorry for the lack of explanation. is basically flashing and I can't see it well.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download