forked from MrAnyx/Global-Game-Jam-2019-TchipGang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jeu6_ping_pong_jeu_2.pde
122 lines (112 loc) · 2.97 KB
/
jeu6_ping_pong_jeu_2.pde
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
void ping_pong() {
numJeu=6;//jeu numéro 6
textAlign(CENTER, CENTER);
mouton1_6=loadImage("moutonping1.png");
mouton2_6=loadImage("moutonping2.png");
noStroke();
colorMode(RGB);
fill(0, 500);
rect(0, 0, width, height);
colorMode(HSB);
fill(c_6, 1000, 1000);
image(mouton1_6,23, (int)(PlayerPos-70), 65, 140);
image(mouton2_6,1312,(int)(OpponentPos-70), 65, 140);
ellipse(ball.x, ball.y, 30, 30);
stroke(c_6, 1000, 1000);
strokeWeight(3);
line(700, 20, 700, 780);
text(score6, 660, 50);
text(PlayerPoints, 740, 50);
colorMode(RGB);
noFill();
rect(20, 20, 1360, 760);
c_6++;
if (c_6 > 1000) c_6 = 0;
boolean k = false;
if (dist((float)OpponentPos, 0, ball.y, 0) > 50) {
if (ball.y < OpponentPos) {
k = true;
OpponentSpeed-=0.1;
}
if (ball.y > OpponentPos) {
k = true;
OpponentSpeed+=0.8;
}
OpponentSpeed = (double)constrain((float)OpponentSpeed, -12, 12);
}
if (!k) OpponentSpeed*=0.95;
OpponentPos+=OpponentSpeed;
if (OpponentPos > 700) {
OpponentPos = 700;
OpponentSpeed = -OpponentSpeed*0.6;
}
if (OpponentPos < 100) {
OpponentPos = 100;
OpponentSpeed = -OpponentSpeed*0.6;
}
k = false;
if (keyPressed) {
if (keyCode == UP) {
k = true;
PlayerSpeed-=0.6;
}
if (keyCode == DOWN) {
k = true;
PlayerSpeed+=0.6;
}
PlayerSpeed = (double)constrain((float)PlayerSpeed, -12, 12);
}
if (!k) PlayerSpeed*=0.95;
PlayerPos+=PlayerSpeed;
if (PlayerPos > 700) {
PlayerPos = 700;
PlayerSpeed = -PlayerSpeed*0.6;
}
if (PlayerPos < 100) {
PlayerPos = 100;
PlayerSpeed = -PlayerSpeed*0.6;
}
ball.add(ballSpeed);
if (ball.y > 770) {
ball.y = 770;
ballSpeed.y *= -1;
}
if (ball.y < 30) {
ball.y = 30;
ballSpeed.y *= -1;
}
if (ball.x < 65 && ball.x > 35 && ball.y > PlayerPos-85 && ball.y < PlayerPos+85) {
ball.x = 65;
float a = map((float)ball.y, (float)(PlayerPos-85), (float)(PlayerPos+85), -PI/3, PI/3);
ballSpeed.x = cos(a)*10;
ballSpeed.y = sin(a)*10;
}
if (ball.x > 1340 && ball.x < 1350 && ball.y > OpponentPos-85 && ball.y < OpponentPos+85) {
ball.x = 1340;
float a = map((float)ball.y, (float)(OpponentPos-85), (float)(OpponentPos+85), -PI/3, PI/3);
ballSpeed.x = -cos(a)*10;
ballSpeed.y = sin(a)*10;
}
if (ball.x < -15) {
PlayerPoints++;
ball = new PVector(640, 360);
float a = random(-PI/3, PI/3);
ballSpeed.x = cos(a)*10;
if (random(2) < 1) ballSpeed.x *= -1;
ballSpeed.y = sin(a)*10;
}
if (ball.x > 1395) {
score6++;
ball = new PVector(640, 360);
float a = random(-PI/3, PI/3);
ballSpeed.x = cos(a)*10;
if (random(2) < 1) ballSpeed.x *= -1;
ballSpeed.y = sin(a)*10;
}
if(score6==3 || PlayerPoints == 3)
{
score_general[5]=score6;
jeu6=false;
suivant=true;
}
}