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 92 93 94 95 96 97 98 99 100 101 |
#include <sdl.h> #include <windows.h> #ifdef main #undef main #endif int main(int argc, char *argv[]) { SDL_Surface *Screen; SDL_Surface *Player; SDL_Surface *Stars; SDL_Surface *Shot; SDL_Rect ShotRect[255]; SDL_Rect PlayerRect; SDL_Rect StarRect; bool exit = false; float LastTime, CurTime, Elapsed; SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); Screen = SDL_SetVideoMode(1024,768,32,SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); Shot = SDL_LoadBMP("Schuss.bmp"); SDL_SetColorKey(Shot, SDL_SRCCOLORKEY, SDL_MapRGB(Shot->format, 255,255,255)); Player = SDL_LoadBMP("Raumschiff.bmp"); PlayerRect.x = 150; PlayerRect.y = 150; PlayerRect.w = Player->w; PlayerRect.h = Player->h; SDL_SetColorKey(Player,SDL_SRCCOLORKEY, SDL_MapRGB(Player->format, 255,255,255)); Stars = SDL_LoadBMP("Sterne.bmp"); StarRect.x = 0; StarRect.y = 0; StarRect.w = Stars->w; StarRect.h = Stars->h; LastTime = SDL_GetTicks() / 1000.0f; int i=0; while(!(exit)) { CurTime = SDL_GetTicks() / 1000.0f; Elapsed = CurTime - LastTime; LastTime = CurTime; SDL_FillRect(Screen, NULL, SDL_MapRGB(Screen->format,255,0,0)); SDL_BlitSurface(Stars, NULL, Screen, &StarRect); SDL_BlitSurface(Player, NULL, Screen,&PlayerRect); for(int j=0; j==254;j++) { SDL_BlitSurface(Shot, NULL, Screen, &ShotRect[j]); } SDL_Flip(Screen); if(GetAsyncKeyState(VK_SPACE)) { if(i==254) { i = 0; } else { i++; } ShotRect[i].x = PlayerRect.x + PlayerRect.w + 1; ShotRect[i].y = PlayerRect.y; } if(GetAsyncKeyState(VK_RIGHT) & 0x8000) { if(PlayerRect.x + PlayerRect.w < 1024) { PlayerRect.x += 500.0f * Elapsed; } } if(GetAsyncKeyState(VK_LEFT) & 0x8000) { if(PlayerRect.x > 0) { PlayerRect.x -= 500.0f * Elapsed; } } if(GetAsyncKeyState(VK_DOWN) & 0x8000) { if(PlayerRect.y + PlayerRect.h < 768) { PlayerRect.y += 500.0f * Elapsed; } } if(GetAsyncKeyState(VK_UP) & 0x8000) { if(PlayerRect.y > 0) { PlayerRect.y -= 500.0f * Elapsed; } } if(GetAsyncKeyState(VK_ESCAPE) & 0x8000) { exit = true; } for(int j=0; j== 254;j++) { ShotRect[j].x += 500.0f * Elapsed; } } SDL_Quit(); return 0; } |
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
#include <sdl.h> #include <windows.h> #ifdef main #undef main #endif int main(int argc, char *argv[]) { SDL_Surface *Screen; SDL_Surface *Player; SDL_Surface *Stars; SDL_Surface *Shot; SDL_Rect ShotRect[255]; SDL_Rect PlayerRect; SDL_Rect StarRect; bool exit = false; float LastTime, CurTime, Elapsed; SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); Screen = SDL_SetVideoMode(1024,768,32,SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); Shot = SDL_LoadBMP("Schuss.bmp"); for(int a = 0; a==254; a++) { ShotRect[a].x = 0; ShotRect[a].y = 769; ShotRect[a].w = Shot->w; ShotRect[a].h = Shot->h; } SDL_SetColorKey(Shot, SDL_SRCCOLORKEY, SDL_MapRGB(Shot->format, 255,255,255)); Player = SDL_LoadBMP("Raumschiff.bmp"); PlayerRect.x = 150; PlayerRect.y = 150; PlayerRect.w = Player->w; PlayerRect.h = Player->h; SDL_SetColorKey(Player,SDL_SRCCOLORKEY, SDL_MapRGB(Player->format, 255,255,255)); Stars = SDL_LoadBMP("Sterne.bmp"); StarRect.x = 0; StarRect.y = 0; StarRect.w = Stars->w; StarRect.h = Stars->h; LastTime = SDL_GetTicks() / 1000.0f; int i=0; while(!(exit)) { CurTime = SDL_GetTicks() / 1000.0f; Elapsed = CurTime - LastTime; LastTime = CurTime; SDL_FillRect(Screen, NULL, SDL_MapRGB(Screen->format,255,0,0)); SDL_BlitSurface(Stars, NULL, Screen, &StarRect); SDL_BlitSurface(Player, NULL, Screen,&PlayerRect); for(int j=0; j==254;j++) { SDL_BlitSurface(Shot, NULL, Screen, &ShotRect[j]); } SDL_Flip(Screen); if(GetAsyncKeyState(VK_SPACE)) { ShotRect[i].x = PlayerRect.x + PlayerRect.w + 1; ShotRect[i].y = PlayerRect.y; if(i==254) { i = 0; } else { ++i; } } if(GetAsyncKeyState(VK_RIGHT) & 0x8000) { if(PlayerRect.x + PlayerRect.w < 1024) { PlayerRect.x += 500.0f * Elapsed; } } if(GetAsyncKeyState(VK_LEFT) & 0x8000) { if(PlayerRect.x > 0) { PlayerRect.x -= 500.0f * Elapsed; } } if(GetAsyncKeyState(VK_DOWN) & 0x8000) { if(PlayerRect.y + PlayerRect.h < 768) { PlayerRect.y += 500.0f * Elapsed; } } if(GetAsyncKeyState(VK_UP) & 0x8000) { if(PlayerRect.y > 0) { PlayerRect.y -= 500.0f * Elapsed; } } if(GetAsyncKeyState(VK_ESCAPE) & 0x8000) { exit = true; } for(int k=0; k== 254;k++) { ShotRect[k].x += 550.0f * Elapsed; } } SDL_Quit(); return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 |
for(int k=0; k== 254;k++) { ShotRect[k].x += 550.0f * Elapsed; } |
C-/C++-Quelltext |
|
1 2 3 4 |
for(int j=0; j==254;j++) { SDL_BlitSurface(Shot, NULL, Screen, &ShotRect[j]); } |
C-/C++-Quelltext |
|
1 2 3 4 |
for(int j=0; j== 254;j++) { ShotRect[j].x += 500.0f * Elapsed; } |
C-/C++-Quelltext |
|
1 |
for(int j=0; j<=254; j++) |
Werbeanzeige