Compare commits
2 Commits
497b40a6e7
...
d21332fe6a
| Author | SHA1 | Date | |
|---|---|---|---|
| d21332fe6a | |||
| 6d8e6e519b |
@@ -97,6 +97,7 @@ public class Arkanoid {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
canvas.crearEstrellas(50, altoVentana, anchoVentana);
|
||||||
ventana.setVisible(true);
|
ventana.setVisible(true);
|
||||||
canvas.requestFocus();
|
canvas.requestFocus();
|
||||||
}
|
}
|
||||||
@@ -119,7 +120,7 @@ public class Arkanoid {
|
|||||||
|
|
||||||
for (int i = 0; i < Ladrillo.colores.length; i++) {
|
for (int i = 0; i < Ladrillo.colores.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));
|
actores.add(new Ladrillo(anchoLadrillos, 10, i, j, separacionBloques, altoVentana/12));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,11 +176,4 @@ public class Arkanoid {
|
|||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getAltoVentana() {
|
|
||||||
return altoVentana;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getAnchoVentana() {
|
|
||||||
return anchoVentana;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,31 @@ import java.util.List;
|
|||||||
public class MiCanvas extends Canvas {
|
public class MiCanvas extends Canvas {
|
||||||
List<Actor> actores = null;
|
List<Actor> actores = null;
|
||||||
|
|
||||||
|
private int[][] estrellitas = null;
|
||||||
|
|
||||||
public MiCanvas(List<Actor> actores) {
|
public MiCanvas(List<Actor> actores) {
|
||||||
this.actores = actores;
|
this.actores = actores;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void crearEstrellas(int numEstrellas, int altoVentana, int anchoVentana) {
|
||||||
|
estrellitas = new int[numEstrellas][2];
|
||||||
|
for (int i = 0; i < estrellitas.length; i++) {
|
||||||
|
int x = (int) (Math.random() * anchoVentana);
|
||||||
|
int y = (int) (Math.random() * altoVentana);
|
||||||
|
estrellitas[i][0] = x;
|
||||||
|
estrellitas[i][1] = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
this.setBackground(Color.BLACK);
|
this.setBackground(Color.BLACK);
|
||||||
|
|
||||||
|
for (int[] estrella : estrellitas) {
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillOval(estrella[0], estrella[1], 2, 2);
|
||||||
|
}
|
||||||
|
|
||||||
for (Actor actor : actores) {
|
for (Actor actor : actores) {
|
||||||
actor.paint(g);
|
actor.paint(g);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ public class Jugador extends Actor {
|
|||||||
@Override
|
@Override
|
||||||
public void actua() {
|
public void actua() {
|
||||||
if (movIzq && this.x > 0) this.x -= velocidadX;
|
if (movIzq && this.x > 0) this.x -= velocidadX;
|
||||||
if (movDer && this.x + this.ancho < Arkanoid.getAnchoVentana()) this.x += velocidadX;
|
if (movDer && this.x + this.ancho < Arkanoid.getInstance().getCanvas().getWidth()) this.x += velocidadX;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void movimientoRaton(int x, int y) {
|
public void movimientoRaton(int x, int y) {
|
||||||
x = (x - ancho / 2);
|
x = (x - ancho / 2);
|
||||||
|
|
||||||
if (x > 0 && x < Arkanoid.getAnchoVentana() - this.ancho) this.x = x;
|
if (x > 0 && x < Arkanoid.getInstance().getCanvas().getWidth() - this.ancho) this.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void movimientoTecladoDerecha(boolean derecha) {
|
public void movimientoTecladoDerecha(boolean derecha) {
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ public class Ladrillo extends Actor {
|
|||||||
|
|
||||||
int fila;
|
int fila;
|
||||||
|
|
||||||
public Ladrillo(int ancho, int alto, int fila, int columna, int separacion) {
|
public Ladrillo(int ancho, int alto, int fila, int columna, int separacion, int separacionSuperior) {
|
||||||
this.setAncho(ancho);
|
this.setAncho(ancho);
|
||||||
this.setAlto(alto);
|
this.setAlto(alto);
|
||||||
this.fila = fila;
|
this.fila = fila;
|
||||||
|
|
||||||
this.x = separacion + (columna * ancho) + (separacion * columna);
|
this.x = separacion + (columna * ancho) + (separacion * columna);
|
||||||
this.y = separacion + (fila * alto) + (separacion * fila) + (Arkanoid.getAltoVentana()/12);
|
this.y = separacion + (fila * alto) + (separacion * fila) + separacionSuperior;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user