Versiones 1, 2 y 3
This commit is contained in:
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
||||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
13
.idea/misc.xml
generated
Normal file
13
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="homebrew-23" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
17
pom.xml
Normal file
17
pom.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>net.h4ckx0r</groupId>
|
||||||
|
<artifactId>Arkanoid</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>23</maven.compiler.source>
|
||||||
|
<maven.compiler.target>23</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
185
src/main/java/net/h4ckx0r/Arkanoid.java
Normal file
185
src/main/java/net/h4ckx0r/Arkanoid.java
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
package net.h4ckx0r;
|
||||||
|
|
||||||
|
import net.h4ckx0r.actores.Actor;
|
||||||
|
import net.h4ckx0r.actores.Jugador;
|
||||||
|
import net.h4ckx0r.actores.Ladrillo;
|
||||||
|
import net.h4ckx0r.actores.Pelota;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Arkanoid {
|
||||||
|
|
||||||
|
private static Arkanoid instance = null;
|
||||||
|
|
||||||
|
private static int altoVentana = 700;
|
||||||
|
|
||||||
|
//Para ajustar el ancho de la ventana usar estos valores
|
||||||
|
private static int anchoLadrillos = 40;
|
||||||
|
private static int numLadrillosPorLinea = 10;
|
||||||
|
private static int separacionBloques = 4;
|
||||||
|
|
||||||
|
//No tocar el ancho
|
||||||
|
private static int anchoVentana = separacionBloques + ((anchoLadrillos + separacionBloques) * numLadrillosPorLinea);
|
||||||
|
|
||||||
|
private List<Actor> actores = crearActores();
|
||||||
|
private JFrame ventana = new JFrame("Arkanoid - Natanael Gómez Ortiz");
|
||||||
|
private MiCanvas canvas = new MiCanvas(actores);
|
||||||
|
|
||||||
|
private boolean pausado = false;
|
||||||
|
|
||||||
|
public Arkanoid() {
|
||||||
|
|
||||||
|
ventana.setBounds(100, 100, anchoVentana, altoVentana);
|
||||||
|
ventana.getContentPane().setLayout(new BorderLayout());
|
||||||
|
ventana.getContentPane().add(canvas, BorderLayout.CENTER);
|
||||||
|
ventana.setResizable(false);
|
||||||
|
ventana.setIgnoreRepaint(true);
|
||||||
|
|
||||||
|
ventana.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||||
|
ventana.addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
super.windowClosing(e);
|
||||||
|
cerrarVentana();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
canvas.addMouseMotionListener(new MouseMotionAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
super.mouseMoved(e);
|
||||||
|
Jugador j = (Jugador) actores.getFirst();
|
||||||
|
j.movimientoRaton(e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
super.mouseDragged(e);
|
||||||
|
mouseMoved(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
canvas.addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
super.keyPressed(e);
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||||
|
Jugador j = (Jugador) actores.getFirst();
|
||||||
|
j.movimientoTecladoIzquierda(true);
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||||
|
Jugador j = (Jugador) actores.getFirst();
|
||||||
|
j.movimientoTecladoDerecha(true);
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||||
|
cerrarVentana();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {
|
||||||
|
super.keyReleased(e);
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||||
|
Jugador j = (Jugador) actores.getFirst();
|
||||||
|
j.movimientoTecladoIzquierda(false);
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||||
|
Jugador j = (Jugador) actores.getFirst();
|
||||||
|
j.movimientoTecladoDerecha(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ventana.setVisible(true);
|
||||||
|
canvas.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Arkanoid getInstance() {
|
||||||
|
if (instance == null) instance = new Arkanoid();
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Actor> crearActores() {
|
||||||
|
List<Actor> actores = new ArrayList<Actor>();
|
||||||
|
int anchoJugador = 40;
|
||||||
|
int altoJugador = 10;
|
||||||
|
actores.add(new Jugador(anchoJugador, altoJugador, (anchoVentana - anchoJugador) / 2, altoVentana - (altoVentana / 9)));
|
||||||
|
|
||||||
|
int diametroPelota = 20;
|
||||||
|
actores.add(new Pelota(diametroPelota, (anchoVentana - diametroPelota) / 2, 400));
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < Ladrillo.colores.length; i++) {
|
||||||
|
for (int j = 0; j < numLadrillosPorLinea; j++) {
|
||||||
|
actores.add(new Ladrillo(anchoLadrillos, 10, i, j, separacionBloques));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return actores;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bucleJuego() {
|
||||||
|
int FPS = 60;
|
||||||
|
int milisegundosPorFrame = 1000 / FPS;
|
||||||
|
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
long tiempoInicio = new Date().getTime();
|
||||||
|
|
||||||
|
if (!pausado) {
|
||||||
|
for (Actor actor : actores) {
|
||||||
|
actor.actua();
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
long tiempoTranscurrido = new Date().getTime() - tiempoInicio;
|
||||||
|
int milisPausa = (int) (milisegundosPorFrame - tiempoTranscurrido);
|
||||||
|
milisPausa = Math.max(milisPausa, 0);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(milisPausa);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void cerrarVentana() {
|
||||||
|
Arkanoid.getInstance().pausado = true;
|
||||||
|
int eleccion = JOptionPane.showOptionDialog(Arkanoid.getInstance().ventana, "¿Quiere cerrar el juego?", "Salir de Arkanoid", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[]{"Aceptar", "Cancelar"}, "Cancelar");
|
||||||
|
if (eleccion == 0) {
|
||||||
|
System.exit(0);
|
||||||
|
} else {
|
||||||
|
Arkanoid.getInstance().pausado = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Arkanoid.getInstance().bucleJuego();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public MiCanvas getCanvas() {
|
||||||
|
return canvas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getAltoVentana() {
|
||||||
|
return altoVentana;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getAnchoVentana() {
|
||||||
|
return anchoVentana;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/main/java/net/h4ckx0r/MiCanvas.java
Normal file
25
src/main/java/net/h4ckx0r/MiCanvas.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package net.h4ckx0r;
|
||||||
|
|
||||||
|
import net.h4ckx0r.actores.Actor;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MiCanvas extends Canvas {
|
||||||
|
List<Actor> actores = null;
|
||||||
|
|
||||||
|
public MiCanvas(List<Actor> actores) {
|
||||||
|
this.actores = actores;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
this.setBackground(Color.BLACK);
|
||||||
|
|
||||||
|
for (Actor actor : actores) {
|
||||||
|
actor.paint(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
43
src/main/java/net/h4ckx0r/actores/Actor.java
Normal file
43
src/main/java/net/h4ckx0r/actores/Actor.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package net.h4ckx0r.actores;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public abstract class Actor {
|
||||||
|
int x, y, ancho, alto;
|
||||||
|
|
||||||
|
public abstract void paint(Graphics g);
|
||||||
|
|
||||||
|
public abstract void actua();
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(int x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(int y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAncho() {
|
||||||
|
return ancho;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAncho(int ancho) {
|
||||||
|
this.ancho = ancho;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAlto() {
|
||||||
|
return alto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlto(int alto) {
|
||||||
|
this.alto = alto;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/main/java/net/h4ckx0r/actores/Jugador.java
Normal file
45
src/main/java/net/h4ckx0r/actores/Jugador.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package net.h4ckx0r.actores;
|
||||||
|
|
||||||
|
import net.h4ckx0r.Arkanoid;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class Jugador extends Actor {
|
||||||
|
|
||||||
|
private boolean movIzq = false;
|
||||||
|
private boolean movDer = false;
|
||||||
|
|
||||||
|
private int velocidadX = 4;
|
||||||
|
|
||||||
|
public Jugador(int ancho, int alto, int initialX, int initialY) {
|
||||||
|
this.ancho = ancho;
|
||||||
|
this.alto = alto;
|
||||||
|
this.x = initialX;
|
||||||
|
this.y = initialY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
g.setColor(Color.RED);
|
||||||
|
g.fillRect(this.x, this.y, this.ancho, this.alto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actua() {
|
||||||
|
if (movIzq && this.x > 0) this.x -= velocidadX;
|
||||||
|
if (movDer && this.x + this.ancho < Arkanoid.getAnchoVentana()) this.x += velocidadX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void movimientoRaton(int x, int y) {
|
||||||
|
x = (x - ancho / 2);
|
||||||
|
|
||||||
|
if (x > 0 && x < Arkanoid.getAnchoVentana() - this.ancho) this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void movimientoTecladoDerecha(boolean derecha) {
|
||||||
|
this.movDer = derecha;
|
||||||
|
}
|
||||||
|
public void movimientoTecladoIzquierda(boolean izquierda) {
|
||||||
|
this.movIzq = izquierda;
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/main/java/net/h4ckx0r/actores/Ladrillo.java
Normal file
44
src/main/java/net/h4ckx0r/actores/Ladrillo.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package net.h4ckx0r.actores;
|
||||||
|
|
||||||
|
import net.h4ckx0r.Arkanoid;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class Ladrillo extends Actor {
|
||||||
|
|
||||||
|
public static Color[] colores = new Color[]{Color.RED, Color.YELLOW, Color.PINK, Color.CYAN, Color.GREEN, Color.ORANGE};
|
||||||
|
|
||||||
|
int fila;
|
||||||
|
|
||||||
|
public Ladrillo(int ancho, int alto, int fila, int columna, int separacion) {
|
||||||
|
this.setAncho(ancho);
|
||||||
|
this.setAlto(alto);
|
||||||
|
this.fila = fila;
|
||||||
|
|
||||||
|
this.x = separacion + (columna * ancho) + (separacion * columna);
|
||||||
|
this.y = separacion + (fila * alto) + (separacion * fila) + (Arkanoid.getAltoVentana()/12);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
g.setColor(colores[fila]);
|
||||||
|
|
||||||
|
g.fillRect(this.x, this.y, this.ancho, this.alto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actua() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Ladrillo{" +
|
||||||
|
"fila=" + fila +
|
||||||
|
", x=" + x +
|
||||||
|
", y=" + y +
|
||||||
|
", ancho=" + ancho +
|
||||||
|
", alto=" + alto +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/main/java/net/h4ckx0r/actores/Pelota.java
Normal file
34
src/main/java/net/h4ckx0r/actores/Pelota.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package net.h4ckx0r.actores;
|
||||||
|
|
||||||
|
import net.h4ckx0r.Arkanoid;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class Pelota extends Actor {
|
||||||
|
|
||||||
|
private static int velocidadX = 5;
|
||||||
|
private static int velocidadY = 2;
|
||||||
|
|
||||||
|
public Pelota(int diametro, int initialX, int initialY) {
|
||||||
|
this.ancho = diametro;
|
||||||
|
this.alto = diametro;
|
||||||
|
this.x = initialX;
|
||||||
|
this.y = initialY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.fillOval(this.x, this.y, this.ancho, this.alto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actua() {
|
||||||
|
this.x += Pelota.velocidadX;
|
||||||
|
this.y += Pelota.velocidadY;
|
||||||
|
|
||||||
|
if (this.x + this.ancho >= Arkanoid.getInstance().getCanvas().getWidth()
|
||||||
|
|| this.x <= 0) Pelota.velocidadX = -Pelota.velocidadX;
|
||||||
|
if (this.y + this.alto >= Arkanoid.getInstance().getCanvas().getHeight()
|
||||||
|
|| this.y <= 0) Pelota.velocidadY = -Pelota.velocidadY;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user