1 typedef struct
2 {
3 	int points;
4 	int x, y, mx, my;
5 	SDL_Rect rect;
6 	SDL_Surface *image;
7 	char name[50];
8 	char who_live[50];
9 }object;
10 
11 object adam, david, ball;
12 
13 extern int MOVE_Y;
14 extern SDL_Surface *screen;
15 int M_Y = 7;
16 int difficult = 0;
17 float visible = 0;
18 
ai_check(object * user)19 void ai_check(object * user)
20 {
21 
22 		if((ball.rect.y > (user->rect.y + user->rect.h/2))
23 			&& (user->my != M_Y))
24 			{
25 				if((user->rect.y + user->rect.h + M_Y) < (screen->h - 5))
26 					user->my = M_Y;
27 
28 				else
29 					user->my = -M_Y;
30 			}
31 
32 		if((ball.rect.y < (user->rect.y + user->rect.h/2))
33 			&& (user->my != -M_Y))
34 				user->my = -M_Y;
35 }
36 
ai_move(object * user)37 void ai_move(object * user)
38 {
39 
40 	switch(difficult)
41 	{
42 		case 0: visible = (SCR_X/3.1);
43 			break;
44 		case 1: visible = (SCR_X/3);
45 			break;
46 		case 2: visible = (SCR_X/2.9);
47 			break;
48 		default: break;
49 	}
50 
51 	if(user->rect.x < SCR_X/2)
52 	{
53 		if((ball.rect.x < visible) && (ball.mx < 0))
54 			ai_check(user);
55 
56 		else user->my = 0;
57 	}
58 
59 
60 
61 	if(user->rect.x > SCR_X/2)
62 	{
63 		if(ball.rect.x > (SCR_X - visible) && (ball.mx > 0))
64 			ai_check(user);
65 
66 		else user->my = 0;
67 	}
68 
69 }
70 
71