Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8602812
  • 博文数量: 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:35:18

 

//显示固定的文字

//先在黑色背景显示文字

//后类rpg一样显示图形及文字

//注意技巧:一是缓冲贴图,这样可以杜绝闪屏,二是半透明贴图,显示文字

#i nclude <allegro.h>
#i nclude <stdio.h>
FILE *f;
BITMAP *bmpBk;
BITMAP *bmpSprite1;
BITMAP *bmpSprite2;
BITMAP *bmpBuffer;
BITMAP *bmpTBk;
BITMAP *bmpSeban;
BITMAP *bmpPress;
void init();
void deinit();
void dispText();
void loadFile();
void dispMessage();

int main() {
 init();

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

 deinit();
 return 0;
}
END_OF_MAIN()

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

 install_timer();
 install_keyboard();
 install_mouse();
 /* add other initializations here */
 loadFile();
 clear_to_color(screen,makecol(0,0,0));
 dispText();
 dispMessage();
 
}

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

void loadFile()
{
 f=fopen("txt/talk.txt","r");
 if(f==NULL)
 {
  allegro_message("open talk.txt error!");
 }
 bmpBk=load_bmp("img/bk.bmp",NULL);
 bmpSprite1=load_bmp("img/s1.bmp",NULL);
 bmpSprite2=load_bmp("img/s2.bmp",NULL);
 bmpBuffer=create_bitmap(SCREEN_W,SCREEN_H);
 bmpTBk=load_bmp("img/tbk.bmp",NULL);
 bmpSeban=create_bitmap(500,130);
 bmpPress=load_bmp("img/press.bmp",NULL);
 
}

void dispText()
{
 textout_centre_ex(screen,font,"love make the world go around",SCREEN_W/2,SCREEN_H/2,makecol(255,255,255),-1);
 readkey();
 clear_to_color(screen,makecol(0,0,0));
 textout_centre_ex(screen,font,"Life is a Game,Game is My Life",SCREEN_W/2,SCREEN_H/2,makecol(255,255,255),-1);
 readkey();
 clear_to_color(screen,makecol(0,0,0));
 textout_centre_ex(screen,font,"I want change the world,and the world will be change because of me",SCREEN_W/2,SCREEN_H/2,makecol(255,255,255),-1);
 readkey();
  
}

void dispMessage()
{
 //清屏

 clear_to_color(screen,makecol(0,0,0));
 //贴背景,缩放贴图

 stretch_blit(bmpBk,bmpBuffer,0,0,bmpBk->w,bmpBk->h,0,0,SCREEN_W,SCREEN_H);
 //贴角色

 masked_blit(bmpSprite1,bmpBuffer,0,0,5,300,bmpSprite1->w,bmpSprite1->h);
 //半透明处理

 set_trans_blender(0,0,180,180);
 draw_trans_sprite(bmpBuffer,bmpTBk,125,335);
 textout_ex(bmpBuffer,font,"I want beat you,please use you kungfu!",130,340,makecol(255,255,255),-1);
 masked_blit(bmpPress,bmpBuffer,0,0,580,420,bmpPress->w,bmpPress->h);
 blit(bmpBuffer,screen,0,0,0,0,bmpBuffer->w,bmpBuffer->h);
 readkey();
 stretch_blit(bmpBk,bmpBuffer,0,0,bmpBk->w,bmpBk->h,0,0,SCREEN_W,SCREEN_H);
 masked_blit(bmpSprite2,bmpBuffer,0,0,5,300,bmpSprite2->w,bmpSprite2->h);
 rectfill(bmpSeban,0,0,500,130,makecol(0,0,255));
 set_trans_blender(0,0,0,180);
 draw_trans_sprite(bmpBuffer,bmpSeban,125,335);
 textout_ex(bmpBuffer,font,"No problem,Buf I want tell you,I don't want to beat you",130,340,makecol(255,255,255),-1);
 masked_blit(bmpPress,bmpBuffer,0,0,580,420,bmpPress->w,bmpPress->h);
 blit(bmpBuffer,screen,0,0,0,0,bmpBuffer->w,bmpBuffer->h);
 readkey();
 stretch_blit(bmpBk,bmpBuffer,0,0,bmpBk->w,bmpBk->h,0,0,SCREEN_W,SCREEN_H);
 masked_blit(bmpSprite1,bmpBuffer,0,0,5,300,bmpSprite1->w,bmpSprite1->h);
 set_trans_blender(0,0,180,180);
 draw_trans_sprite(bmpBuffer,bmpTBk,125,335);
 textout_ex(bmpBuffer,font,"why? are you love me very much,if you think so ,I love you/",130,340,makecol(255,255,255),-1);
 masked_blit(bmpPress,bmpBuffer,0,0,580,420,bmpPress->w,bmpPress->h);
 blit(bmpBuffer,screen,0,0,0,0,bmpBuffer->w,bmpBuffer->h);
 readkey();
}

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