-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGota.java
More file actions
57 lines (46 loc) · 1.47 KB
/
Copy pathGota.java
File metadata and controls
57 lines (46 loc) · 1.47 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
package puppy.code;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
public abstract class Gota implements Colisionable {
protected float x, y;
protected float velocidadCaida;
protected Texture imagen;
protected Rectangle area;
public Gota(float x, float y, float velocidadCaida, Texture imagen) {
this.x = x;
this.y = y;
this.velocidadCaida = velocidadCaida;
this.imagen = imagen;
this.area = new Rectangle(x, y, 48, 48);
}
// =====================================================
// TEMPLATE METHOD (NO SE SOBREESCRIBE)
// =====================================================
@Override
public final void onColision(Colisionable otro) {
if (otro instanceof Tarro) {
reproducirSonido();
aplicarEfecto((Tarro) otro);
}
}
// MÉTODOS ABSTRACTOS DEL TEMPLATE
protected abstract void reproducirSonido();
protected abstract void aplicarEfecto(Tarro tarro);
// =====================================================
public void mover(float delta) {
y -= velocidadCaida * delta;
area.y = y;
area.x = x;
}
public void dibujar(SpriteBatch batch) {
batch.draw(imagen, x, y, 48, 48);
}
public boolean fueraPantalla() {
return y + 48 < 0;
}
@Override
public Rectangle getArea() {
return area;
}
}