Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
#include <SDL.h> SDL_Surface *screen; SDL_Surface *back; SDL_Surface *sun; int xpos=0,ypos=0; int InitImages() { back = SDL_LoadBMP("back.bmp"); sun = SDL_LoadBMP("sun.bmp"); return 0; } void DrawIMG(SDL_Surface *img, int x, int y) { SDL_Rect dest; dest.x = x; dest.y = y; SDL_BlitSurface(img, NULL, screen, &dest); } void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2) { SDL_Rect dest; dest.x = x; dest.y = y; SDL_Rect dest2; dest2.x = x2; dest2.y = y2; dest2.w = w; dest2.h = h; SDL_BlitSurface(img, &dest2, screen, &dest); } void DrawBG() { DrawIMG(back, 0, 0); } void DrawScene() { DrawIMG(sun, xpos, ypos); DrawIMG(back, xpos, ypos, 0, 0, xpos, ypos); SDL_Flip(screen); } /*-----------------------------------------------------------------------------------*/ /*---MAIN-SCHLEIFE-------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/ int main (int argc, char *argv[]) { Uint8* keys; SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO); screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF); InitImages(); DrawBG(); int done=0; while(done == 0) { SDL_Event event; while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_QUIT ) { done = 1; } if ( event.type == SDL_KEYDOWN ) { if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; } } } keys = SDL_GetKeyState(NULL); if ( keys[SDLK_UP] ) { ypos -= 3; } if ( keys[SDLK_DOWN] ) { ypos += 3; } if ( keys[SDLK_LEFT] ) { xpos -= 3; } if ( keys[SDLK_RIGHT] ) { xpos += 3; } DrawScene(); } atexit(SDL_Quit); return 0; } |
Anonymous
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
void DrawScene() { DrawIMG(sun, xpos, ypos); DrawIMG(back, xpos, ypos, 0, 0, xpos, ypos); SDL_Flip(screen); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
void DrawScene() { DrawIMG(back, xpos-3, ypos-3, sun->w+6, sun->h+6, xpos-3, ypos-3); DrawIMG(sun, xpos, ypos); SDL_Flip(screen); } |
Anonymous
unregistriert
Bist Du sicher das die Main eine Schleife ist?Zitat von »"spacegaier"«
C-/C++-Quelltext
1 2 3 4 /*-----------------------------------------------------------------------------------*/ /*---MAIN-SCHLEIFE-------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/ int main (int argc, char *argv[])
Werbeanzeige