Mail Archives: djgpp/1997/03/14/15:33:35
I think that it would be easier and faster to use integers as a direction,
then for comparison you do not have to compare strings,here is a sample
program that I came up just now. I did not test it so I do not know if
that would work:
#include <allegro.h>
#define DIR_RIGHT 1
#define DIR_LEFT 2
void walk(int dir)
{
if (dir == DIR_RIGHT) {
if (frame_number == RIGHT_1) frame_number = RIGHT_2;
else frame_number = RIGHT_1;
}
else if (dir == DIR_LEFT) {
if (frame_number == LEFT_1) frame_number = LEFT_2;
else frame_number = LEFT_1;
}
draw_sprite((BITMAP*)data[frame_number].dat, screen, x_loc, y_loc);
}
main()
{
//do all your initialization and loading
...
while (1==1) {
if (key[KEY_RIGHT]) walk(DIR_RIGHT);
else if (key[KEY_LEFT]) walk(DIR_LEFT);
else if (key[KEY_ESC]) break;
}
}
On Fri, 14 Mar 1997, Deltaman wrote:
> Hi!
>
> I'm quite new to c programming and I have the following problem.
>
> In my main function I pass a string that contains a direction to
> the function 'walk(direction)'
> In this function I also give a value to 'int frame_number'
>
> The sprite is defined named like RIGHT_1, RIGHT_2, LEFT_1 and so on
>
> How can I use draw_sprite (in Allegro) to draw the right frame if
> I have the right direction and frame_number?
> ------------------------------------------------------------------------
> mailto:deltaman AT swipnet DOT se
>
> Please visit my homepage at http://www.geocities.com/TimesSquare/8240
> ------------------------------------------------------------------------
> ______ _______ _______ _______ _______ _______ __ _
> | \ |______ | | |_____| | | | |_____| | \ |
> |_____/ |______ |_____ | | | | | | | | | \_|
>
>
- Raw text -