From f6997ebd1de555916c491dbd603f7a0e9c1d9c58 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 4 Aug 2006 00:56:19 +0000 Subject: git-svn-id: svn://mattst88.com/svn/sdlpong/trunk@2 e27a58fc-241a-0410-afba-9958544cdf14 --- ball.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ball.c (limited to 'ball.c') diff --git a/ball.c b/ball.c new file mode 100644 index 0000000..6470f68 --- /dev/null +++ b/ball.c @@ -0,0 +1,31 @@ +#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); +} + -- cgit v1.2.3