Explosiones con animación, animación del jugador y cambio de tamaño de los Ladrillos
@@ -116,7 +116,7 @@ public class Arkanoid {
|
|||||||
List<Actor> actores = new ArrayList<Actor>();
|
List<Actor> actores = new ArrayList<Actor>();
|
||||||
int anchoJugador = 55;
|
int anchoJugador = 55;
|
||||||
int altoJugador = 15;
|
int altoJugador = 15;
|
||||||
actores.add(new Jugador(anchoJugador, altoJugador, (anchoVentana - anchoJugador) / 2, altoVentana - (altoVentana / 9), ResourceCache.IMAGEN_JUGADOR));
|
actores.add(new Jugador(anchoJugador, altoJugador, (anchoVentana - anchoJugador) / 2, altoVentana - (altoVentana / 9)));
|
||||||
|
|
||||||
int diametroPelota = 20;
|
int diametroPelota = 20;
|
||||||
actores.add(new Pelota(diametroPelota, (anchoVentana - diametroPelota) / 2, 400, ResourceCache.IMAGEN_PELOTA));
|
actores.add(new Pelota(diametroPelota, (anchoVentana - diametroPelota) / 2, 400, ResourceCache.IMAGEN_PELOTA));
|
||||||
@@ -124,7 +124,7 @@ public class Arkanoid {
|
|||||||
|
|
||||||
for (int i = 0; i < ResourceCache.IMAGEN_LADRILLO.length; i++) {
|
for (int i = 0; i < ResourceCache.IMAGEN_LADRILLO.length; i++) {
|
||||||
for (int j = 0; j < numLadrillosPorLinea; j++) {
|
for (int j = 0; j < numLadrillosPorLinea; j++) {
|
||||||
actores.add(new Ladrillo(anchoLadrillos, 10, i, j, separacionBloques, altoVentana / 12, ResourceCache.IMAGEN_LADRILLO));
|
actores.add(new Ladrillo(anchoLadrillos, 15, i, j, separacionBloques, altoVentana / 12, ResourceCache.IMAGEN_LADRILLO));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public class ResourceCache {
|
public class ResourceCache {
|
||||||
|
|
||||||
public static final String IMAGEN_JUGADOR = "Player1.png";
|
|
||||||
public static final String IMAGEN_PELOTA = "Pelota.png";
|
public static final String IMAGEN_PELOTA = "Pelota.png";
|
||||||
public static final String[] IMAGEN_LADRILLO = new String[] {"LadrilloRojo.png", "LadrilloNaranja.png", "LadrilloAmarillo.png", "LadrilloVerde.png", "LadrilloAzul.png", "LadrilloAzulOscuro.png" };
|
public static final String[] IMAGEN_LADRILLO = new String[] {"LadrilloRojo.png", "LadrilloNaranja.png", "LadrilloAmarillo.png", "LadrilloVerde.png", "LadrilloAzul.png" };
|
||||||
|
|
||||||
|
|
||||||
private HashMap<String, BufferedImage> cacheImagenes = new HashMap<>();
|
private HashMap<String, BufferedImage> cacheImagenes = new HashMap<>();
|
||||||
|
|||||||
@@ -18,6 +18,13 @@ public abstract class Actor {
|
|||||||
this.sprite = ResourceCache.getInstance().getImage(imgName);
|
this.sprite = ResourceCache.getInstance().getImage(imgName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Actor(int x, int y, int ancho, int alto) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.ancho = ancho;
|
||||||
|
this.alto = alto;
|
||||||
|
}
|
||||||
|
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
g.drawImage(this.sprite, this.x, this.y, this.ancho, this.alto, null);
|
g.drawImage(this.sprite, this.x, this.y, this.ancho, this.alto, null);
|
||||||
}
|
}
|
||||||
|
|||||||
45
src/main/java/net/h4ckx0r/actores/Explosion.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package net.h4ckx0r.actores;
|
||||||
|
|
||||||
|
import net.h4ckx0r.Arkanoid;
|
||||||
|
import net.h4ckx0r.ResourceCache;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Explosion extends Actor{
|
||||||
|
|
||||||
|
List<BufferedImage> spritesAnimacion = new ArrayList<>();
|
||||||
|
int velocidadCambioSprite = 5;
|
||||||
|
int tiempoSprites = 0;
|
||||||
|
|
||||||
|
public Explosion(int x, int y, int ancho, int alto) {
|
||||||
|
super(x, y, ancho, alto);
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("explosion/sprite-explosion2.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("explosion/sprite-explosion1.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("explosion/sprite-explosion3.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("explosion/sprite-explosion4.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("explosion/sprite-explosion5.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("explosion/sprite-explosion6.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("explosion/sprite-explosion7.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("explosion/sprite-explosion8.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("explosion/sprite-explosion9.png"));
|
||||||
|
this.sprite = this.spritesAnimacion.getFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actua() {
|
||||||
|
if (!this.spritesAnimacion.isEmpty()) {
|
||||||
|
tiempoSprites++;
|
||||||
|
if (tiempoSprites % velocidadCambioSprite == 0){
|
||||||
|
tiempoSprites = 0;
|
||||||
|
int indiceSpriteActual = spritesAnimacion.indexOf(this.sprite);
|
||||||
|
int indiceSiguienteSprite = (indiceSpriteActual + 1) % spritesAnimacion.size();
|
||||||
|
this.sprite = spritesAnimacion.get(indiceSiguienteSprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.sprite.equals(this.spritesAnimacion.getLast())) {
|
||||||
|
Arkanoid.getInstance().eliminaActor(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
package net.h4ckx0r.actores;
|
package net.h4ckx0r.actores;
|
||||||
|
|
||||||
import net.h4ckx0r.Arkanoid;
|
import net.h4ckx0r.Arkanoid;
|
||||||
|
import net.h4ckx0r.ResourceCache;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Jugador extends Actor {
|
public class Jugador extends Actor {
|
||||||
|
|
||||||
@@ -11,8 +15,16 @@ public class Jugador extends Actor {
|
|||||||
|
|
||||||
private int velocidadX = 4;
|
private int velocidadX = 4;
|
||||||
|
|
||||||
public Jugador(int ancho, int alto, int initialX, int initialY, String imgName) {
|
List<BufferedImage> spritesAnimacion = new ArrayList<>();
|
||||||
super(initialX, initialY, ancho, alto, imgName);
|
int velocidadCambioSprite = 5;
|
||||||
|
int tiempoSprites = 0;
|
||||||
|
|
||||||
|
public Jugador(int ancho, int alto, int initialX, int initialY) {
|
||||||
|
super(initialX, initialY, ancho, alto);
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("Player1.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("Player2.png"));
|
||||||
|
this.spritesAnimacion.add(ResourceCache.getInstance().getImage("Player3.png"));
|
||||||
|
this.sprite = this.spritesAnimacion.getFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -24,6 +36,17 @@ public class Jugador extends Actor {
|
|||||||
if (this.x < 0) this.x = 0;
|
if (this.x < 0) this.x = 0;
|
||||||
if (this.x + this.ancho > Arkanoid.getInstance().getCanvas().getWidth())
|
if (this.x + this.ancho > Arkanoid.getInstance().getCanvas().getWidth())
|
||||||
this.x = Arkanoid.getInstance().getCanvas().getWidth() - this.ancho;
|
this.x = Arkanoid.getInstance().getCanvas().getWidth() - this.ancho;
|
||||||
|
|
||||||
|
|
||||||
|
if (!this.spritesAnimacion.isEmpty()) {
|
||||||
|
tiempoSprites++;
|
||||||
|
if (tiempoSprites % velocidadCambioSprite == 0){
|
||||||
|
tiempoSprites = 0;
|
||||||
|
int indiceSpriteActual = spritesAnimacion.indexOf(this.sprite);
|
||||||
|
int indiceSiguienteSprite = (indiceSpriteActual + 1) % spritesAnimacion.size();
|
||||||
|
this.sprite = spritesAnimacion.get(indiceSiguienteSprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void movimientoRaton(int x, int y) {
|
public void movimientoRaton(int x, int y) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class Ladrillo extends Actor {
|
|||||||
public void colisionaCon(Actor a, Rectangle act1Rectangle, Rectangle act2Rectangle) {
|
public void colisionaCon(Actor a, Rectangle act1Rectangle, Rectangle act2Rectangle) {
|
||||||
if (a instanceof Pelota) {
|
if (a instanceof Pelota) {
|
||||||
Arkanoid.getInstance().eliminaActor(this);
|
Arkanoid.getInstance().eliminaActor(this);
|
||||||
|
Arkanoid.getInstance().incorporaActor(new Explosion(this.x, this.y, this.ancho, this.alto));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
src/main/resources/images/explosion/sprite-explosion1.png
Normal file
|
After Width: | Height: | Size: 327 B |
BIN
src/main/resources/images/explosion/sprite-explosion2.png
Normal file
|
After Width: | Height: | Size: 467 B |
BIN
src/main/resources/images/explosion/sprite-explosion3.png
Normal file
|
After Width: | Height: | Size: 658 B |
BIN
src/main/resources/images/explosion/sprite-explosion4.png
Normal file
|
After Width: | Height: | Size: 841 B |
BIN
src/main/resources/images/explosion/sprite-explosion5.png
Normal file
|
After Width: | Height: | Size: 1016 B |
BIN
src/main/resources/images/explosion/sprite-explosion6.png
Normal file
|
After Width: | Height: | Size: 1010 B |
BIN
src/main/resources/images/explosion/sprite-explosion7.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/main/resources/images/explosion/sprite-explosion8.png
Normal file
|
After Width: | Height: | Size: 991 B |
BIN
src/main/resources/images/explosion/sprite-explosion9.png
Normal file
|
After Width: | Height: | Size: 884 B |