Mail Archives: djgpp/1998/01/31/11:06:55
Matt Riker wrote:
> Woops, I said that wrong. Here is my variable declaration:
> char spritename[20] = "BLANK";
> That's valid, right?
That's a valid C initializer, but you're heading in the wrong direction
about using it with an Allegro datafile.
> The header and stuff's all taken care of with Grabber, and I've checked
> just to verify. BLANK is declared in my datafile, as a BMP.
[snip]
> Except that I don't want the function to always draw BLANK to the
> screen. I want to use my variable, spritename, because the sprite I
> want drawn is depending on which sprite the user chooses in my program.
When BLANK is defined in the header file, it is associating the work
BLANK with some number. Let's say the number happens to be 2:
#define IMAGE0 0
#define IMAGE1 1
#define BLANK 2
This gives BLANK the value of 2.
In draw_sprite(), you use BLANK like this:
draw_sprite(screen,datafile[BLANK].dat,0,0);
So far we're in agreement, right? If so, follow on..
The above is the same as:
draw_sprite(screen,datafile[2].dat,0,0);
The following code fragment demonstrates how to draw the user-selected
sprite:
int SpriteNumber;
int ContinueLoop;
while (ContinueLoop)
{
SpriteNumber = GetSpriteNumberFromWherever();
draw_sprite(screen,datafile[SpriteNumber].dat,Xcor,Ycor);
ContinueLoop = AskUserToContinueLoop();
}
--
Tony O'Bryan
http://www.geocities.com/SiliconValley/Park/7201
- Raw text -