Let's copy one

xiaoxiao2021-03-06  48

#include #include #include #include #include #include #include

/ SDL_Surface * g_screenSurface = NULL; SDL_Surface * g_donutSurface = NULL; SDL_Surface * g_backface = NULL; SDL_Surface * g_test = NULL; // surface effects SDL_Surface * bBuffer; SDL_Surface * Image; SDL_Rect rScreen; SDL_Rect rBuffer;

#define pi 3.1415926535f

Const int update_interval = 30; static int direct = 1; // 1: Right, 2: Left, 3: On, 4: Under the default

static Uint32 timeCount = 0; / Uint32 timeLeft (void); void init (void); void shutDown (void); void loadBMP (void); void loadBack (void); void loadAnimal (void); void OnKeyDown (int key); Void render (int Direct); / void tunnel_timer ()} double tunnel_gettime () {return SDL_GETTICKS () * 1.0 / 1000;

/

/

INT Main (int Argc, char * argv []) {tunnel_timer ();

INIT ();

LoadBMP ();

LoadBack ();

Loadanimal ();

BOOL BDONE = false; while (bdone == false) {sdl_event event; while (SDL_POLLEVENT)) {if (event.type == SDL_QUIT) BDONE = true; if (event.type == SDL_KEYDOWN) {IF (Event .key.keysym.sym == SDLK_ESCAPE) BDONE = true; onkeydown (event.key.keym.sym);}} render (Direct);} shutdown (); return 0;} void onkeydown (int key) {switch (@Witch Key) {CASE SDLK_A:

Break; Case SDLK_S:

Break; Case SDLK_D:

Break; Case SDLK_W:

Break;}} // void init (void) {if (SDL_INIT (SDL_INIT_VIDEO) <0) {printf ("Unable to init s / n", SDL_GETERROR ()); exit (1);} atexit (SDL_QUIT ); G_screensurface = SDL_SETVIDEODE (800, 600, 32, SDL_HWSURFACE); // | SDL_DOUBLEBUF); if (g_screensurface == null) {Printf ("Unable to set 800x600 video:% s / n", SDL_GETERROR ()); EXIT (1);} / * bBuffer = SDL_CreateRGBSurface (SDL_HWSURFACE, 256, // g_screenSurface-> w, 256, // g_screenSurface-> h, g_screenSurface-> format-> BitsPerPixel, g_screenSurface-> format-> rmask, g_screenSurface-> Format-> gmask, g_screensurface-> format-> bmask, g_screensurface-> format-> amask);

Image = SDL_LOADBMP ("tunnel_map.bmp"); if (! Bbuffer ||! Image) {printf ("Error: i can't load or create bmp !!! / n / n");} Image = SDL_CONVERTSURFACE (Image) , g_screensurface-> format, sdl_hwsurface);

rBuffer.x = 0; rBuffer.y = 0; rBuffer.w = bBuffer-> w; rBuffer.h = bBuffer-> h; SDL_EventState (SDL_ACTIVEEVENT, SDL_IGNORE); SDL_EventState (SDL_MOUSEMOTION, SDL_IGNORE); SDL_ShowCursor (SDL_DISABLE); Tunnel .SET (320, 240); // Dimension du tunnel tunnel.precal (16); // DIAMETRE DU TUNNEL * / SDL_ENABLEKEYREPEAT (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);}

