blob: 5728e9f97bd99f3130d1d495855a56db0b28d18f (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include <stdlib.h>
#include "SDL.h"
#include "SDL_opengl.h"
#include "glpong.h"
#include "ball.h"
void GLPong_BallAdd() {
Uint8 i;
int added = 0;
for (i = 0; i < sizeof(GLPong.Balls) / sizeof(void *); i++) {
if (GLPong.Balls[i] == NULL) {
GLPong.Balls[i] = malloc(sizeof(Ball_t));
added = 1;
break;
}
}
if (added) {
GLPong.Balls[i]->w = GLPong.w / (GLfloat)40;
GLPong.Balls[i]->h = GLPong.h / (GLfloat)30;
GLPong.Balls[i]->x = 40.0f;
GLPong.Balls[i]->y = 40.0f;
GLPong.Balls[i]->r = (float)rand() / RAND_MAX;
GLPong.Balls[i]->g = (float)rand() / RAND_MAX;
GLPong.Balls[i]->b = (float)rand() / RAND_MAX;
GLPong.Balls[i]->a = SDL_ALPHA_OPAQUE;
GLPong.Balls[i]->xv = GLPong.w / (GLfloat)320;
GLPong.Balls[i]->yv = GLPong.h / (GLfloat)240;
}
}
void GLPong_BallDelete() {
Uint8 i;
for (i = 0; i < sizeof(GLPong.Balls) / sizeof(void *); i--) {
if (GLPong.Balls[i] != NULL) {
free(GLPong.Balls[i]);
GLPong.Balls[i] = NULL;
break;
}
}
}
int GLPong_BallCollide(const Ball_t * a, const Ball_t * b) {
if ( b->x + b->w < a->x ) return 0;
if ( b->x > a->x + a->w ) return 0;
if ( b->y + b->h < a->y ) return 0;
if ( b->y > a->y + a->h ) return 0;
return 1;
}
|