//显示固定的文字
//先在黑色背景显示文字
//后类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(); }
|