//// ---------------------------------- ------------------------------- void loadbmp (void) {// load the bmp file = SURFACE G_DONUTSURFACE = SDL_LOADBMP ( "donut.bmp"); if (g_donutSurface == NULL) {fprintf (stderr, "Could not load /"donut.bmp/" ", SDL_GetError ()); return;} SDL_SetColorKey (g_donutSurface, SDL_SRCCOLORKEY, SDL_MapRGB (g_donutSurface -> Format, 0, 0, 0);} void loadingback (void) {g_backface = SDL_LOADBMP ("back2.bmp"); if (g_backface == null) {fprintf (stderr, "couldn't load /" back2 .bmp / ​​"", SDL_GetError ()); return;} SDL_SetColorKey (g_backface, SDL_SRCCOLORKEY, SDL_MapRGB (g_backface-> format, 0, 0, 0));} void loadAnimal (void) {g_test = SDL_LoadBMP ( "back2.bmp "); if (g_test == null) {fprintf (stderr," couldn't load / "back2.bmp/ ", SDL_GETERROR ()); return;} SDL_SETCOLORKEY (G_Test, SDL_SRCCOLORKEY, SDL_MAPRGB (g_test-> format, 0, 0, 0));} // uint32 timeeleft (void) {stat ic Uint32 timeToNextUpdate = 0; Uint32 currentTime; currentTime = SDL_GetTicks (); if (timeToNextUpdate <= currentTime) {timeToNextUpdate = currentTime UPDATE_INTERVAL; return 0;} // time control timeCount = timeCount 10; return (timeToNextUpdate - currentTime) }

Void shutdown (void) {//tunnel.free (); SDL_FREESURFACE; SDL_FREESURFACE; SDL_FREESURFACE; SDL_FREESURFACE; SDL_FREESURFACE (g_test);}

void render (int iDirect) {SDL_Delay (timeLeft ()); // SDL_FillRect: brush main page where rect is null, the entire g_screenSurface 0,0,0 background color set to black SDL_FillRect (g_screenSurface, NULL, SDL_MapRGB (g_screenSurface- > format, 0,0,0)); // // blit the bitmap back surface to the main surface // SDL_BLITSURFACE (g_blickface, null, g_screensurface, null); // // blit the bitmap Animal Surface to the main Surface // / * SDL_Rect srcRectAnimal; SDL_Rect destRectAnimal; srcRectAnimal.x = 200; srcRectAnimal.y = 300; srcRectAnimal.w = 100; srcRectAnimal.h = 50; destRectAnimal.x = 400; destRectAnimal.y = 100; destRectAnimal.w = 100; destRectAnimal.h = 50; SDL_BlitSurface (g_test, & srcRectAnimal, g_screenSurface, & destRectAnimal); * / // SDL_Delay (1000); // SDL_UpdateRects (g_screenSurface, 1, & destRectAnimal); // // Blit the bitmap surface to the main Surface /// * static int nposition = 0; static int nframe = 0; SDL_RECT SRCRECT; SDL_RECT DESTRECT; / / BUILD A Source SDL_Rect Which Will Copy Only A Small Portion of the Texture. srcRect.x = ((NFRAME% 5) * 64); // Cut the small block block from the original large group diagram to write to the main page srcRect.y = ((NFRAME / 5) ) * 64); srcRect.w = 64; SrcRect.h = 64;

DestRect.x = nposition; destRect.y = 500; destRect.w = 64; destRect.h = 64;

SDL_BLITSURFACE (G_Donutsurface, & srcRect, g_screensurface, & design);

// Update The Changed Portion of The Screen SDL_UPDATERECTS (G_Screensurface, 1, & Destruction);

////// INCREMENT THE SPRIS'S FRAME NUMBER. Our sprite's Animation Sequence // Consists of 30 frames (0-29). // nframe; // A total of 30 small pictures nFrame = 0; // // Slowly move our sprite across the screen This demonstrates how to use // a SDL_Rect destination rect with the SDL_BlitSurface method to place a // sprite on the main screen surface // nPosition;.. if (nPosition> 800) nPosition = 0; * / SDL_Flip (g_screenSurface); / / * float fTime = Tunnel_GetTime (); SDL_LockSurface (bBuffer); SDL_LockSurface (Image); // et on le dessine normalement // Tunnel.Draw (! BBuffer, Image, FTIME * 100, FTIME * 100); // OU Un PEU Plus Delire Tunnel.draw (BBuffer, Image, 180 * Sin (ftime), ftime * 100); SDL_UNLOCKSURFACE (BBuffer); SDL_Unlocksurface (image); SDL_BLITSURFACE (BBuffer, Null, G_Screensurface, & RBuffer); SDL_UPDATERECT (G_Screensurface, 0, 0, 0, 0); * / ///}

转载请注明原文地址:https://www.9cbs.com/read-40709.html

New Post(0)