void Menu::draw_menu(SDL_Surface *dest_surf) { SDL_Rect menu_src, menu_dest; menu_src.x = 0; menu_src.w = W; menu_src.h = H; if(Sel) menu_src.y = 25; else menu_src.y = 0; menu_dest.x = X; menu_dest.y = Y; menu_dest.w = W; menu_dest.h = H; SDL_BlitSurface(Surf, &menu_src, dest_surf, &menu_dest); if (!TTF_WasInit()){ printf("Truetype font engine has not been initialized!\n"); exit(1); } SDL_BlitText(Name, dest_surf, X, Y + 5, Font, *Color); }
void Map::draw_map (SDL_Surface * dest_surf, Role & player, SDL_Surface *assist_surf) { static int flash = 1; int i, j; int TileNum; SDL_Rect map_src, map_dest, assist_src; //画地图元素 for(i=0;i<10;i++) { for(j=0;j<15;j++) { TileNum = Tile[i][j]; if (TileNum <40||count_in_row==15) { map_src.x = (TileNum % count_in_row)*32; map_src.y = (TileNum/count_in_row)*32; } else { map_src.x = (TileNum % count_in_row)*32+128; map_src.y = (TileNum/count_in_row)*32-320; } map_src.w = 32; map_src.h = 32; #ifdef PSP map_dest.x = j*32; map_dest.y = i*27; map_dest.w = 32; map_dest.h = 27; #else map_dest.x = j*32; map_dest.y = i*32; map_dest.w = 32; map_dest.h = 32; #endif SDL_BlitSurface(Surf, &map_src, dest_surf, &map_dest); //画场景切换点 if (Trap[i][j]&& Trap[i][j]<100) { //SetRect(&Rect_map_dest, j*32, i*32, (j+1)*32, (i+1)*32); if (flash > 0) { assist_src.x = 1; } else { assist_src.x = 36; } assist_src.y = 176; assist_src.w = 35; assist_src.h = 35; SDL_BlitSurface(assist_surf, &assist_src, dest_surf, &map_dest); } } } //画Npc if (Npc) { Role *temp; temp = Npc; while(temp && (temp->Y < player.Y)) { temp->draw_self(dest_surf); temp = temp->R; } player.draw_self(dest_surf); while (temp) { temp->draw_self(dest_surf); temp = temp->R; } } else { player.draw_self(dest_surf); } if (!TTF_WasInit()){ printf("Truetype font engine has not been initialized!\n"); exit(1); } SDL_BlitText(Name, dest_surf, SCR_W/2-8, 8, Font, *Color); //更新Flash flash = -flash; }
void Fighter::draw_self(short n, SDL_Surface *dest_surf, int ex, int ey,short eAttack) { SDL_Rect fighter_src, fighter_dest; SDL_Color color; char damage[20]; if (bAttack) { switch(n) { case 0: case 5: fighter_src.x = 0; fighter_src.y = Index * 85; fighter_src.w = 60; fighter_src.h = 85; fighter_dest.x = X; fighter_dest.y = Y - Height; fighter_dest.w = Width; fighter_dest.h = Height; SDL_BlitSurface(Surf, &fighter_src, dest_surf, &fighter_dest); break; case 1: fighter_src.x = 0; fighter_src.y = Index * 85; fighter_src.w = 60; fighter_src.h = 85; if(Left) fighter_dest.x = ex - Width; else fighter_dest.x = ex + Width; fighter_dest.y = Y - Height; fighter_dest.w = Width; fighter_dest.h = Height; SDL_BlitSurface(Surf, &fighter_src, dest_surf, &fighter_dest); break; case 2: fighter_src.x = 61; fighter_src.y = Index * 85; fighter_src.w = 60; fighter_src.h = 85; if(Left) fighter_dest.x = ex - Width/2; else fighter_dest.x = ex + Width/2; fighter_dest.y = Y - Height; fighter_dest.w = Width; fighter_dest.h = Height; SDL_BlitSurface(Surf, &fighter_src, dest_surf, &fighter_dest); break; case 3: case 4: fighter_src.x = 121; fighter_src.y = Index * 85; fighter_src.w = 60; fighter_src.h = 85; if(Left) fighter_dest.x = ex - Width/2; else fighter_dest.x = ex + Width/2; fighter_dest.y = Y - Height; fighter_dest.w = Width; fighter_dest.h = Height; SDL_BlitSurface(Surf, &fighter_src, dest_surf, &fighter_dest); break; } } else { fighter_src.x = 0; fighter_src.y = Index*85; fighter_src.w = 60; fighter_src.h = 85; fighter_dest.y = Y - Height; fighter_dest.w = Width; fighter_dest.h = Height; sprintf(damage, "-%d", get_damage(eAttack)); switch(n) { case 0: case 1: case 2: case 3: fighter_dest.x = X; fighter_dest.y = Y - Height; fighter_dest.w = Width; fighter_dest.h = Height; SDL_BlitSurface(Surf, &fighter_src, dest_surf, &fighter_dest); break; case 4: if (Left) fighter_dest.x = X - 20; else fighter_dest.x = X + 20; SDL_BlitSurface(Surf, &fighter_src, dest_surf, &fighter_dest); color.r = 255; color.g = 255; color.b = 0; SDL_BlitText(damage, dest_surf, X+Width/2, Y - Height, Font, color); break; case 5: fighter_dest.x = X; SDL_BlitSurface(Surf, &fighter_src, dest_surf, &fighter_dest); color.r = 255; color.g = 255; color.b = 150; SDL_BlitText(damage, dest_surf, X+Width/2, Y - Height -20, Font, color); break; } } }