summaryrefslogtreecommitdiff
path: root/ball.c
diff options
context:
space:
mode:
Diffstat (limited to 'ball.c')
-rw-r--r--ball.c31
1 files changed, 31 insertions, 0 deletions
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 <stdlib.h>
+#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);
+}
+