#include "SDL.h" #include "SDL_image.h" #include #include "ball.h" Ball_t * CreateBall(const char * image) { SDL_Surface * Temp = NULL; Ball_t * newball; newball = malloc(sizeof(Ball_t)); Temp = IMG_Load(image); if (!Temp) { fprintf(stderr, "Unable to load image: %s\n", SDL_GetError()); exit (-1); } newball->Surface = SDL_DisplayFormatAlpha(Temp); newball->Rect.w = newball->Surface->w; newball->Rect.h = newball->Surface->h; SDL_FreeSurface(Temp); return newball; } void DrawBall(Ball_t * Ball) { SDL_BlitSurface(Ball->Surface, NULL, SDL_GetVideoSurface(), &Ball->Rect); SDL_UpdateRect(SDL_GetVideoSurface(), Ball->Rect.x, Ball->Rect.y, Ball->Rect.w, Ball->Rect.h); } void DeleteBall(Ball_t * Ball) { SDL_FreeSurface(Ball->Surface); free(Ball); }