当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_SetColorKey函数代码示例

本文整理汇总了C++中SDL_SetColorKey函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_SetColorKey函数的具体用法?C++ SDL_SetColorKey怎么用?C++ SDL_SetColorKey使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_SetColorKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getline

//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
    lastchar = -1;
    inputdelay = -1;

    std::string typeface = "Terminus";
    std::string blending = "solid";
    std::ifstream fin;
    int faceIndex = 0;
    int fontsize = 0; //actuall size
    fin.open("data/FONTDATA");
    if (!fin.is_open()){
        fontwidth = 8;
        fontheight = 16;
        std::ofstream fout;//create data/FONDATA file
        fout.open("data/FONTDATA");
        if(fout.is_open()) {
            fout << typeface << "\n";
            fout << fontwidth << "\n";
            fout << fontheight;
            fout.close();
        }
    } else {
        getline(fin, typeface);
        fin >> fontwidth;
        fin >> fontheight;
        fin >> fontsize;
        fin >> blending;
        if ((fontwidth <= 4) || (fontheight <= 4)) {
            fontheight = 16;
            fontwidth = 8;
        }
        fin.close();
    }

    fontblending = (blending=="blended");

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;

    if(!InitSDL()) {
        DebugLog() << (std::string)"Failed to initialize SDL!\n";
    }

    #ifdef SDLTILES
    DebugLog() << "Initializing SDL Tiles context\n";
    tilecontext = new cata_tiles;
    tilecontext->init("gfx");
    #endif // SDLTILES
    DebugLog() << (std::string)"Tiles initialized successfully.\n";
    WindowWidth= OPTIONS["TERMINAL_X"];
    if (WindowWidth < FULL_SCREEN_WIDTH) WindowWidth = FULL_SCREEN_WIDTH;
    WindowWidth *= fontwidth;
    WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight;
    if(!WinCreate()) {
        DebugLog() << (std::string)"Failed to create game window!\n";
        return NULL;
    }
    #ifdef SDLTILES
    tilecontext->set_screen(screen);

    while(!strcasecmp(typeface.substr(typeface.length()-4).c_str(),".bmp") ||
          !strcasecmp(typeface.substr(typeface.length()-4).c_str(),".png")) {
        SDL_Surface *asciiload;
        typeface = "data/font/" + typeface;
        asciiload = IMG_Load(typeface.c_str());
        if(!asciiload || asciiload->w*asciiload->h < (fontwidth * fontheight * 256)) {
            SDL_FreeSurface(asciiload);
            break;
        }
        Uint32 key = SDL_MapRGB(asciiload->format, 0xFF, 0, 0xFF);
        SDL_SetColorKey(asciiload,SDL_SRCCOLORKEY,key);
        ascii[0] = SDL_DisplayFormat(asciiload);
        SDL_FreeSurface(asciiload);
        for(int a = 1; a < 16; a++) {
            ascii[a]=SDL_ConvertSurface(ascii[0],ascii[0]->format,ascii[0]->flags);
        }

        init_colors();
        for(int a = 0; a < 15; a++) {
            SDL_LockSurface(ascii[a]);
            int size = ascii[a]->h * ascii[a]->w;
            Uint32 *pixels = (Uint32 *)ascii[a]->pixels;
            Uint32 color = (windowsPalette[a].r << 16) | (windowsPalette[a].g << 8) | windowsPalette[a].b;
            for(int i=0;i<size;i++) {
                if(pixels[i] == 0xFFFFFF)
                    pixels[i] = color;
            }
            SDL_UnlockSurface(ascii[a]);
        }
        if(fontwidth)tilewidth=ascii[0]->w/fontwidth;
        OutputChar = &OutputImageChar;

        mainwin = newwin(OPTIONS["TERMINAL_Y"], OPTIONS["TERMINAL_X"],0,0);
        return mainwin;
    }
    #endif // SDLTILES

    std::string sysfnt = find_system_font(typeface, faceIndex);
//.........这里部分代码省略.........
开发者ID:ClockworkZombie,项目名称:Cataclysm-DDA,代码行数:101,代码来源:sdltiles.cpp

示例2: SDL_ConvertSurface

/*
 * Convert a surface into the specified pixel format.
 */
