c++ - Can someone code review my small SDL app? Want to make sure I didn't make any beginner mistakes -
In an effort to teach SDL libraries (hence handle my stack overflow :)) I wanted to try my hand Side Scroller . My code has been completed but I need some feedback (mostly because I feel like some simple arguments if there is any more details for that).
My "Program" is a C + + Side-Scroller where you move a single phantom on the screen to jump, bad guys, guns, scores, levels or nothing. I wanted to use it on the basis, so I thought that my base is wrong, I could end up with some very bad future apps. It is also multi-threaded. Next, I would like to make the person animated animated (it seems that he is running instead of sliding) as well as the arrow buttons are kept for long while the person gets faster).
The code is too long but this is my main way to have a link below for the entire program:
#include type == SDL_QUIT} {return 0; } And if (event-> type == SDL_KEYDOWN) {if (event-> gtk; key.keysym.sym == SDLK_ LEFT}}; event-> key.keysym.sym == SDLK_RIGHT) {gamez-> Move (incident> gtc: key.keysym.sym); }} And if (Event-> Type == SDL_KEYUP) {if (event-> gt; key.keysym.sym == SDLK_LEft}} Event-> Key.kizim SIM == SDLK_RGHT {gamez- & Gt; Stop_mov (Event> Key.keysym.sym); }} And {// is not an event related to this game}}}} int display_loop (zero * stuff) {game * gamez = (game *) accessories; Double period = 1 / fps * 1000; Uint32 milli_period = (Uint32) duration; // Gadgets SDL_Rect * background_rect = gamez- & gt; Get some features from get_background_rect (); SDL_property * person_rect = gamez- & gt; Get_person_rect (); SDL_Surface * screen = gamez- & gt; Get_screen (); SDL_Surface * background = gamez- & gt; Get_background (); SDL_Surface * person = gamez- & gt; Get_person (); Uint32 start, end; Int sleep; While (1) {start = SDL_GetTicks (); // blit background SDL_BlitSurface (background, background, screen, zero); // blit person SDL_BlitSurface (person, zero, screen, person_rect); End = SDL_GetTicks (); Sleep = milli-period - (end-start); If (sleeping Lieutenant; 0) {sleep = 0; } SDL_Delay ((Uint32) sleep); If (SDL_Flip (gamez-> get_screen ())! = 0) {cout & lt; & Lt; "Error drawing on screen:" & lt; & Lt; SDL_GetError () & lt; & Lt; Endl; }}}
Here is a link to my .zip file of all the codes (please ignore some variable names ;-)): Well you guys can see a glance and tell me Do you think?
Looks good, but some small improvements come to my mind:
- If you can switch-case instead of if-else-if
- You can create aliases for event-> key.keysym.sym for readability.
Comments
Post a Comment