-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCombate.pde
More file actions
394 lines (360 loc) · 10.4 KB
/
Combate.pde
File metadata and controls
394 lines (360 loc) · 10.4 KB
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
// Aqui tenemos toda la logica de la pantalla del combate, es demasiado largo e ineficiente la verdad
// Todas las propiedades de los botones
// Llamarlos
PImage fight;
PImage fight2;
PImage act;
PImage act2;
PImage item;
PImage item2;
PImage mercy;
PImage mercy2;
PImage alma;
// Animar a red
int totalFrames = 44; // Número total de imágenes en la animación
int currentFrame = 0;
PImage[] redImagen = new PImage[totalFrames];
int totalFramesHard = 25;
int currentFrameHard = 0;
PImage[] redHard = new PImage[totalFramesHard];
SoundFile musicaBatalla;
// Posición
int fightX = 83;
int botonY = 490;
// Posición del alma en batalla
int almaX = 390;
int almaY = 360;
int almaXOriginal = 390;
int almaYOriginal = 360;
float centinelaY = 75;
float speed = 0.3;
// Comportamiento
int boton = 1;
int tiempoEspera = 200;
int recuperacion = 0;
int objetoCurativo = 20;
// Turnos
int turnoAtaque;
int turnoCombate;
// Controlar el combate
boolean turnoJugador = true;
boolean finCombate = false;
boolean menuPelea = true;
// La vida en el combate
int vida = 60;
int maxVida = 60; // Para no sobrepasar este límite de vida
// Vida de red
int vidaRed = 180;
int vidaRedMax = 180;
void combate() {
if (combate == true && finCombate == false) {
// Vuelve a aparecer el cursor normal
cursor();
background(0);
botones();
// println(mouseX, mouseY); lo usaba para colocar las cosas
/*
text("Combate", width/2, height/2);
Fue lo primero que puse, le tengo cariño
*/
} else if (finCombate == true ) {
if (vida <= 0) {
musicaBatalla.stop();
GameOver.play();
gameOver();
} else {
musicaBatalla.stop();
victory.play();
victoria();
}
}
}
void musicaBatalla() {
// Inicializar la música de batalla
musicaBatalla = new SoundFile(this, "musica/RedThemeBatlle.mp3");
musicaBatalla.loop();
}
void botones() {
if (finCombate == false) {
// Mueve y muestra cada rayo
for (int i = 0; i < numRayos; i++) {
rayos[i].caer();
rayos[i].mostrar();
}
// Nv 11 = 60hp siguiendo la logica del juego en el que me baso
fill(255);
text("Nv 11", 100, 460);
// Palabras de la vida
fill(255);
text("Life", 280, 460);
text(vida+"/"+maxVida, 540, 460);
// Barra para la vida
if (vida >= maxVida/2) {
fill(0, 255, 0);
} else if (vida >= maxVida/3) {
fill(255, 255, 0);
} else {
fill(255, 0, 0);
}
noStroke();
rect(350, 450, vida*3, 20);
// Dibujar a Red y sus centinelas
animarRed();
image(centinela, 70, centinelaY);
image(centinela, 530, centinelaY);
// Mueve a los centinelas hacia arriba o hacia abajo para simular una minima animacion
centinelaY = centinelaY + speed;
// Cambia la dirección de los centinelas
if (centinelaY <= 75 || centinelaY >= 90) {
speed *= -1;
}
// Barra de la vida de Red
fill(255, 0, 0);
text("Red", 10, 20);
fill(255, 0, 0);
stroke(255);
rect(10, 40, vidaRed, 15);
}
if (turnoJugador) {
moverMenu();
// Dibujar botones
// Boton de pelea
if (boton != 1) {
image(fight, fightX, botonY);
} else {
image(fight2, fightX, botonY);
image(alma, fightX+5, botonY+8);
}
// Boton de actuar
if (boton != 2) {
image(act, fightX+170, botonY);
} else {
image(act2, fightX+170, botonY);
image(alma, fightX+175, botonY+8);
}
// Boton de objetos
if (boton != 3) {
image(item, fightX+340, botonY);
} else {
image(item2, fightX+340, botonY);
image(alma, fightX+345, botonY+8);
}
// Boton de piedad
if (boton != 4) {
image(mercy, fightX+510, botonY);
} else {
image(mercy2, fightX+510, botonY);
image(alma, fightX+515, botonY+8);
}
// Rectángulo del menú
fill(0);
strokeWeight(3);
stroke(255);
rect(50, 335, 680, 100);
// Llamar a las frases para el combate
frases();
} else {
// Rectángulo del combate
fill(0);
strokeWeight(3);
stroke(255);
rect(290, 230, 220, 200);
// Mantener todo para el turno del rival, pero todo en su estado original ya que el boton no deberia estar seleccionado
image(fight, fightX, botonY);
image(act, fightX+170, botonY);
image(item, fightX+340, botonY);
image(mercy, fightX+510, botonY);
// Llamamos a la función para poder movernos en batalla
movimientoBatalla();
boton = 0;
}
// Control de vida del jugador
if (vida > 60) {
vida = 60;
}
if (vida <= 0) {
vida = 0;
musicaBatalla.stop();
finCombate = true;
}
// Controlar la vida de Red
if (vidaRed <= 0) {
musicaBatalla.stop();
finCombate = true;
victoria = true;
}
}
// Tiempo de espera para que el menú no vuele
int tiempoEsperaGlobal = 200;
int ultimoTiempo;
// Esto se usará para todos los botones diferentes al de atacar
boolean ejecutarBotonesEspeciales = false;
int tiempoInicioEspera = -1;
int tiempoTranscurrido;
int ultimoBoton;
// Lógica para movernos por el menú
void moverMenu() {
if (turnoJugador && menuPelea) {
tiempoTranscurrido = millis() - ultimoTiempo;
if (tiempoTranscurrido > tiempoEsperaGlobal) {
if (keyPressed) {
if (keyCode == LEFT) {
boton--;
if (boton < 1) {
boton = 4;
}
} else if (keyCode == RIGHT) {
boton++;
if (boton > 4) {
boton = 1;
}
}
ultimoTiempo = millis();
if (key == 'F' || key == 'f') {
vida -= 40;
}
// Sonido cada vez que te mueves de un botón para otro en el menú
if (keyCode == LEFT || keyCode == RIGHT) { // Si no ponemos esto sonará con cualquier tecla
// Si no se reinicia solo suena una vez
Sonidoboton.play();
}
if (boton == 1 && key == 'z' || boton == 1 && key == 'Z') {
ultimoBoton = boton;
turnoAtaque++;
turnoCombate++;
vidaRed = vidaRed - 18;
reiniciarVariables();
turnoJugador = false;
if (vidaRed <= 0) {
vidaRed = 0;
}
}
if (boton == 2 && key == 'z' || boton == 2 && key == 'Z') {
turnoCombate = turnoAtaque;
turnoAtaque = 10;
menuPelea = false;
tiempoInicioEspera = millis(); // Inicia el temporizador
ejecutarBotonesEspeciales = true;
}
if (boton == 3 && key == 'z' || boton == 3 && key == 'Z') {
if (recuperacion == 0) {
vida = vida + objetoCurativo;
turnoCombate = turnoAtaque;
turnoAtaque = 13;
recuperacion++;
} else if (recuperacion == 1) {
vida = vida + objetoCurativo;
turnoCombate = turnoAtaque;
turnoAtaque = 14;
recuperacion++;
} else if (recuperacion == 2) {
vida = vida + objetoCurativo;
turnoCombate = turnoAtaque;
turnoAtaque = 15;
recuperacion++;
} else {
turnoCombate = turnoAtaque;
turnoAtaque = 11;
}
menuPelea = false;
tiempoInicioEspera = millis(); // Inicia el temporizador
ejecutarBotonesEspeciales = true;
}
if (boton == 4 && key == 'z' || boton == 4 && key == 'Z') {
turnoCombate = turnoAtaque;
turnoAtaque = 12;
menuPelea = false;
tiempoInicioEspera = millis(); // Inicia el temporizador
ejecutarBotonesEspeciales = true;
}
}
}
}
// Botones especiales, es decir, todos los que no sean de atacar
if (ejecutarBotonesEspeciales && millis() - tiempoInicioEspera > tiempoEspera+500) {
botonesEspeciales();
ejecutarBotonesEspeciales = false;
}
}
void animarRed() {
if (vidaRed > vidaRedMax/2) {
PImage redAnimation = redImagen[currentFrame];
// Dibujar la imagen en pantalla
image(redAnimation, 310, 40);
// Incrementar el frame actual para la próxima iteración
currentFrame++;
// Si has alcanzado el último frame, reinicia la animación
if (currentFrame >= totalFrames) {
currentFrame = 0;
}
} else {
PImage redAnimationHard = redHard[currentFrameHard];
// Dibujar la imagen en pantalla
image(redAnimationHard, 310, 40);
// Incrementar el frame actual para la próxima iteración
currentFrameHard++;
// Si has alcanzado el último frame, reinicia la animación
if (currentFrameHard >= totalFramesHard) {
currentFrameHard = 0;
}
}
}
void movimientoBatalla() {
if (!turnoJugador) {
// Llamar en funcion del turno que sea
if (turnoAtaque == 1 || turnoAtaque == 3 || turnoAtaque == 5 || turnoAtaque == 7) {
manejarBolasAtaque();
} else if (turnoAtaque == 9) {
AtaqueRectangulos();
manejarBolasAtaque();
} else {
AtaqueRectangulos();
}
if (!turnoJugador) {
almaPlayer.dibuja();
// Colision de arriba
if (almaPlayer.y >= 235) {
if ( moveUp ) almaPlayer.y = almaPlayer.y - almaPlayer.vel;
}
// Colisión de la derecha
if (almaPlayer.x <= 485) {
if (moveRight) almaPlayer.x = almaPlayer.x + almaPlayer.vel;
}
// Colisión de abajo
if (almaPlayer.y <= 405) {
if ( moveDown ) almaPlayer.y = almaPlayer.y + almaPlayer.vel;
}
// Colisión de la izquierda
if (almaPlayer.x >= 295) {
if (moveLeft) almaPlayer.x = almaPlayer.x - almaPlayer.vel;
}
}
}
}
void keyPressed() {
if (!turnoJugador) {
if (keyCode == UP || keyCode == 'W' || keyCode == 'w') moveUp = true;
if (keyCode == RIGHT || keyCode == 'D' || keyCode == 'd') moveRight = true;
if (keyCode == DOWN || keyCode == 'S' || keyCode == 's') moveDown = true;
if (keyCode == LEFT || keyCode == 'A' || keyCode == 'a') moveLeft = true;
}
}
void keyReleased() {
if (!turnoJugador) {
if (keyCode == UP || keyCode == 'W' || keyCode == 'w') moveUp = false;
if (keyCode == RIGHT || keyCode == 'D' || keyCode == 'd') moveRight = false;
if (keyCode == DOWN || keyCode == 'S' || keyCode == 's') moveDown = false;
if (keyCode == LEFT || keyCode == 'A' || keyCode == 'a') moveLeft = false;
} else {
moveUp = false;
moveRight = false;
moveDown = false;
moveLeft = false;
}
}
void botonesEspeciales() {
reiniciarVariables();
ultimoBoton = boton;
turnoAtaque = turnoCombate;
turnoJugador = false;
}