SDL_Surface *
SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format,
                   Uint32 flags)
{
    SDL_Surface *convert;
    Uint32 copy_flags;
    SDL_Rect bounds;

    /* Check for empty destination palette! (results in empty image) */
    if (format->palette != NULL) {
        int i;
        for (i = 0; i < format->palette->ncolors; ++i) {
            if ((format->palette->colors[i].r != 0xFF) ||
                (format->palette->colors[i].g != 0xFF) ||
                (format->palette->colors[i].b != 0xFF))
                break;
        }
        if (i == format->palette->ncolors) {
            SDL_SetError("Empty destination palette");
            return (NULL);
        }
    }

    /* Create a new surface with the desired format */
    convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
                                   format->BitsPerPixel, format->Rmask,
                                   format->Gmask, format->Bmask,
                                   format->Amask);
    if (convert == NULL) {
        return (NULL);
    }

    /* Copy the palette if any */
    if (format->palette && convert->format->palette) {
        SDL_memcpy(convert->format->palette->colors,
                   format->palette->colors,
                   format->palette->ncolors * sizeof(SDL_Color));
        convert->format->palette->ncolors = format->palette->ncolors;
    }

    /* Save the original copy flags */
    copy_flags = surface->map->info.flags;
    surface->map->info.flags = 0;

    /* Copy over the image data */
    bounds.x = 0;
    bounds.y = 0;
    bounds.w = surface->w;
    bounds.h = surface->h;
    SDL_LowerBlit(surface, &bounds, convert, &bounds);

    /* Clean up the original surface, and update converted surface */
    convert->map->info.r = surface->map->info.r;
    convert->map->info.g = surface->map->info.g;
    convert->map->info.b = surface->map->info.b;
    convert->map->info.a = surface->map->info.a;
    convert->map->info.flags =
        (copy_flags &
         ~(SDL_COPY_COLORKEY | SDL_COPY_BLEND
           | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
           SDL_COPY_RLE_ALPHAKEY));
    surface->map->info.flags = copy_flags;
    if (copy_flags & SDL_COPY_COLORKEY) {
        SDL_bool set_colorkey_by_color = SDL_FALSE;

        if (surface->format->palette) {
            if (format->palette &&
                surface->format->palette->ncolors <= format->palette->ncolors &&
                (SDL_memcmp(surface->format->palette->colors, format->palette->colors,
                  surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
                /* The palette is identical, just set the same colorkey */
                SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
            } else if (format->Amask) {
                /* The alpha was set in the destination from the palette */
            } else {
                set_colorkey_by_color = SDL_TRUE;
            }
        } else {
            set_colorkey_by_color = SDL_TRUE;
        }

        if (set_colorkey_by_color) {
            /* Set the colorkey by color, which needs to be unique */
            Uint8 keyR, keyG, keyB, keyA;

            SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR,
                        &keyG, &keyB, &keyA);
            SDL_SetColorKey(convert, 1,
                            SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA));
            /* This is needed when converting for 3D texture upload */
            SDL_ConvertColorkeyToAlpha(convert);
        }
    }
    SDL_SetClipRect(convert, &surface->clip_rect);

    /* Enable alpha blending by default if the new surface has an
     * alpha channel or alpha modulation */
//.........这里部分代码省略.........
开发者ID:EddieRingle,项目名称:SDL,代码行数:101,代码来源:SDL_surface.c

示例3: SDL_RWtell


//.........这里部分代码省略.........
	}

	/* compute some usefull values, based on the bitmap header */

	width = ( bmhd.w + 15 ) & 0xFFFFFFF0;  /* Width in pixels modulo 16 */

	bytesperline = ( ( bmhd.w + 15 ) / 16 ) * 2;

	nbplanes = bmhd.planes;

	if ( pbm )                         /* File format : 'Packed Bitmap' */
	{
		bytesperline *= 8;
		nbplanes = 1;
	}

	stencil = (bmhd.mask & 1);   /* There is a mask ( 'stencil' ) */

	/* Allocate memory for a temporary buffer ( used for
           decompression/deinterleaving ) */

	MiniBuf = (void *)malloc( bytesperline * (nbplanes + stencil) );
	if ( MiniBuf == NULL )
	{
		error="no enough memory for temporary buffer";
		goto done;
	}

	if ( ( Image = SDL_CreateRGBSurface( SDL_SWSURFACE, width, bmhd.h, (bmhd.planes==24 || flagHAM==1)?24:8, 0, 0, 0, 0 ) ) == NULL )
	   goto done;

	if ( bmhd.mask & 2 )               /* There is a transparent color */
#if (SDL_VERSION_ATLEAST(1,3,0))
		SDL_SetColorKey( Image, SDL_TRUE, bmhd.tcolor );
#else
		SDL_SetColorKey( Image, SDL_SRCCOLORKEY, bmhd.tcolor );
