Author: ProSergeant. Date 2014-07-30 19:25:28, views: 1197, Raw
#ifndef IMAGE_H #define IMAGE_H SDL_Surface *screen; SDL_Surface *space; SDL_Surface *space_2; SDL_Surface *player_up, *player_rt, *player_dn, *player_lt, *player; SDL_Surface *ship_up, *ship_rt, *ship_dn, *ship_lt; SDL_Surface *ship_2; SDL_Surface *planet_1; SDL_Surface *planet_2; SDL_Surface *sputnik_1; SDL_Surface *sputnik_2; SDL_Surface *arrow_up, *arrow_rt, *arrow_dn, *arrow_lt; SDL_Surface *menu, *inv, *battle; SDL_Surface *p_beam, *e_beam; SDL_Surface *boom_1,*boom_2,*boom_3,*boom_4,*boom_5,*boom_6,*boom_7,*boom_8,*boom_9,*boom_10,*p_rocket; //загрузка картинок SDL_Surface *load_image( std::string filename ) { //The image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image loadedImage = IMG_Load( filename.c_str() ); //If the image loaded if( loadedImage != NULL ) { //Create an optimized image optimizedImage = SDL_DisplayFormatAlpha( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); } //Return the optimized image return optimizedImage; } //проÑто нариÑовать картинку void img_draw ( SDL_Surface *img, int x, int y ) { SDL_Rect dest; dest.x = x; dest.y = y; SDL_BlitSurface ( img, NULL, screen, &dest ); } //риÑует закрашенный прÑмоугольник void img_rect ( int x, int y, int w, int h, Uint8 R = 255, Uint8 G = 255, Uint8 B = 255 ) { Uint32 color = SDL_MapRGB ( screen->format, R, G, B ); SDL_Rect dest; dest.x = x; dest.y = y; dest.w = w; dest.h = h; SDL_FillRect ( screen, &dest, color ); } //риÑует (или печатает) текÑÑ‚ на Ñкране - ÑÐ°Ð¼Ð°Ñ Ñ‚Ð¾Ñ€Ð¼Ð¾Ð·ÑÑ‰Ð°Ñ Ñ„ÑƒÐ½ÐºÑ†Ð¸Ñ Ð² игре, //но разрабатывать еще и Ñвои шрифты откровенно лень void img_text ( char message[200], int size, int x, int y, Uint8 R = 0, Uint8 G = 0, Uint8 B = 0 ) { SDL_Color color = {R, G, B, 0}; SDL_Rect dest; dest.x = x; dest.y = y; //Ñ Ñ‚Ñ€ÑƒÐ´Ð¾Ð¼ добытый шрифт, чтобы кириллица работала TTF_Font *fnt = TTF_OpenFont ( "un1251n.ttf", size ); SDL_Surface *sText = TTF_RenderText_Blended ( fnt, message, color ); SDL_BlitSurface ( sText, NULL, screen, &dest ); SDL_FreeSurface ( sText ); TTF_CloseFont ( fnt ); } #endif