forked from nestorvc/funJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunObject.java
More file actions
462 lines (409 loc) · 11.9 KB
/
funObject.java
File metadata and controls
462 lines (409 loc) · 11.9 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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
package fun_v01;
import java.awt.Graphics;
import java.awt.Rectangle;
/**
* Esta clase define los objetos 'accionables' de fun.
* Se separa de funSprite ya que acá pueden entrar otro tipo de objetos que
* no necesariamente se usen visualmente en el juego.
* @author Marvin Gonzalez, Kevin Gutierrez, Néstor Villalobos
*/
public abstract class funObject extends funBasic {
//*******************************ATRIBUTOS*******************************//
//***********************************************************************//
//***********************************************************************//
private int alto;
private int ancho;
private int posX;
private int posY;
private Rectangle hitbox;
private double aceleracionX;
private double aceleracionY;
private double arrastre;
private double maxVelocidadX;
private double velocidadX;
private double maxVelocidadY;
private double velocidadY;
private double masa;
private int salud;
private boolean seMueve;
private boolean tieneColisiones;
private funColisiones estaTocando;
private funPhysics fisica;
//******************************CONSTRUCTOR******************************//
//***********************************************************************//
//***********************************************************************//
/**
* El constructor de funObject.
* Adicionalmente a los parámetros que se piden, establece varios otros
* parámetros por default.
* Se establece un Hitbox de proporciones identicas al objeto, esta es la caja
* de colisión del objeto.
* Se establece una aceleraciónX y aceleraciónY de 3.0
* Se establece un arrastre de 6.0
* Se establece una velocidadX y velocidadY de 6.0 y 1.0
* Se establece una maxVelocidadX y maxVelocidadY de 20.0
* Se establece una masa virtual de 6.0
* Se establece una salud de 10.
* Se establece que el objeto se puede mover.
* Se establece que el objeto provoca colisiones en todos sus lados.
* Se establece que el objeto en éste momento no está colisionando con nadie.
* Se establece que está en estado habilitado.
* @param ancho Ancho del objeto.
* @param alto Alto del objeto.
* @param ancho Ancho del objeto.
* @param alto Alto del objeto.
* @param posX Posición en coordenada X del objeto.
* @param posY Posición en coordenada Y del objeto.
*/
public funObject(int ancho, int alto, int posX, int posY) {
super();
this.alto = alto;
this.ancho = ancho;
this.posX = posX;
this.posY = posY;
setBounds(posX, posY, ancho, alto);
setHitbox(new Rectangle(posX - 1, posY - 1, ancho + 2, alto + 2));
setAceleracionX(15.0);
setAceleracionY(15.0);
setArrastre(6.0);
setMaxVelocidadX(30.0);
setVelocidadX(0.0);
setMaxVelocidadY(30.0);
setVelocidadY(0.0);
setMasa(6.0);
setSalud(10);
setSeMueve(true);
setTieneColisiones(true);
setEstaTocando(funColisiones.NINGUNA);
setFisica(new funPhysics(this, posY, velocidadY, posX, velocidadX));
}
//*****************************OTROS MÈTODOS*****************************//
//***********************************************************************//
//***********************************************************************//
/**
* Elimina al objeto del funScreen en el cual esté y cancela todos sus estados.
*/
public boolean matar() {
setAceleracionX(0);
setAceleracionY(0);
setArrastre(0);
setMaxVelocidadX(0);
setVelocidadX(0);
setMaxVelocidadY(0);
setVelocidadY(0);
setMasa(0);
setSalud(0);
setVisible(false);
setSeMueve(false);
setTieneColisiones(false);
return getMadre().eliminarObjeto(this);
}
/**
* Daña al objeto quitándole 1 punto de vida.
* Si el objeto llega a <= 0 de vida, se muere.
*/
public void danar() {
setSalud(getSalud() - 1);
if (getSalud() <= 0) {
matar();
}
}
/**
* Éste es el método que separa a éste objeto de otro cuando hay una colisión.
* Éste método se llama automaticamente en funLaws.revisarColisionesEntre().
* @param otroObjeto El objeto del cual se va a separar.
* @return Si se sepaó o no
*/
public boolean separar(funObject otroObjeto) {
//Código ajeno pero bueno
int lapTop, lapBot, lapLeft, lapRight, small, scootX = 0, scootY = 0;
try {
lapTop = (otroObjeto.getPosY() + otroObjeto.getAlto()) - getPosY();
lapBot = (getPosY() + getAlto()) - otroObjeto.getPosY();
lapLeft = (otroObjeto.getPosX() + otroObjeto.getAncho()) - getPosX();
lapRight = (getPosX() + getAncho()) - otroObjeto.getPosX();
small = 999999999;
//TODO
if (isTieneColisiones()) {
if (lapTop < small) {
small = lapTop;
scootX = 0;
scootY = lapTop;
}
if (lapBot < small) {
small = lapBot;
scootX = 0;
scootY = lapBot * -1;
}
if (lapLeft < small) {
small = lapLeft;
scootX = lapLeft;
scootY = 0;
}
if (lapRight < small) {
small = lapRight;
scootX = lapRight * -1;
scootY = 0;
}
}
} catch (Exception e) {
System.out.println("NOTIFICACION: Hubo problemas separando al objeto " + this + " de " + otroObjeto + ":" + e);
return false;
}
setVelocidadY(0);
setPosX(getPosX() + scootX);
setPosY(getPosY() + scootY);
return true;
}
/**
* Éste método revisa si hay una colision en algún lado del objeto
* @param superficieX La colisión en el lado del objeto
* @return Si hay colisión o no
*/
public boolean hayContactoEn(funColisiones superficieX) {
//TODO
return true;
}
@Override
public abstract void crear();
@Override
public abstract void ejecutor();
@Override
public void actualizar() {
}
@Override
public void paint(Graphics g) {
//TODO
}
//******************************GETS-&-SETS******************************//
//***********************************************************************//
//***********************************************************************//
/**
* @return the alto
*/
public int getAlto() {
return alto;
}
/**
* @param alto the alto to set
*/
public void setAlto(int alto) {
this.alto = alto;
setBounds(getPosX(), getPosY(), getAncho(), alto);
getHitbox().setBounds(getPosX() - 1, getPosY() - 1, getAncho() + 2, alto + 2);
}
/**
* @return the ancho
*/
public int getAncho() {
return ancho;
}
/**
* @param ancho the ancho to set
*/
public void setAncho(int ancho) {
this.ancho = ancho;
setBounds(getPosX(), getPosY(), ancho, getAlto());
getHitbox().setBounds(getPosX() - 1, getPosY() - 1, ancho + 2, getAlto() + 2);
}
/**
* @return the posX
*/
public int getPosX() {
return posX;
}
/**
* @param posX the posX to set
*/
public void setPosX(int posX) {
if (isSeMueve()) {
this.posX = posX;
setBounds(posX, getPosY(), getAncho(), getAlto());
getHitbox().setBounds(posX - 1, getPosY() - 1, getAncho() + 2, getAlto() + 2);
}
}
/**
* @return the posY
*/
public int getPosY() {
return posY;
}
/**
* @param posY the posY to set
*/
public void setPosY(int posY) {
if (isSeMueve()) {
this.posY = posY;
setBounds(getPosX(), posY, getAncho(), getAlto());
getHitbox().setBounds(getPosX() - 1, posY - 1, getAncho() + 2, getAlto() + 2);
}
}
/**
* @return the hitbox
*/
public Rectangle getHitbox() {
return hitbox;
}
/**
* @param hitbox the hitbox to set
*/
public void setHitbox(Rectangle hitbox) {
this.hitbox = hitbox;
}
/**
* @return the aceleracionX
*/
public double getAceleracionX() {
return aceleracionX;
}
/**
* @param aceleracionX the aceleracionX to set
*/
public void setAceleracionX(double aceleracionX) {
this.aceleracionX = aceleracionX;
}
/**
* @return the arrastre
*/
public double getArrastre() {
return arrastre;
}
/**
* @param arrastre the arrastre to set
*/
public void setArrastre(double arrastre) {
this.arrastre = arrastre;
}
/**
* @return the masa
*/
public double getMasa() {
return masa;
}
/**
* @param masa the masa to set
*/
public void setMasa(double masa) {
this.masa = masa;
}
/**
* @return the maxVelocidadX
*/
public double getMaxVelocidadX() {
return maxVelocidadX;
}
/**
* @param maxVelocidadX the maxVelocidadX to set
*/
public void setMaxVelocidadX(double maxVelocidadX) {
this.maxVelocidadX = maxVelocidadX;
}
/**
* @return the salud
*/
public int getSalud() {
return salud;
}
/**
* @param salud the salud to set
*/
public void setSalud(int salud) {
this.salud = salud;
}
/**
* @return the seMueve
*/
public boolean isSeMueve() {
return seMueve;
}
/**
* @param seMueve the seMueve to set
*/
public void setSeMueve(boolean seMueve) {
this.seMueve = seMueve;
}
/**
* @return the velocidadX
*/
public double getVelocidadX() {
return velocidadX;
}
/**
* @param velocidadX the velocidadX to set
*/
public void setVelocidadX(double velocidadX) {
this.velocidadX = velocidadX;
}
/**
* @return the tieneColisiones
*/
public boolean isTieneColisiones() {
return tieneColisiones;
}
/**
* @param tieneColisiones the tieneColisiones to set
*/
public void setTieneColisiones(boolean tieneColisiones) {
this.tieneColisiones = tieneColisiones;
}
/**
* @return the estaTocando
*/
public funColisiones getEstaTocando() {
return estaTocando;
}
/**
* @param estaTocando the estaTocando to set
*/
public void setEstaTocando(funColisiones colision) {
this.estaTocando = colision;
}
/**
* @return the aceleracionY
*/
public double getAceleracionY() {
return aceleracionY;
}
/**
* @param aceleracionY the aceleracionY to set
*/
public void setAceleracionY(double aceleracionY) {
this.aceleracionY = aceleracionY;
}
/**
* @return the maxVelocidadY
*/
public double getMaxVelocidadY() {
return maxVelocidadY;
}
/**
* @param maxVelocidadY the maxVelocidadY to set
*/
public void setMaxVelocidadY(double maxVelocidadY) {
this.maxVelocidadY = maxVelocidadY;
}
/**
* @return the velocidadY
*/
public double getVelocidadY() {
return velocidadY;
}
/**
* @param velocidadY the velocidadY to set
*/
public void setVelocidadY(double velocidadY) {
this.velocidadY = velocidadY;
}
/**
* @return the fisica
*/
public funPhysics getFisica() {
return fisica;
}
/**
* @param fisica the fisica to set
*/
public void setFisica(funPhysics fisica) {
this.fisica = fisica;
}
}