#endif


	/* Update palette informations */

	/* There is no palette in 24 bits ILBM file */
	if ( nbcolors>0 && flagHAM==0 )
	{
		/* FIXME: Should this include the stencil? See comment below */
		int nbrcolorsfinal = 1 << (nbplanes + stencil);
		ptr = &colormap[0];

		for ( i=0; i<nbcolors; i++ )
		{
			Image->format->palette->colors[i].r = *ptr++;
			Image->format->palette->colors[i].g = *ptr++;
			Image->format->palette->colors[i].b = *ptr++;
		}

		/* Amiga EHB mode (Extra-Half-Bright) */
		/* 6 bitplanes mode with a 32 colors palette */
		/* The 32 last colors are the same but divided by 2 */
		/* Some Amiga pictures save 64 colors with 32 last wrong colors, */
		/* they shouldn't !, and here we overwrite these 32 bad colors. */
		if ( (nbcolors==32 || flagEHB ) && (1<<bmhd.planes)==64 )
		{
			nbcolors = 64;
			ptr = &colormap[0];
			for ( i=32; i<64; i++ )
			{
开发者ID:knepe,项目名称:cdogs-sdl-android,代码行数:67,代码来源:IMG_lbm.c

示例4: uploadTextureFromSurface

/**
 * Creates a texture from a surface. Set the alpha according to the color key.
 * Pixels that match the color key get an alpha of zero while all other
 * pixels get an alpha of one.
 *
 * The source surface can come from example from a PNG file.
 *
 * @url:http://osdl.sourceforge.net/main/documentation/rendering/SDL-openGL-examples.html#loadnonalphaexample
 */
static GLuint uploadTextureFromSurface(
        SDL_Surface* sourceSurface,
        Uint8 colorKeyRed,
        Uint8 colorKeyGreen,
        Uint8 colorKeyBlue,
        Uint8 colorKeyAlpha)
{

    /*
     * Use the surface width and height expanded to powers of 2 :
     * (one may call also gluScaleImage.
     */

    //int w = powerOfTwo( sourceSurface->w ) ;
    //int h = powerOfTwo( sourceSurface->h ) ;
    int w = ( sourceSurface->w ) ;
    int h = ( sourceSurface->h ) ;

    //    int w = sourceSurface->w;
    //    int h = sourceSurface->h;

    /*
     //TODO:Remove
    // Min X :
    texcoord[0] = 0.0f ;
    // Min Y :
    texcoord[1] = 0.0f ;
    // Max X :
    texcoord[2] = (GLfloat) surface->w / w ;
    // Max Y :
    texcoord[3] = (GLfloat) surface->h / h ;
    */

    /* Create the target alpha surface with correct color component ordering */
    SDL_Surface* alphaImage = SDL_CreateRGBSurface( SDL_SWSURFACE,
            sourceSurface->w,
            sourceSurface->h,
            32 /* bits */,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN // OpenGL RGBA masks
            0x000000FF,
            0x0000FF00,
            0x00FF0000,
            0xFF000000
#else
            0xFF000000,
            0x00FF0000,
            0x0000FF00,
            0x000000FF
#endif
            );

    if ( alphaImage == NX_NULL )
    {
        nxAssertFail("uploadTextureFromSurface : RGB surface creation failed.");
    }

    // Set up so that colorkey pixels become transparent :
    //Uint32 colorkey = SDL_MapRGBA( alphaImage->format, colorKeyRed, colorKeyGreen, colorKeyBlue, colorKeyAlpha );
    Uint32 colorkey = SDL_MapRGBA( alphaImage->format, colorKeyRed, colorKeyGreen, colorKeyBlue, colorKeyAlpha );
    SDL_FillRect( alphaImage, 0, colorkey );

    colorkey = SDL_MapRGBA( sourceSurface->format, colorKeyRed, colorKeyGreen, colorKeyBlue, colorKeyAlpha);
    SDL_SetColorKey( sourceSurface, SDL_SRCCOLORKEY, colorkey );

    SDL_Rect area;

//    SDL_SetAlpha(sourceSurface, 0, 0); //http://www.gamedev.net/topic/518525-opengl--sdl--transparent-image-make-textures/
    SDL_SetAlpha(sourceSurface, 0, colorKeyAlpha); //http://www.gamedev.net/topic/518525-opengl--sdl--transparent-image-make-textures/

//    SDL_SetAlpha(sourceSurface, SDL_ALPHA_TRANSPARENT, 255); //http://www.gamedev.net/topic/518525-opengl--sdl--transparent-image-make-textures/

    // Copy the surface into the GL texture image :
    area.x = 0;
    area.y = 0;
    area.w = sourceSurface->w;
    area.h = sourceSurface->h;
    SDL_BlitSurface( sourceSurface, &area, alphaImage, &area );

    // Create an OpenGL texture for the image

    GLuint textureID;
    glGenTextures( 1, &textureID );
    glBindTexture( GL_TEXTURE_2D, textureID );

    /* Prepare the filtering of the texture image */

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

//.........这里部分代码省略.........
开发者ID:df3n5,项目名称:nur,代码行数:101,代码来源:nxTextureLoader.c

示例5: SDL_GetTicks

	// Draw
	// Paints the surface onto the destination
	bool Sprite::Draw(){
		if(m_Animate){
			if(m_AnimationSpeed > 0){
				Uint32 now = SDL_GetTicks();
				if(m_NextFrameTime <= now){
					IncrementFrameX();
					m_NextFrameTime = now + m_AnimationSpeed;
				}
			}
		}
		if(m_alpha <= 0) return true; // Invisible
		if(pImageSource){

			//SDL_SetAlpha(pImageSource, SDL_SRCALPHA, m_alpha);
			if(m_TileWidth >= pImageSource->w && m_TileHeight >= pImageSource->h && m_TileX == 0 && m_TileY == 0){
				if(m_angle != 0 || m_zoom != 1){ // Just rotated/zoomed
					
					SDL_SetAlpha(pImageSource, SDL_SRCALPHA, 255);
					SDL_Surface* pImageOutput = rotozoomSurface(pImageSource, m_angle, m_zoom, m_smoothing);
					if(pImageOutput != NULL){
						SDL_SetColorKey(pImageOutput, SDL_SRCCOLORKEY, pImageSource->format->colorkey);
						SDL_SetAlpha(pImageOutput, SDL_SRCALPHA, m_alpha);
					    SDL_Rect dest;
						dest.x = (int)m_x - pImageOutput->w/2 - System::CameraX;
						dest.y = (int)m_y - pImageOutput->h/2 - System::CameraY;
					    SDL_BlitSurface(pImageOutput, NULL, System::Screen, &dest);
						SDL_FreeSurface(pImageOutput);
						return true;
					}

				} else { // No rotation or zoom - fast
				    SDL_Rect dest;
					dest.x = (int)m_x - pImageSource->w/2 - System::CameraX;
					dest.y = (int)m_y - pImageSource->h/2 - System::CameraY;
					SDL_SetAlpha(pImageSource, SDL_SRCALPHA, m_alpha);
				    SDL_BlitSurface(pImageSource, NULL, System::Screen, &dest);
					return true;
				}
			} else { // Different tile
				if(m_angle != 0 || m_zoom != 1){ // Rotated/zoomed and different tile

					SDL_Surface* pImageTile = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCCOLORKEY, m_TileWidth, m_TileHeight, pImageSource->format->BitsPerPixel,
                                   pImageSource->format->Rmask, pImageSource->format->Gmask, pImageSource->format->Bmask, pImageSource->format->Amask);
					if(pImageTile){
						
						SDL_Rect source;
						source.x = m_TileX * m_TileWidth;
						source.y = m_TileY * m_TileHeight;
						source.w = m_TileWidth;
						source.h = m_TileHeight;

						SDL_SetAlpha(pImageSource, SDL_SRCALPHA, 255);
						SDL_FillRect(pImageTile, NULL, pImageSource->format->colorkey);
						SDL_BlitSurface(pImageSource, &source, pImageTile, NULL);
						SDL_SetColorKey(pImageTile, SDL_SRCCOLORKEY, pImageSource->format->colorkey);
						SDL_Surface* pImageOutput = rotozoomSurface(pImageTile, m_angle, m_zoom, m_smoothing);
						SDL_FreeSurface(pImageTile);

						if(pImageOutput){
						    SDL_Rect dest;
							dest.x = (int)m_x - pImageOutput->w/2 - System::CameraX;
							dest.y = (int)m_y - pImageOutput->h/2 - System::CameraY;

							SDL_SetColorKey(pImageOutput, SDL_SRCCOLORKEY, pImageSource->format->colorkey);
							SDL_SetAlpha(pImageOutput, SDL_SRCALPHA, m_alpha);
						    SDL_BlitSurface(pImageOutput, NULL, System::Screen, &dest);
							SDL_FreeSurface(pImageOutput);
							return true;
						}
					}
				} else { // Just different tile
					SDL_Rect source; source.x = m_TileX * m_TileWidth; source.y = m_TileY * m_TileHeight;
					source.w = m_TileWidth; source.h = m_TileHeight;
				    SDL_Rect dest;
					dest.x = (int)m_x - m_TileWidth/2 - System::CameraX;
					dest.y = (int)m_y - m_TileHeight/2 - System::CameraY;

					SDL_SetAlpha(pImageSource, SDL_SRCALPHA, m_alpha);
				    SDL_BlitSurface(pImageSource, &source, System::Screen, &dest);
					return true;
				}
				
				
			}
				
		}
		return false;


	}
开发者ID:RobLoach,项目名称:Blastoids,代码行数:92,代码来源:sprite.cpp

示例6: FCN_EXCEPTION

    void SDLImage::convertToDisplayFormat()
    {
        if (mSurface == NULL)
        {
            throw FCN_EXCEPTION("Trying to convert a non loaded image to display format.");
        }

        int i;
        bool hasPink = false;
        bool hasAlpha = false;

        for (i = 0; i < mSurface->w * mSurface->h; ++i)
        {
            if (((unsigned int*)mSurface->pixels)[i] == SDL_MapRGB(mSurface->format,255,0,255))
            {
                hasPink = true;
                break;
            }
        }

        for (i = 0; i < mSurface->w * mSurface->h; ++i)
        {
            Uint8 r, g, b, a;

            SDL_GetRGBA(((unsigned int*)mSurface->pixels)[i], mSurface->format,
                        &r, &g, &b, &a);

            if (a != 255)
            {
                hasAlpha = true;
                break;
            }
        }

        SDL_Surface *tmp;

        if (hasAlpha)
        {
            tmp = SDL_DisplayFormatAlpha(mSurface);
            SDL_FreeSurface(mSurface);
            mSurface = NULL;
        }
        else
        {
            tmp = SDL_DisplayFormat(mSurface);
            SDL_FreeSurface(mSurface);
            mSurface = NULL;
        }

        if (tmp == NULL)
        {
            throw FCN_EXCEPTION("Unable to convert image to display format.");
        }

        if (hasPink)
        {
            SDL_SetColorKey(tmp, SDL_SRCCOLORKEY,
                            SDL_MapRGB(tmp->format,255,0,255));
        }
        if (hasAlpha)
        {
            SDL_SetAlpha(tmp, SDL_SRCALPHA, 255);
        }

        mSurface = tmp;
    }
开发者ID:Beliaar,项目名称:fifechan,代码行数:66,代码来源:sdlimage.cpp

示例7: render_text

bool render_text(font_data *ft_font, const char *text, string_tex_t *string_tex)
{
    SDL_Color white = { 0xFF, 0xFF, 0xFF, 0x00 };
    SDL_Color *forecol;
    SDL_Surface *string_glyph = NULL;
    SDL_Surface *glyph = NULL;
    SDL_Rect src, dest;
    GLenum gl_error;

    if (!(ft_font)) return false;
    if (!(ft_font->ttffont)) return false;
    if (!(string_tex)) return false;
#if 0
    if (!strlen(text)) return false; /* something is printing an empty string each frame */
#else
    /* kps - fix for empty author field in cannon dodgers */
    if (!strlen(text))
	text = " ";
#endif

    forecol = &white;
	
    string_tex->font_height = ft_font->h;
    
    string_glyph = TTF_RenderText_Blended( ft_font->ttffont, text, *forecol );
    
    string_tex->tex_list = Arraylist_alloc(sizeof(tex_t));
	
    string_tex->width = 0;
    string_tex->height = string_glyph->h;
    
    if (string_glyph) {
    	int i, num = 1 + string_glyph->w / 254;
 	string_tex->text = (char *)malloc(sizeof(char)*(strlen(text)+1));
	sprintf(string_tex->text,"%s",text);
   	for( i=0 ; i<num ; ++i ) {
	    tex_t tex;
	    
	    tex.texture = 0;
	    tex.texcoords.MinX = 0.0;
	    tex.texcoords.MaxX = 0.0;
	    tex.texcoords.MinY = 0.0;
	    tex.texcoords.MaxY = 0.0;
	    tex.width = 0;
	    
    	    src.x   = i*254;
	    dest.x  = 0;
    	    src.y = dest.y = 0;
	    if (i==num-1)
	    	dest.w = src.w = string_glyph->w - i*254;
	    else
	    	dest.w = src.w = 254;
    	    src.h = dest.h = string_glyph->h;
	    
    	    glyph = SDL_CreateRGBSurface(0,dest.w,dest.h,32,0,0,0,0);
    	    SDL_SetColorKey(glyph, SDL_SRCCOLORKEY, 0x00000000);
    	    SDL_BlitSurface(string_glyph,&src,glyph,&dest);
    
  	    glGetError();
	    tex.texture = SDL_GL_LoadTexture(glyph,&(tex.texcoords));
    	    if ( (gl_error = glGetError()) != GL_NO_ERROR )
    	    	printf("Warning: Couldn't create texture: 0x%x\n", gl_error);

    	    tex.width = dest.w;
	    string_tex->width += dest.w;
	    
    	    SDL_FreeSurface(glyph);
	    
	    Arraylist_add(string_tex->tex_list,&tex);
	}
	SDL_FreeSurface(string_glyph);
    } else {
    	printf("TTF_RenderText_Blended failed for [%s]\n",text);
	return false;
    }
    return true;
}
开发者ID:calumchisholm,项目名称:XPilotNG-web,代码行数:77,代码来源:text.c

示例8: main

int main(int argc, char* argv[])
{	
	Grille g1 = lirefichier(argv[1]); //Création d'une nouvelle grille à partir d'un fichier chargé
	
	//La grille servira de contrôleur mais l'utilisateur ne la voit jamais : il ne voit que l'interface graphique qui en découlera
	
	joueur j1; //Création d'un nouveau joueur
	j1.posn = 0; 
	j1.posm = 0;
	posjoueur(g1, j1);
		
	SDL_Surface *screen, *temp, *sprite, *grass, *wall; //Création de surfaces SDL
	SDL_Rect rcSprite, rcGrass;
	SDL_Event event;
	Uint8 *keystate;
	int colorkey, gameover;
	
	SDL_Init(SDL_INIT_VIDEO); //initialisation de la fenêtre
	
	SDL_WM_SetCaption("Jeu TecDev SDL", "Jeu TecDev SDL"); //Définission du titre de la fenêtre
	
	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0); //Création de la fenêtre
	
	temp   = SDL_LoadBMP("mushroom.bmp"); //Chargement du sprite mushroom.bmp dans la surface sprite
	sprite = SDL_DisplayFormat(temp);
	SDL_FreeSurface(temp);
	
	colorkey = SDL_MapRGB(screen->format, 255, 255, 255); //Création de la transparence du sprite
	SDL_SetColorKey(sprite, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); 
	
	temp  = SDL_LoadBMP("grass.bmp"); //Chargement du background grass.bmp dans la surface grass
	grass = SDL_DisplayFormat(temp);
	SDL_FreeSurface(temp);
				 
	temp  = SDL_LoadBMP("wall.bmp"); //Chargement de l'image wall.bmp dans la surface wall
	wall = SDL_DisplayFormat(temp);
	SDL_FreeSurface(temp);
	
	colorkey = SDL_MapRGB(screen->format, 255, 255, 255); //Transparence du mur
	SDL_SetColorKey(wall, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey);

	rcSprite.x = 0; //Le sprite est en (0,0) à la base
	rcSprite.y = 0;
	
	gameover = 0; //Si gameover à 1 => Fin du jeu
	
	while (!gameover)
	{
	 if (SDL_PollEvent(&event)) {
		switch (event.type) {
			case SDL_QUIT:
				gameover = 1;
				break;
				
				case SDL_KEYDOWN:
				switch (event.key.keysym.sym) {
					case SDLK_ESCAPE: //Si la touche entrée est échap
					case SDLK_q: //ou q
						gameover = 1; //Alors quitter le jeu
						break;
					case SDLK_p: //Si la touche entrée est p
						while (event.key.keysym.sym != SDLK_p) { //Alors tant que la touche entrée n'est pas p
							rcSprite.x = rcSprite.x; //Le joueur ne bouge pas
							rcSprite.y = rcSprite.y;
						}
						break;
					case SDLK_r: //Si la touche entrée est r
						rcSprite.x = 0; //Réinitialisation du sprite en 0
						rcSprite.y = 0;
						j1.posn = 0; //Réinitialisation du joueur en 0
						j1.posm = 0;
						posjoueur(g1, j1); //Replacement du joueur dans la grille
						break;
					default:
						break;
				}
				break;
			}
		}
		
		//Traitement des cas ou l'utilisateur entre une touche fléchée
		
		keystate = SDL_GetKeyState(NULL); //L'utilisateur entre une touche qui sera contenue dans keystate
		
		int tempn = j1.posn;
		int tempm = j1.posm;
		
		if (keystate[SDLK_LEFT] ) 
		{ 
			if (j1.posm-1 >= 0) 
			{ 
				if (g1.g[j1.posn][j1.posm-1] == 0) 
				{
					j1.posm--;
					g1 = posjoueur(g1, j1); //Placement du joueur dans la grille aux cases correspondantes
					rcSprite.x -= STEP_SIZE;
					retiretrace(g1, j1); //Retire la présence précédente du joueur dans la grille
				}
				else 
				{
//.........这里部分代码省略.........
开发者ID:ychibout,项目名称:tecdev,代码行数:101,代码来源:main.c

示例9: SDL_DisplayFormat

void view::Surface::setShadowSurface(SDL_Surface* surface) {
	this->shadow = SDL_DisplayFormat(surface);
	SDL_SetColorKey(this->shadow,SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB(this->surface->format,255,0,255));
}
开发者ID:hugo-chavar,项目名称:servertall,代码行数:4,代码来源:Surface.cpp

示例10: SDL_BlitSurface

void player::showplayer()
{
    SDL_BlitSurface(image,&clips[1],SDL_GetVideoSurface(),&box);
    SDL_SetColorKey(image,SDL_SRCCOLORKEY,SDL_MapRGB(SDL_GetVideoSurface()->format,255,0,255));
}
开发者ID:WissemAchour,项目名称:Programming-Projects,代码行数:5,代码来源:player.cpp

示例11: SDL_SetColorKey

//sets the color key for the objects within the world
void Application::setKey()
{
    SDL_SetColorKey(player.player, SDL_SRCCOLORKEY, SDL_MapRGB(player.player->format, 0, 128, 128));

    for(int i = 0; i<2; i++)//set key for wraiths
    {
        SDL_SetColorKey(wraithFactory[i].wraith, SDL_SRCCOLORKEY, SDL_MapRGB(wraithFactory[i].wraith->format, 0, 128, 128));
    }

    for(int i = 0; i<2; i++)//set key for mummy
    {
        SDL_SetColorKey(mummyFactory[i].mummy, SDL_SRCCOLORKEY, SDL_MapRGB(mummyFactory[i].mummy->format, 0, 128, 128));
    }

    SDL_SetColorKey(seeker.seeker, SDL_SRCCOLORKEY, SDL_MapRGB(seeker.seeker->format, 0, 128, 128));
    SDL_SetColorKey(ghost.ghost, SDL_SRCCOLORKEY, SDL_MapRGB(ghost.ghost->format, 0, 128, 128));

    SDL_SetColorKey(island1, SDL_SRCCOLORKEY, SDL_MapRGB(island1->format, 0, 128, 128));
    SDL_SetColorKey(island2, SDL_SRCCOLORKEY, SDL_MapRGB(island2->format, 0, 128, 128));
    SDL_SetColorKey(island3, SDL_SRCCOLORKEY, SDL_MapRGB(island3->format, 0, 128, 128));
    SDL_SetColorKey(island4, SDL_SRCCOLORKEY, SDL_MapRGB(island4->format, 0, 128, 128));
    SDL_SetColorKey(spikes, SDL_SRCCOLORKEY, SDL_MapRGB(spikes->format, 0, 128, 128));
    SDL_SetColorKey(spikes1, SDL_SRCCOLORKEY, SDL_MapRGB(spikes1->format, 0, 128, 128));
    SDL_SetColorKey(pillar, SDL_SRCCOLORKEY, SDL_MapRGB(pillar->format, 0, 128, 128));
    SDL_SetColorKey(finish, SDL_SRCCOLORKEY, SDL_MapRGB(finish->format, 0, 128, 128));
    SDL_SetColorKey(ghost.lightning, SDL_SRCCOLORKEY, SDL_MapRGB(ghost.lightning->format, 0, 128, 128));

    for(int i = 0; i<100; i++)//set key for all the arrows
    {
        SDL_SetColorKey(quiver[i].arrowR, SDL_SRCCOLORKEY, SDL_MapRGB(quiver[i].arrowR->format, 0, 128, 128));
        SDL_SetColorKey(quiver[i].arrowL, SDL_SRCCOLORKEY, SDL_MapRGB(quiver[i].arrowL->format, 0, 128, 128));
    }

}
开发者ID:dnivanthaka,项目名称:demo-programs,代码行数:35,代码来源:Application.cpp

示例12: main

int main(int argc, char **argv)
{
	struct birdPackage infoToSend, infoReceived;
	int	port;
	char serverIp  [16];
	if (argc != 3) {
        std::cout << "USO flappy <serverIp> <port>" << std::endl;
		exit(-1);
	}

	strcpy(serverIp, argv[1]);
	port = atoi(argv[2]);

	SocketDatagrama	socket;

	std::cout << "Enviando al servidor: " << serverIp << " : " << port << " datos iniciados" << std::endl;

	bzero(&infoToSend,sizeof(birdPackage));
	bzero(&infoReceived,sizeof(birdPackage));

	/* CONEXION POR PRIMERA VEZ */
	infoToSend.opcode = NEW;

	std::cout << "OPCODE: " << infoToSend.opcode << std::endl;

	PaqueteDatagrama paq((char *)&infoToSend, sizeof(birdPackage), serverIp, port);
	socket.envia(paq);

    PaqueteDatagrama receive(sizeof(birdPackage));
    socket.recibe(receive);

    memcpy(&infoReceived, receive.obtieneDatos(), sizeof(birdPackage));

	if(infoReceived.opcode == DENY) //Se rechaza al jugador, por lo que se tiene que salir
	{
		std::cout << "Partida llena intente más tarde..." << std::endl;
		exit(-1);
	}else{
		nJugador = infoReceived.jugadorNum;
		infoToSend.opcode = JUMP;
		std::cout << "Partida iniciada, jugador: " << nJugador << std::endl;
	}

	SDL_Init(SDL_INIT_VIDEO);
	SDL_Window     *ventana = SDL_CreateWindow("Hi", 200, 200, 864, 510, SDL_WINDOW_SHOWN);
	SDL_Renderer   *render = SDL_CreateRenderer(ventana, -1, SDL_RENDERER_ACCELERATED);
	//se carga la imagen que contiene todos los graficos
	SDL_Surface * bmp = SDL_LoadBMP("atlas.bmp");
	//se define el blanco como color transparente
	SDL_SetColorKey(bmp, 1, SDL_MapRGB(bmp->format, 255, 255, 255));
	SDL_Texture    *textura = SDL_CreateTextureFromSurface(render, bmp);
	SDL_FreeSurface(bmp);
	SDL_Event	event;
	if (textura == NULL) {
        std::cout << "FAILED TO FIND THE IMAGE" << std::endl;
	}
	SDL_RenderClear(render);
	renderFondo(render, textura);

	//Inicializa la posición de los pajaros dentro de la pantalla, pasandolos del atlas.bmp al recuadro del juego
	initPajarosOrigen(render, textura);
	SDL_RenderPresent(render);


	int		done = 1;
	double		angulo = 330;
	const int	FPS = 24;
	//Cuantos frames por segundo queremos, 60 es el que utilizan los televisores
    const int	DELAY_TIME = 1000.0f / FPS;
	//1000 ms entre los fps da el numero de milisegundos entre cada frame
    Uint32 frameStart, frameTime;
	while (done) {
		frameStart = SDL_GetTicks();

		//validacion del piso
		if (rectangulo_destino[nJugador].y < 500) {
			rectangulo_destino[nJugador].y += 10;
		}
		//validacion del angulo maximo
		if (angulo < 450) {
			angulo += 15;
		}
		//mientras exista un evento en el pila de eventos
			while (SDL_PollEvent(&event)) {
			//salto
			if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) {
				rectangulo_destino[nJugador].y -= 100;
				angulo = 300;
				infoToSend.opcode = 1;
			} else if (event.type == SDL_QUIT) {
				infoToSend.opcode = CLOSE;
				done = 0;
			}
		}
		//enviar Paquete con las coordenadas
		infoToSend.jugadorNum = nJugador;
		infoToSend.posicionJUMP_X[nJugador] = rectangulo_destino[nJugador].x;
		infoToSend.posicionJUMP_Y[nJugador] = rectangulo_destino[nJugador].y;
		infoToSend.angulo[nJugador] = angulo;
		PaqueteDatagrama paq((char *)&infoToSend, sizeof(birdPackage), serverIp, port);
//.........这里部分代码省略.........
开发者ID:jolmes01,项目名称:SDL_Bird,代码行数:101,代码来源:flappyCliente.cpp

示例13: AG_LoadGIF_RW


//.........这里部分代码省略.........
	gd->g89.inputFlag	= -1;
	gd->g89.disposal	= AG_DISPOSE_NA;

	if ( !SDL_RWread(src,buf,7,1) )
	{
		SDL_SetError( "failed to read screen descriptor" );
		goto done;
	}

	gd->gs.Width			= LM_to_uint(buf[0],buf[1]);
	gd->gs.Height			= LM_to_uint(buf[2],buf[3]);
	gd->gs.BitPixel			= 2 << (buf[4] & 0x07);
	gd->gs.ColorResolution	= (((buf[4] & 0x70) >> 3) + 1);
	gd->gs.Background		= buf[5];
	gd->gs.AspectRatio		= buf[6];

	if ( BitSet(buf[4],LOCALCOLORMAP) )		/* Global Colormap */
	{
		if ( ReadColorMap(gd,gd->gs.BitPixel,gd->gs.ColorMap) )
		{
			SDL_SetError( "error reading global colormap" );
			goto done;
		}
	}

	do
	{
		if ( !SDL_RWread(src,&c,1,1) )
		{
			SDL_SetError( "EOF / read error on image data" );
			goto done;
		}

		if ( c == ';' )		/* GIF terminator */
			goto done;

		if ( c == '!' )		/* Extension */
		{
			if ( !SDL_RWread(src,&c,1,1) )
			{
				SDL_SetError( "EOF / read error on extention function code" );
				goto done;
			}
			DoExtension( gd, c );
			continue;
		}

		if ( c != ',' )		/* Not a valid start character */
			continue;

		if ( !SDL_RWread(src,buf,9,1) )
		{
			SDL_SetError( "couldn't read left/top/width/height" );
			goto done;
		}

		useGlobalColormap = !BitSet(buf[8],LOCALCOLORMAP);
		bitPixel = 1 << ((buf[8] & 0x07) + 1);

		if ( !useGlobalColormap )
		{
			if ( ReadColorMap(gd,bitPixel,gd->localColorMap) )
			{
				SDL_SetError( "error reading local colormap" );
				goto done;
			}
			image = ReadImage( gd, LM_to_uint(buf[4],buf[5]), LM_to_uint(buf[6],buf[7]), bitPixel, gd->localColorMap, BitSet(buf[8],INTERLACE), (frames==NULL) );
		}
		else
		{
			image = ReadImage( gd, LM_to_uint(buf[4],buf[5]), LM_to_uint(buf[6],buf[7]), gd->gs.BitPixel, gd->gs.ColorMap, BitSet(buf[8],INTERLACE), (frames==NULL) );
		}

		if ( frames )
		{
			if ( image == NULL )
				goto done;

			if ( gd->g89.transparent >= 0 )
				SDL_SetColorKey( image, SDL_SRCCOLORKEY, gd->g89.transparent );

			frames[iFrame].surface	= image;
			frames[iFrame].x		= LM_to_uint(buf[0], buf[1]);
			frames[iFrame].y		= LM_to_uint(buf[2], buf[3]);
			frames[iFrame].disposal	= gd->g89.disposal;
			frames[iFrame].delay	= gd->g89.delayTime*10;
/*			gd->g89.transparent		= -1;			** Hmmm, not sure if this should be reset for each frame? */
		}

		iFrame++;
	} while ( iFrame < maxFrames || frames == NULL );

done:
	if ( image == NULL )
		SDL_RWseek( src, start, SEEK_SET );

	free( gd );

	return iFrame;
}
开发者ID:Kr0nZ,项目名称:boxee,代码行数:101,代码来源:SDL_anigif.c

示例14: File

/**
 * Load a font from the given .0FN file.
 *
 * @param fileName Name of an .0FN file
 */
Font::Font (const char* fileName) {

	File* file;
	unsigned char* pixels;
	unsigned char* blank;
	int fileSize;
	int count, size, width, height;

	// Load font from a font file

	try {

		file = new File(fileName, false);

	} catch (int e) {

		throw e;

	}

	fileSize = file->getSize();

	nCharacters = 128;


	file->seek(20, true);
	lineHeight = file->loadChar() << 1;


	// Create blank character data

	blank = new unsigned char[3];
	memset(blank, 0, 3);


	// Load characters

	for (count = 0; count < 128; count++) {

		if (file->tell() >= fileSize) {

			nCharacters = count;

			break;

		}

		size = file->loadShort();

		if (size > 4) {

			pixels = file->loadRLE(size);

			width = pixels[0];
			width += pixels[1] << 8;
			height = pixels[2];
			height += pixels[3] << 8;

			if (size - 4 >= width * height)
				characters[count] = createSurface(pixels + 4, width, height);
			else
				characters[count] = createSurface(blank, 3, 1);

			delete[] pixels;

		} else characters[count] = createSurface(blank, 3, 1);

		SDL_SetColorKey(characters[count], SDL_SRCCOLORKEY, 0);

	}

	delete[] blank;

	delete file;


	// Create ASCII->font map

	for (count = 0; count < 33; count++) map[count] = 0;
	map[33] = 107; // !
	map[34] = 116; // "
	map[35] = 0; // #
	map[36] = 63; // $
	map[37] = 0; // %
	map[38] = 0; // &
	map[39] = 115; // '
	map[40] = 111; // (
	map[41] = 112; // )
	map[42] = 0; // *
	map[43] = 105; // +
	map[44] = 101; // ,
	map[45] = 104; // -
	map[46] = 102; // .
	map[47] = 108; // /
	for (count = 48; count < 58; count++) map[count] = count + 5;  // Numbers
//.........这里部分代码省略.........
开发者ID:Chemrat,项目名称:openjazz,代码行数:101,代码来源:font.cpp

示例15: img_init_suite

void		img_init_suite(t_image *img)
{
  unsigned int	col;

  col = SDL_MapRGB(img->monster1->format, 255, 255, 255);
  SDL_SetColorKey(img->monster1, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->monster2, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->monster3, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->monster4, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->monster5, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->monster6, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->hero1, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->hero2, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->hero3, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->hero4, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->hero5, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
  SDL_SetColorKey(img->hero6, SDL_RLEACCEL | SDL_SRCCOLORKEY, col);
}
开发者ID:Surogate,项目名称:epi-gamerush,代码行数:18,代码来源:image_fct.c


注:本文中的SDL_SetColorKey函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。