summaryrefslogtreecommitdiff
path: root/ball.c
blob: 6470f68b51353948e83595ee0fd379bedac8be69 (plain)
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
#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);
}