Advertisement

Some Allegro Questions

Started by August 12, 2004 07:26 PM
5 comments, last by hellz 20 years, 6 months ago
Hey guys, Finally had a chance to play around with Allegro, and I've made quite a lot of progress, but I have a few things which are proving awkward. 1. I'm in the middle of making a Pong clone and I'm setting up the batons (paddles, whatever you want to call them), to be 10 pixels from the edge of each side of the screen. So player 1 would be 10 pixels in from the left edge of the screen, and player 2, would be 10 pixels in from the right. Here's my CBaton class:

#pragma warning(disable : 4312)

#ifndef BATON_H
#define BATON_H

#include <allegro.h>

class CBaton
{
private:
	int m_x;          // x coord.
	int m_y;          // y coord.
	int m_width;      // Baton width.
	int m_height;     // Baton height.
	int m_colour;     // Baton colour.
	int m_batonSpeed; // Speed at which the baton will move.

public:
	// Constructor.
	CBaton(const int ALIGNMENT, int colour);

	// Constants to aid drawing different batons.
	static const int ALIGN_BATON_LEFT = 10;
	static const int ALIGN_BATON_RIGHT = SCREEN_W - 10;

	// Draw the baton to the target bitmap.  In this case,
	// the background.
	void Draw(BITMAP *bmp);

	// Method to move the baton.
	void Move();
};

#endif



I'm having a problem with the ALIGN_BATON_RIGHT constant. It draws player 2's baton about 5 pixels away from player 1's, which seems to make no sense at all, so they're both on the left edge of the screen. Any ideas what the problem here is? You'll see why I'm having trouble debugging it from my next question. 2. I can't seem to debug the application in the debugger. As soon as it goes fullscreen, if it hits a breakpoint, I can't alt+tab to the debugger without everything going nuts, which is making life incredibly awkward. Anyone know how I can successfully debug the application? 3. This one's not as important, but still a little annoying. 23yrold3yrold gave me a sweet tip to disable compiler warnings that I get with Allegro. It works great, except that I have to put the line in every single header file in the project. Is there a work-around to that? Here's the line, just for reference:

#pragma warning(disable : 4312)



Any help would be gratefully received. [smile] -hellz
Quote:
Original post by hellz
Hey guys,

Finally had a chance to play around with Allegro, and I've made quite a lot of progress, but I have a few things which are proving awkward.

1. I'm in the middle of making a Pong clone and I'm setting up the batons (paddles, whatever you want to call them), to be 10 pixels from the edge of each side of the screen. So player 1 would be 10 pixels in from the left edge of the screen, and player 2, would be 10 pixels in from the right.

Here's my CBaton class:

*** Source Snippet Removed ***

I'm having a problem with the ALIGN_BATON_RIGHT constant. It draws player 2's baton about 5 pixels away from player 1's, which seems to make no sense at all, so they're both on the left edge of the screen.

Cool; the site inserts "*** Source Snippet Removed ***". 1337. [cool]

SCREEN_W means nothing until the screen width is established by calling set_gfx_mode(). I'm guessing that's your problem there.

Can't help with #2, but for #3 I'm guessing your IDE has a menu option available. Or you can just live with warning errors. [wink]

[Edited by - 23yrold3yrold on August 12, 2004 8:54:34 PM]

Jesus saves ... the rest of you take 2d4 fire damage.

Advertisement
#2
Use dual monitor, or run your game in windowed.

#3
Put that line in the precompiled header file (if you are using one that is).
1] The defines are:

#define SCREEN_W (gfx_driver ? gfx_driver->w : 0)
#define SCREEN_H (gfx_driver ? gfx_driver->h : 0)

You'll have to make sure your class is created after the graphics mode has been set.

2] You'll have to run in Windowed mode. Depending on what you are debugging, sometimes it's just as easy to use the built in TRACE() debugging macro to log to a file - or to output variables to the screen temporarily.

3] You should be able to add that line to <allegro.h> to suppress all the warnings.
Thanks alot guys! That explains the SCREEN_W problem. I was trying to initialise the constants at compile-time, so I guess I'll have to use another way.

For #2, does this debugging problem occur when running fullscreen if you're using other graphics libraries, or is it simply because Allegro seems to handle the wndproc itself? As in, if I handled alt+tab for an app. written with DirectX, would the problem be the same?

Thanks for the tip about precompiled headers, too. I'm not using them, so adding the warning to the allegro.h file seems best. I'll try that. [smile]

Cheers dudes!

-hellz
Quote:
Original post by hellz
For #2, does this debugging problem occur when running fullscreen if you're using other graphics libraries, or is it simply because Allegro seems to handle the wndproc itself? As in, if I handled alt+tab for an app. written with DirectX, would the problem be the same?

Yes, the same thing applies in DirectX. When a program is running fullscreen, it's put on the topmost by the operating system. When something happens (like an exception or pointer-related error), the program is halted; but since the program is on the topmost, we couldn't bring the other program to the top.
Advertisement
Thanks for the info, alnite. Sorry for taking so long to reply, had to dart off this weekend. Is there another way to debug fullscreen programs then, or is it simply a case of using TRACE statements or logging to a file?

The debugger feels too valuable not to be able to use it for programs like these.

Thanks again,

-hellz

This topic is closed to new replies.

Advertisement