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
/
Copy pathtest1b.pjs
102 lines (84 loc) · 1.89 KB
/
test1b.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
int bx, by, bz;
float dx, dy, dz;
int paddledepth = 160, paddlesize = 100, walldepth = -1000, cameradepth = 200, score;
int speed = 20;
void setup() {
size(window.innerWidth * .95, window.innerHeight * .95, OPENGL);
newgame();
PFont fontA = loadFont("Courier New");
textFont(fontA, 36);
}
void newgame() {
bx = .4*width;
by = .4*height;
bz = walldepth;
dx = 0;
dy = 0;
dz = speed;
score = 0;
}
void draw() {
background(0);
lights();
noStroke();
bx += dx;
by += dy;
bz += dz;
if(mousePressed) {
camera(width/2,height/2,500,width/2,height/2,-200, 0, 1, 0);
} else {
camera(mouseX,mouseY,500,width/2,height/2,-200, 0, 1, 0);
}
if((bz == paddledepth && bx > mouseX - paddlesize/2 && bx < mouseX + paddlesize/2 && by > mouseY - paddlesize/2 && by < mouseY + paddlesize/2)) {
dz = -dz;
dx = (speed/4)*(bx - mouseX)/paddlesize;
dy = (speed/4)*(by - mouseY)/paddlesize;
score++;
}
if(bz < walldepth) {
dz = -dz;
}
if(bz >= 600) {
newgame();
}
pointLight(255,255,255,bx,by,bz);
pushMatrix();
translate(bx,by,bz);
fill(255,88,0);
sphere (30);
popMatrix();
pushMatrix();
translate(width*3/4, height/2, -650);
rotateX(PI/4);
rotateZ(PI/3);
fill(255,255,255,128);
box(90, 60, 150);
popMatrix();
pushMatrix();
translate(width/2, height, walldepth/2);
fill(99,55,22,192);
box(700,10,walldepth);
popMatrix();
pushMatrix();
translate(bx, by, walldepth);
fill(255,55,22,192);
box(paddlesize,paddlesize,10);
popMatrix();
pushMatrix();
translate(width/2, height/2, walldepth/2);
fill(99,55,22,32);
box(500,700,10);
popMatrix();
pushMatrix();
translate(width/4, height/3, -90);
fill(22,55,99);
sphere(90);
popMatrix();
pushMatrix();
translate(mouseX, mouseY, paddledepth);
fill(255,255,0,32);
box(paddlesize,paddlesize,10);
stroke();
text("score", 0, -60, 0, 0);
popMatrix();
}