Message-Id: <199801130831.QAA11712@ultra140> Date: Mon, 13 Jan 1997 16:29:15 +0800 From: Wang Jingtao Reply-To: jtwang AT ultra140 DOT xjtu DOT edu DOT cn To: "jdkris AT NOPOOPalpha DOT delta DOT edu" Cc: "djgpp AT delorie DOT com" Subject: Re: Sprite help... Organization: Artificial Intelligence & Robortics Institute of XJTU Mime-Version: 1.0 Content-Type: text/plain; charset="GB2312" Content-Transfer-Encoding: 7bit Precedence: bulk >Howdy.... >Could someone out there help me out and convert this code so that it uses >Allegro and load a 10x10 bitmap from a file. Right now it defines all of >its own functions and doesn't load the bitmap from a file. Thanks alot. Don't be too lazy :-) , Allegro is very easy to learn. please check all the examples in allegro\examples directory. After rewritten your program much smaller. The best teacher you can get is yourself. >#define GRAPHICS 0x013 >#define TEXT 0x03 >char *video_buffer = (char *)0xa0000; Here it is : Use "gcc -s -o foo.exe foo.c -lalleg" to compile. --------------------------------------------------------------------------------- #include #include #include typedef struct sprite_type { unsigned x, y; /* location */ unsigned x_vel, y_vel; /* velocity */ char width, height; /* dimensions */ char num_frames; /* number of frames */ char cur_frame; /* current frame */ BITMAP *background, **frame; } SPRITE; void draw_my_sprite(SPRITE * s) { s->x += s->x_vel; s->y += s->y_vel; blit(screen,s->background,s->x,s->y,0,0,s->width,s->height); blit(s->frame[s->cur_frame],screen,0,0,s->x,s->y,s->width,s->height); } void erase_my_sprite(SPRITE * s) { blit(s->background,screen,0,0,s->x,s->y,s->width,s->height); } void create_cross_sprite(char * filename) { BITMAP *cross; RGB pal[256]; cross = create_bitmap(10,10); get_palette(pal); clear(cross); line(cross,0,0,9,9,15); line(cross,9,0,0,9,15); rect(cross,0,0,9,9,15); save_bitmap(filename,cross,pal); destroy_bitmap(cross); } int main(void) { unsigned count,i; RGB pal[256]; SPRITE sprite; char *filename="sprite.bmp"; allegro_init(); install_keyboard(); create_cross_sprite(filename); set_gfx_mode(GFX_VGA, 320, 200, 0, 0); set_pallete(pal); sprite.x = 160; sprite.y = 100; sprite.x_vel = 1; sprite.y_vel = 1; sprite.width = 10; sprite.height = 10; sprite.num_frames = 1; sprite.cur_frame = 0; sprite.background = create_bitmap(sprite.width,sprite.height); sprite.frame = (BITMAP **)malloc(sizeof(BITMAP *) * sprite.num_frames); sprite.frame[0] = load_bitmap(filename,pal); set_palette(pal); for (count = 0; count < 32000; count++) { putpixel(screen,rand() % 320, rand() % 200, rand() % 256); } while(! keypressed()) { if ( (sprite.x > 309) || (sprite.x < 1)) sprite.x_vel = -sprite.x_vel; if((sprite.y > 189) || (sprite.y < 1)) sprite.y_vel = -sprite.y_vel; draw_my_sprite(&sprite); delay(10); erase_my_sprite(&sprite); } for (i= 0; i< sprite.num_frames; i++) destroy_bitmap(sprite.frame[i]); destroy_bitmap(sprite.background); free((void *)sprite.frame); exit(0); } Regards Wang Jingtao Xi'an Jiaotong University P.R. China