-
Notifications
You must be signed in to change notification settings - Fork 0
/
juegoBola.pde
353 lines (286 loc) · 8.84 KB
/
juegoBola.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
PImage imgD;
PImage imgI;
PImage imgTT;
float hite=70.0; // camera height
float BALL_R=7; // ball radius
int level=0;
int ypos;
int ptsW, ptsH;
final int largoTablero=100;
boolean[][] hueco=new boolean[8][largoTablero];
int numPointsW;
int numPointsH_2pi;
int numPointsH;
float[] coorX;
float[] coorY;
float[] coorZ;
float[] multXZ;
float caida=BALL_R;
boolean gameover=false;
PFont font;
int score=0;
int xPos=300;
int row0=0;
int lastRow0=0;
float xx,yy;
void sortearTablero(int max, int level){
for(int i=0;i<max;i++)
for(int j=0;j<8;j++)
hueco[j][i]=false;
for (int row=0;row<(max/2);row++) {
int ran = (int)random(0,6);
int ran2 = (int)random(0,12);
int ran3 = (int)random(0,18);
int ran4 = (int)random(0,24);
for(int col=0;col<7;col++)
if(col!=ran && col!=ran2 && col!=ran3 && col!=ran4) hueco[col][row*2]=true;
int ranHueco = (int)random(4-level,7);
row+=(int)(ranHueco/2);
}
}
void setup(){
gameover=false;
font=loadFont("2006-48.vlw");
textFont(font,28.0);
imgD = loadImage("Esquiador_dch.png"); // Load the image into the program
imgTT = loadImage("tt.png"); // Load the image into the program
imgI = loadImage("Esquiador_izq.png"); // Load the image into the program
initializeSphere(20, 20);
size(800,700,P3D);
background(0);
sortearTablero(largoTablero,0);
for(int i=0;i<10;i++)
for(int j=0;j<8;j++)
hueco[j][i]=false;
}
void draw(){
camera(0,ypos,hite,0,(ypos+400),0,0,-1,0);
ambientLight(210,220,200);
directionalLight(204, 204, 204, -.7, 1, 1.2);
lightFalloff(1.0, 0.0, 0.0) ;
background(0);
pushMatrix();
textSize(32);
fill(255, 108, 0, 255);
translate(-30,ypos+500,180);
rotateZ(PI);
rotateX((PI*3.0/2.2));
text("TechBossuGame",0,0);
popMatrix();
if(!gameover){
if(score>1000)ypos=(frameCount%20000)*2;
else ypos=(frameCount%20000);
row0=(int)(ypos/20.0)+4;
if(row0!=lastRow0)score+=5;
lastRow0=row0;
float mY=mouseY;
xx = 60-mouseX/4.25; //Ball position left-right
yy = ypos+80+((512.0-mY)/8.0); //Ball position front-back
if(mY>500)mY=500;
if(xx<-60)xx=-60;
}
if(!gameover){
//ellipse(xx,yy,10,10);
pushMatrix();
translate(xx,yy,BALL_R);
rotateX(-frameCount/20.0); // ball roll
//sphereDetail(10);
//fill(190,56,78);
//sphere(BALL_R);
noStroke();
textureSphere(BALL_R, BALL_R, BALL_R, imgTT);
stroke(0);
popMatrix();
pushMatrix();
textSize(32);
fill(255, 108, 0, 255);
translate(150,ypos+300,80);
rotateZ(PI);
rotateX((PI*3.0/2.2));
text("Score: "+score,0,0);
popMatrix();
}else{
//hacer que la bola caiga
pushMatrix();
translate(xx,yy++,caida--);
rotateX(-frameCount/30.0); // ball roll
noStroke();
textureSphere(BALL_R, BALL_R, BALL_R, imgTT);
stroke(0);
popMatrix();
//letreros GameOver
pushMatrix();
textSize(42);
fill(250, 2, 3, 204);
translate(100,ypos+300,80);
rotateZ(PI);
rotateX((PI*3.0/2.2));
text("GAME OVER\n Score: "+score,0,0);
println("GAME OVER"+caida);
popMatrix();
}
println(row0);
if((row0%largoTablero)==largoTablero-26){
sortearTablero(largoTablero-26, (level++)%3);
}
for (int col=0;col<6;col++) {
int x=-60+(20*col);
for (int row=0;row<25;row++) {
int y=20*(row+row0);
// clip to visible region
if(!hueco[col][(row+row0)%largoTablero]){
fill(color(250,250,50),255-((y-ypos)/2));
rect(x,y,20,20);
}
}
}
int row=(int)(yy/20.0);
int col=(int)((xx+60)/20.0);
if(hueco[col][row%largoTablero]){
gameover=true;
}
//println(row+" , "+col+ " | "+ypos+ " , "+row0);
fill(0);
}
void mouseClicked() {
if (gameover) reset();
}
void reset(){
frameCount=0;
score=0;
gameover=false;
caida=BALL_R;
setup();
}
void plotEsquiador(int centerX, int centerY, boolean der){
//triangle(centerX-50,centerY+50,centerX+50,centerY+50,centerX,centerY-50);
if(der)image(imgD, centerX, centerY, imgD.width/20, imgD.height/20);
else image(imgI, centerX, centerY, imgD.width/20, imgD.height/20);
}
void initializeSphere(int numPtsW, int numPtsH_2pi) {
// The number of points around the width and height
numPointsW=numPtsW+1;
numPointsH_2pi=numPtsH_2pi; // How many actual pts around the sphere (not just from top to bottom)
numPointsH=ceil((float)numPointsH_2pi/2)+1; // How many pts from top to bottom (abs(....) b/c of the possibility of an odd numPointsH_2pi)
coorX=new float[numPointsW]; // All the x-coor in a horizontal circle radius 1
coorY=new float[numPointsH]; // All the y-coor in a vertical circle radius 1
coorZ=new float[numPointsW]; // All the z-coor in a horizontal circle radius 1
multXZ=new float[numPointsH]; // The radius of each horizontal circle (that you will multiply with coorX and coorZ)
for (int i=0; i<numPointsW ;i++) { // For all the points around the width
float thetaW=i*2*PI/(numPointsW-1);
coorX[i]=sin(thetaW);
coorZ[i]=cos(thetaW);
}
for (int i=0; i<numPointsH; i++) { // For all points from top to bottom
if (int(numPointsH_2pi/2) != (float)numPointsH_2pi/2 && i==numPointsH-1) { // If the numPointsH_2pi is odd and it is at the last pt
float thetaH=(i-1)*2*PI/(numPointsH_2pi);
coorY[i]=cos(PI+thetaH);
multXZ[i]=0;
}
else {
//The numPointsH_2pi and 2 below allows there to be a flat bottom if the numPointsH is odd
float thetaH=i*2*PI/(numPointsH_2pi);
//PI+ below makes the top always the point instead of the bottom.
coorY[i]=cos(PI+thetaH);
multXZ[i]=sin(thetaH);
}
}
}
void textureSphere(float rx, float ry, float rz, PImage t) {
// These are so we can map certain parts of the image on to the shape
float changeU=t.width/(float)(numPointsW-1);
float changeV=t.height/(float)(numPointsH-1);
float u=0; // Width variable for the texture
float v=0; // Height variable for the texture
beginShape(TRIANGLE_STRIP);
texture(t);
for (int i=0; i<(numPointsH-1); i++) { // For all the rings but top and bottom
// Goes into the array here instead of loop to save time
float coory=coorY[i];
float cooryPlus=coorY[i+1];
float multxz=multXZ[i];
float multxzPlus=multXZ[i+1];
for (int j=0; j<numPointsW; j++) { // For all the pts in the ring
normal(-coorX[j]*multxz, -coory, -coorZ[j]*multxz);
vertex(coorX[j]*multxz*rx, coory*ry, coorZ[j]*multxz*rz, u, v);
normal(-coorX[j]*multxzPlus, -cooryPlus, -coorZ[j]*multxzPlus);
vertex(coorX[j]*multxzPlus*rx, cooryPlus*ry, coorZ[j]*multxzPlus*rz, u, v+changeV);
u+=changeU;
}
v+=changeV;
u=0;
}
endShape();
}
class Generador {
ArrayList<Vec2>lista=new ArrayList<Vec2>();
int[][] laberinto;
private int ancho;
private int largo;
public int[][] generarLaberinto(int ancho, int largo){
this.ancho=ancho;
this.largo = largo;
laberinto = new int[ancho][largo];
generar(1, 1);
return laberinto;
}
private void generar(int x, int z){
//Obtener lista de vecinos aleatorios
ArrayList<Vec2> vecinos = vecinosAleatorios(x, z);
//Para todos los de la lista
for(int i = 0;i<vecinos.size();i++){
Vec2 vecino = vecinos.get(i);
//Si no está visitado
if(!(laberinto[vecino.x][vecino.z]>=1)){
laberinto[vecino.x][vecino.z] = 1;
Vec2 puntoMedio = new Vec2((vecino.x + x)/2, (vecino.z + z)/2);
laberinto[puntoMedio.x][puntoMedio.z] = 1;
lista.add(new Vec2(puntoMedio.x,puntoMedio.z));
lista.add(new Vec2(vecino.x,vecino.z));
//Llamar a generar para ese vecino
generar(vecino.x, vecino.z);
}
}
}
private ArrayList<Vec2> vecinosAleatorios(int x, int z){
boolean limiteDerecho = x >=ancho-3;
boolean limiteAbajo = z <= 1;
boolean limiteIzquierda = x <= 1;
boolean limiteArriba = z >= largo-3;
ArrayList<Vec2> resultado = new ArrayList<Vec2>();
Vec2[] vecinos = new Vec2[4];
vecinos[0] = new Vec2(x, z+2);
vecinos[1] = new Vec2(x+2, z);
vecinos[2] = new Vec2(x-2, z);
vecinos[3] = new Vec2(x, z-2);
if(!limiteArriba){
resultado.add(vecinos[0]);
}
if(!limiteDerecho){
resultado.add(vecinos[1]);
}
if(!limiteIzquierda){
resultado.add(vecinos[2]);
}
if(!limiteAbajo){
resultado.add(vecinos[3]);
}
int ale1 = (int)(Math.random()*20);
for(int i = 0;i<ale1;i++){
int ale2 = (int)(Math.random()*resultado.size());
int ale3 = (int)(Math.random()*resultado.size());
Vec2 uno = resultado.get(ale2);
resultado.set(ale2, resultado.get(ale3));
resultado.set(ale3, uno);
}
return resultado;
}
}
class Vec2 {
int x;
int z;
public Vec2(int x, int z){
this.x=x;
this.z=z;
}
} //