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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
void Game() { SDL_Surface *Player; SDL_Surface *Background; SDL_Rect PlayerRect; SDL_Rect BackgroundRect; SDL_Rect Background_Frame; float CurTime, LastTime, Elapsed = 0; float jumpTime = 0; bool jumpLock = false; Player = SDL_LoadBMP("data\\Player_Male.bmp"); PlayerRect.x = 1024/2 - 128/2; PlayerRect.y = 500; PlayerRect.w = Player->w; PlayerRect.h = Player->h; SDL_SetColorKey(Player, SDL_SRCCOLORKEY, SDL_MapRGB(Player->format, 255,0,255)); Background = SDL_LoadBMP("data\\Tree.bmp"); BackgroundRect.x = 0; BackgroundRect.y = 0; BackgroundRect.w = Background->w; BackgroundRect.h = Background->h; Background_Frame.x = 0; Background_Frame.y = 0; Background_Frame.w = 1024; Background_Frame.h = 768; bool exit = false; LastTime = SDL_GetTicks() / 1000.0f; while(!(exit)) { CurTime = SDL_GetTicks() / 1000.0f; Elapsed = CurTime - LastTime; LastTime = CurTime; SDL_FillRect(Screen, NULL, SDL_MapRGB(Screen->format, 0, 0, 0)); SDL_BlitSurface(Background, &Background_Frame, Screen, &BackgroundRect); SDL_BlitSurface(Player, NULL, Screen, &PlayerRect); SDL_Flip(Screen); if(GetAsyncKeyState(VK_ESCAPE) & 0x8000) { if(!(block)) { exit = true; block = true; } } else { block = false; } if(GetAsyncKeyState(VK_RIGHT) & 0x8000) { if(Background_Frame.x < 3072 - 1024) { Background_Frame.x += 300.0f * Elapsed; } else { if(PlayerRect.x + PlayerRect.w < 1024) { PlayerRect.x += 300.0f * Elapsed; } } } if(GetAsyncKeyState(VK_LEFT) & 0x8000) { if(Background_Frame.x > 0) { Background_Frame.x -= 300.0f * Elapsed; } else { if(PlayerRect.x >= 0) { PlayerRect.x -= 300.0f * Elapsed; } } } if(GetAsyncKeyState(VK_SPACE) & 0x8000) { jumpTime += Elapsed; if((jumpTime < 0.5f) && (!(jumpLock))) { PlayerRect.y -= 500.0f * Elapsed; } else if(jumpTime >= 0.5f) { jumpLock = true; jumpTime = 0; } else { jumpTime = 0; if(PlayerRect.y >= 500.0f) { if(jumpLock = true) jumpLock = false; } else { PlayerRect.y += 500.0f * Elapsed; } } } else { if(PlayerRect.y >= 500.0f) { if(jumpLock = true) jumpLock = false; } else { PlayerRect.y += 500.0f *Elapsed; } } } } |
Anonymous
unregistriert
Anonymous
unregistriert
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 |
if(GetAsyncKeyState(VK_RIGHT) & 0x8000) { if((Background_Frame.x < 3072 - 1024)&&(PlayerRect.x => 1024/2 - 128/2)) { Background_Frame.x += 300.0f * Elapsed; } else { if(PlayerRect.x + PlayerRect.w < 1024) { PlayerRect.x += 300.0f * Elapsed; } } } if(GetAsyncKeyState(VK_LEFT) & 0x8000) { if((Background_Frame.x > 0)&&(PlayerRect.x <= 1024/2 - 128/2)) { Background_Frame.x -= 300.0f * Elapsed; } else { if(PlayerRect.x >= 0) { PlayerRect.x -= 300.0f * Elapsed; } } } |
Werbeanzeige