forked from TheCBKM/Pong_IT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpingpong.js
67 lines (63 loc) · 1023 Bytes
/
pingpong.js
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
class Ball{
constructor(x,y,r){
this.x=x;
this.y=y;
this.r=r;
this.rr=255;
this.gg=0;
this.bb=0;
}
create(){
fill(this.rr,this.gg,this.bb);
ellipse(this.x,this.y,this.r*2);
}
move(x,y){
this.x=x;
this.y=y;
}
updateColor(r,g,b){
this.rr=r;
this.gg=g;
this.bb=b;
}
}
class Bar{
constructor(x,y,l,b){
this.x=x;
this.y=y;
this.l=l;
this.b=b;
this.m=0;
this.rr=255;
this.gg=255;
this.bb=0;
this.bl=new Ball(this.x,this.y+this.b/2,this.b/2)
this.bl.rr=225;
this.bl.gg=255;
this.bl.bb=0;
this.br=new Ball(this.x+this.l,this.y+this.b/2,this.b/2)
this.br.rr=225;
this.br.gg=255;
this.br.bb=0;
}
create(){
noStroke();
fill(this.rr,this.gg,this.bb);
rect(this.x,this.y,this.l,this.b);
this.bl.create();
this.br.create();
}
updateColor(r,g,b){
this.rr=r;
this.gg=g;
this.bb=b;
}
move(x,y){
this.x=x;
this.y=y;
this.bl.y=this.y+this.b/2;
this.bl.x=this.x;
this.br.y=this.y+this.b/2;
this.br.x=this.x+this.l;
}
}