-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.c
58 lines (56 loc) · 1.19 KB
/
run.c
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
52
53
54
55
56
57
58
#include "run.h"
#include "score.h"
#include <stdio.h>
void mouve(struct Ball* ball)
{
int speed = 10;
if (ball->sens == GAUCHE)
{
ball->coord.x -= speed;
ball->coord.y += ball->varY;
}
else
{
ball->coord.x += speed;
ball->coord.y += ball->varY;
}
}
void runAStep(struct Ball* ball, int posYJ1, int posYJ2, struct Score* score)
{
if(colideRWall(*ball) == 1)
{
if (colideRaquette(posYJ1, *ball))
{
changeDirection(ball);
ball->varY = ((ball->coord.y - posYJ1) - 20)/2.3;
mouve(ball);
}
else
{
score->J2++;
displayScore(*score);
initBall(ball);
}
}
else if(colideRWall(*ball) == 2)
{
if (colideRaquette(posYJ2, *ball))
{
changeDirection(ball);
ball->varY = ((ball->coord.y - posYJ2) - 20)/2.3;
mouve(ball);
}
else
{
score->J1++;
displayScore(*score);
initBall(ball);
}
}
else
{
if (colideWall(*ball) > 0)
ball->varY = - ball->varY;
mouve(ball);
}
}