-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTarro.java
More file actions
173 lines (133 loc) · 4.7 KB
/
Copy pathTarro.java
File metadata and controls
173 lines (133 loc) · 4.7 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
package puppy.code;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
public class Tarro extends Entidad implements Colisionable {
private Texture imagen;
private Rectangle area;
private int vidas;
private int puntos;
private boolean herido = false;
private long tiempoHeridoInicio = 0L;
private static final long DURACION_HERIDA = 1_000_000_000L;
private float velocidad = 300f;
private float gravedad = -900f;
private float velocidadY = 0f;
private boolean enSuelo = true;
private float rotacion = 0f;
private float rotacionObjetivo = 0f;
private boolean boostActivo = false;
private long tiempoBoostInicio = 0L;
private static final long DURACION_BOOST = 5_000_000_000L;
// -------------------------------------------------------------
// USANDO SINGLETON (no se pasan recursos por parámetro)
// -------------------------------------------------------------
public Tarro() {
super(0, 0);
this.imagen = SpriteManager.getInstance().tarro;
this.vidas = 3;
this.puntos = 0;
float ancho = 48;
float alto = 56;
this.area = new Rectangle(800 / 2f - ancho / 2f, 20, ancho, alto);
}
@Override
public void crear() {
area.x = 800 / 2f - area.width / 2f;
area.y = 20;
velocidadY = 0f;
enSuelo = true;
vidas = 3;
puntos = 0;
herido = false;
boostActivo = false;
}
@Override
public void actualizarMovimiento() {
float delta = Gdx.graphics.getDeltaTime();
if (herido && (System.nanoTime() - tiempoHeridoInicio > DURACION_HERIDA))
herido = false;
if (boostActivo && (System.nanoTime() - tiempoBoostInicio > DURACION_BOOST)) {
boostActivo = false;
velocidad = 300f;
}
boolean moviendo = false;
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
area.x -= velocidad * delta;
rotacionObjetivo = 10f;
moviendo = true;
}
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
area.x += velocidad * delta;
rotacionObjetivo = -10f;
moviendo = true;
}
if (!moviendo)
rotacionObjetivo = 0f;
rotacion += (rotacionObjetivo - rotacion) * 5f * delta;
if (area.x < 0) area.x = 0;
if (area.x > 800 - area.width) area.x = 800 - area.width;
this.x = area.x;
this.y = area.y;
if (!enSuelo) {
velocidadY += gravedad * delta;
area.y += velocidadY * delta;
}
if (area.y <= 20) {
area.y = 20;
velocidadY = 0;
enSuelo = true;
}
}
@Override
public void dibujar(SpriteBatch batch) {
if (herido) {
float t = (System.nanoTime() / 150_000_000) % 2;
batch.setColor(t == 0 ? Color.RED : Color.WHITE);
} else if (boostActivo) {
batch.setColor(Color.CYAN);
} else {
batch.setColor(Color.WHITE);
}
float offsetX = (area.width - 64) / 2f;
float offsetY = (area.height - 64) / 2f;
batch.draw(imagen, area.x + offsetX, area.y + offsetY,
32, 32, 64, 64,
1f, 1f, rotacion,
0, 0, 64, 64,
false, false);
batch.setColor(Color.WHITE);
}
// ----- INTERFAZ -----
@Override
public Rectangle getArea() { return area; }
@Override
public void onColision(Colisionable otro) { // El tarro no reacciona directamente;
// las gotas manejan la lógica de colisión.
}
// ----- Lógica propia -----
public void dañar() {
if (!herido) {
herido = true;
tiempoHeridoInicio = System.nanoTime();
vidas--;
SpriteManager.getInstance().sonidoGotaMala.play(0.35f);
}
}
public void restarVida() { dañar(); }
public void activarBoostVelocidad() {
boostActivo = true;
tiempoBoostInicio = System.nanoTime();
velocidad = 550f;
}
@Override
public void destruir() {
// El tarro no destruye texturas (SpriteManager las maneja)
}
public int getVidas() { return vidas; }
public int getPuntos() { return puntos; }
public void sumarPuntos(int cantidad) { puntos += cantidad; }
}