This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test5.pjs
162 lines (142 loc) · 3.18 KB
/
test5.pjs
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
int bx, by, bz, br;
float dx, dy, dz, dr;
int paddledepth = 160, paddlesize = 100, walldepth = -1000, cameradepth = 200, score;
int speed = 20, counter;
void setup() {
size(window.innerWidth * .95, window.innerHeight * .95, OPENGL);
newgame();
}
void newgame() {
bx = .4*width;
by = .4*height;
bz = walldepth;
dx = 0;
dy = 0;
dz = speed;
dr = speed * 0.005;
score = 0;
}
void draw() {
background(0);
lights();
counter += 1;
// gravity
dy += speed * 0.01;
br += dr;
bx += dx;
by += dy;
bz += dz;
boolean paddling = bx > mouseX - paddlesize/2 && bx < mouseX + paddlesize/2 && by > mouseY - paddlesize/2 && by < mouseY + paddlesize/2;
// collisions
if(bz >= paddledepth && mousePressed) {
// cheating: never miss, random deflection
dx = random(speed/10)-speed/20;
dy = random(speed/3);
dz = -speed;
dr = -dr;
} else if(bz >= paddledepth && bz < paddledepth + 20 && paddling) {
// my paddle
dz = -dz;
dx = (speed/4)*(bx - mouseX)/paddlesize;
dy = (speed)*(by - mouseY)/paddlesize;
dr = -dr;
score++;
} else if(bz < walldepth) {
// opponent
dz = -dz;
dr = -dr;
} else if(by > height) {
// floor
dy = -dy;
by -= 1;
dr = -dr;
}
if(bz >= 1000) {
newgame();
}
//if(bz > paddledepth) {
// losing
// scenes(mouseX,mouseY,500, bx, by, bz);
//} else
//if(mousePressed) {
// cheating
//scenes(width,height, walldepth/2, bx, by, bz);
//} else {
// normal play
scenes(mouseX,mouseY,500, width/2, height/2, -200);
//}
}
void scenes(int x, int y, int z, int tx, int ty, int tz) {
int delta = 5;
smooth();
strokeWeight(1);
noFill();
camera(x-delta, y, z, tx, ty, tz, 0, 1, 0);
stroke(200,0,0);
//fill(200,0,0,20);
scene();
//fill(0,127,103,20);
camera(x+delta, y, z, tx, ty, tz, 0, 1, 0);
stroke(0,127,103);
scene();
}
void scene() {
// sphere has a light source
pointLight(255,255,255,bx,by,bz);
// bouncing sphere
sphereDetail(8);
pushMatrix();
translate(bx,by,bz);
if(by > height*9/10 && bz < paddledepth) {
scale(1, 5.5-5*by/height, 1);
}
rotateX(br);
rotateY(br);
//fill(255,88,0);
sphere(35);
popMatrix();
// distracting cube
pushMatrix();
translate(width*3/4, height/2, -650);
rotateX(PI/4);
rotateZ(PI/3);
//fill(255,255,255,128);
box(90, 60, 150);
popMatrix();
// floor
pushMatrix();
translate(width/2, height, walldepth/2);
box(700,10,walldepth+15);
popMatrix();
// computer's paddle
pushMatrix();
translate(bx, by, walldepth);
//fill(255,55,22,192);
box(paddlesize,paddlesize,10);
popMatrix();
// gameboard divider ("net")
pushMatrix();
translate(width/2, height/2, walldepth/2);
//fill(99,55,22,32);
box(500,700,10);
popMatrix();
// distracting sphere
sphereDetail(10);
pushMatrix();
translate(width/4, height/3, -90);
rotateX(counter/100);
rotateY(counter/150);
//fill(22,55,99);
sphere(120);
popMatrix();
// my paddle (last so alpha works)
pushMatrix();
if(mousePressed) {
translate(bx, by, paddledepth);
} else {
translate(mouseX, mouseY, paddledepth);
}
//fill(255,255,0,32);
box(paddlesize,paddlesize,10);
popMatrix();
}