Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8299215
  • 博文数量: 1413
  • 博客积分: 11128
  • 博客等级: 上将
  • 技术积分: 14685
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 10:03
个人简介

follow my heart...

文章分类

全部博文(1413)

文章存档

2013年(1)

2012年(5)

2011年(45)

2010年(176)

2009年(148)

2008年(190)

2007年(293)

2006年(555)

分类: C/C++

2006-11-24 22:37:11

//将同一副图显示为动画,例如一副图,其中包含人物的一个动作的一连续的图,
//这里将其按照延迟来显示为动作.

#i nclude <allegro.h>
int x,y;
BITMAP *sprite;

void init();
void deinit();
void list();

int main() {
 init();

 while (!key[KEY_ESC]) {
  /* put your code here */
 }

 deinit();
 return 0;
}
END_OF_MAIN()

void init() {
 int depth, res;
 x=0;
 y=0;
 allegro_init();
 depth = desktop_color_depth();
 if (depth == 0) depth = 32;
 set_color_depth(depth);
 res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
 if (res != 0) {
  allegro_message(allegro_error);
  exit(-1);
 }

 install_timer();
 install_keyboard();
 install_mouse();
 /* add other initializations here */
 //加载图片

 sprite=load_bmp("002.bmp",NULL);
 if(!sprite)
 {
  allegro_message("load 002.bmp error!");
 }
 do
 {
  list();
 }
 while(!keypressed());//直到任意键按下

 
}

void deinit() {
 clear_keybuf();
 /* add other deinitializations here */
}

void list()
{
 clear_to_color(screen,makecol(0,0,0));//将屏幕清除为指定色彩

 masked_blit(sprite,screen,x,y,100,100,32,48);//遮罩显示位图,X,Y为源位图的坐标值

 //这副图的宽为128,高为192,各分成4份,则每一份为32*48

 x+=32;
 if(x==128)
 {
  y+=48;
  x=0;
  if(y==192)
  {
   y=0;
  }
 }
 rest(100);
}


阅读(2514) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-09-24 11:44:21

推荐:allegro高手坐堂! www.eda365.com