blob: e5e0a2b66ddccac3288673fc4b5a8f802cde4bf5 (
plain) (
blame)
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
|
#include "raylib.h"
#include "pong.h"
void enemy(struct Players *Enemy, struct Balls ball) {
if (atomic_load(&Ticks) % 1 == 0) {
if (!CheckCollisionRecs(ball.HitBox, Enemy->BallDetector)) {
if (Enemy->Y+120 > ball.Y) {
Enemy->Direction = 0;
} else if (Enemy->Y < ball.Y) {
Enemy->Direction = 1;
}
} else {
Enemy->Direction = 3;
}
}
switch(Enemy->Direction) {
case 0:
Enemy->Y -= 15;
break;
case 1:
Enemy->Y += 15;
break;
default:
break;
}
// Prevents from going off screen.
if ( Enemy->Y > 480 ) {
Enemy->Y = 480;
} else if (Enemy->Y < 0) {
Enemy->Y = 0;
}
Enemy->HitBox.y = Enemy->Y;
Enemy->BallDetector.y = Enemy->Y+80;
return;
}
|