From f5d2650b972c7c670bf036eb29822283688f9474 Mon Sep 17 00:00:00 2001 From: roshka Date: Mon, 12 Nov 2018 13:59:38 -0300 Subject: [PATCH] JavaCleta 1.0 --- Readme.md | 20 ++++++++++++++++++++ java-e006/.settings/org.eclipse.jdt.core.prefs | 12 ++++++++++++ java-e006/_classpath.xml | 10 ++++++++++ java-e006/_project.xml | 34 ++++++++++++++++++++++++++++++++++ java-e006/bin/Bicicleta.class | Bin 0 -> 1306 bytes java-e006/bin/Something$1.class | Bin 0 -> 1264 bytes java-e006/bin/Something$2.class | Bin 0 -> 1179 bytes java-e006/bin/Something$3.class | Bin 0 -> 2751 bytes java-e006/bin/Something.class | Bin 0 -> 2853 bytes java-e006/bin/bici.png | Bin 0 -> 165620 bytes java-e006/bin/bici2.png | Bin 0 -> 168305 bytes java-e006/bin/fondo.png | Bin 0 -> 1740779 bytes java-e006/src/Bicicleta.java | 37 +++++++++++++++++++++++++++++++++++++ java-e006/src/Something.java | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 14 files changed, 264 insertions(+) create mode 100644 Readme.md create mode 100644 java-e006/.settings/org.eclipse.jdt.core.prefs create mode 100644 java-e006/_classpath.xml create mode 100644 java-e006/_project.xml create mode 100644 java-e006/bin/Bicicleta.class create mode 100644 java-e006/bin/Something$1.class create mode 100644 java-e006/bin/Something$2.class create mode 100644 java-e006/bin/Something$3.class create mode 100644 java-e006/bin/Something.class create mode 100644 java-e006/bin/bici.png create mode 100644 java-e006/bin/bici2.png create mode 100644 java-e006/bin/fondo.png create mode 100644 java-e006/src/Bicicleta.java create mode 100644 java-e006/src/Something.java diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..0895e6b --- /dev/null +++ b/Readme.md @@ -0,0 +1,20 @@ +## Indicaciones + + La carpeta java-e006 contiene la aplicacion. + + El programa fue creado por Eclipse. + + Para ejecutarlo, es necesario abrir la carpeta desde Eclipse. + + +## Controles + + Los controles para mover la bicicleta son: + + * Flechas del teclado: translada la bicicleta de un lugar a otro. + * Control: Mueve la bicicleta en sentido antihorario. + * Alt: Mueve la bicicleta en sentido horario. + +## Observacion + + La bicicleta esta a proposito limitado la zona de movimiento para aumentar el realismo que esta recorriendo en el parque. \ No newline at end of file diff --git a/java-e006/.settings/org.eclipse.jdt.core.prefs b/java-e006/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..a54bb93 --- /dev/null +++ b/java-e006/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=10 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=10 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=10 diff --git a/java-e006/_classpath.xml b/java-e006/_classpath.xml new file mode 100644 index 0000000..d655412 --- /dev/null +++ b/java-e006/_classpath.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/java-e006/_project.xml b/java-e006/_project.xml new file mode 100644 index 0000000..105941e --- /dev/null +++ b/java-e006/_project.xml @@ -0,0 +1,34 @@ + + + java-e006 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + src/bici.png + 1 + /home/hugo/Documentos/bootcamp004/Ejecicios bootcamp/05noviembre/bici.png + + + src/bici2.png + 1 + /home/hugo/Documentos/bootcamp004/Ejecicios bootcamp/05noviembre/bici2.png + + + src/fondo.png + 1 + /home/hugo/Documentos/bootcamp004/Ejecicios bootcamp/01noviembre/fondo.png + + + diff --git a/java-e006/bin/Bicicleta.class b/java-e006/bin/Bicicleta.class new file mode 100644 index 0000000..4d8a743 Binary files /dev/null and b/java-e006/bin/Bicicleta.class differ diff --git a/java-e006/bin/Something$1.class b/java-e006/bin/Something$1.class new file mode 100644 index 0000000..381bea7 Binary files /dev/null and b/java-e006/bin/Something$1.class differ diff --git a/java-e006/bin/Something$2.class b/java-e006/bin/Something$2.class new file mode 100644 index 0000000..d376c8d Binary files /dev/null and b/java-e006/bin/Something$2.class differ diff --git a/java-e006/bin/Something$3.class b/java-e006/bin/Something$3.class new file mode 100644 index 0000000..dba826e Binary files /dev/null and b/java-e006/bin/Something$3.class differ diff --git a/java-e006/bin/Something.class b/java-e006/bin/Something.class new file mode 100644 index 0000000..583ce47 Binary files /dev/null and b/java-e006/bin/Something.class differ diff --git a/java-e006/bin/bici.png b/java-e006/bin/bici.png new file mode 100644 index 0000000..6c2447d Binary files /dev/null and b/java-e006/bin/bici.png differ diff --git a/java-e006/bin/bici2.png b/java-e006/bin/bici2.png new file mode 100644 index 0000000..50bef54 Binary files /dev/null and b/java-e006/bin/bici2.png differ diff --git a/java-e006/bin/fondo.png b/java-e006/bin/fondo.png new file mode 100644 index 0000000..21787bf Binary files /dev/null and b/java-e006/bin/fondo.png differ diff --git a/java-e006/src/Bicicleta.java b/java-e006/src/Bicicleta.java new file mode 100644 index 0000000..1615d54 --- /dev/null +++ b/java-e006/src/Bicicleta.java @@ -0,0 +1,37 @@ +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; + +public class Bicicleta { + private Image bicicleta; + private ImageView mostrarBicicleta; + + public Bicicleta() { + this.bicicleta = new Image("bici.png",160,100,false,true); + this.mostrarBicicleta = new ImageView(bicicleta); + this.mostrarBicicleta.setRotate(0.0); + } + + public void colocarMirarIzquierda(double x,double y) { + this.bicicleta = new Image("bici.png",160,100,false,true); + this.mostrarBicicleta = new ImageView(bicicleta); + this.mostrarBicicleta.setX(x); + this.mostrarBicicleta.setY(y); + } + + public void colocarMirarDerecha(double x,double y) { + this.bicicleta = new Image("bici2.png",160,100,false,true); + this.mostrarBicicleta = new ImageView(bicicleta); + this.mostrarBicicleta.setX(x); + this.mostrarBicicleta.setY(y); + } + + public void girar(double n) { + double rotacion = (n * 180)/Math.PI; + this.mostrarBicicleta.setRotate(rotacion); + } + + public ImageView getImageView() { + return mostrarBicicleta; + } + +} diff --git a/java-e006/src/Something.java b/java-e006/src/Something.java new file mode 100644 index 0000000..a69b601 --- /dev/null +++ b/java-e006/src/Something.java @@ -0,0 +1,151 @@ + + +import java.util.ArrayList; + + + +import javafx.animation.AnimationTimer; +import javafx.application.Application; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.canvas.Canvas; +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.input.KeyEvent; +import javafx.scene.layout.Pane; +import javafx.stage.Stage; + + + +public class Something extends Application{ + //Variables globales a la cual vamos a trabajar + double pos_x = 500; + double pos_y = 400; + int sentido = 0; + double giro = 0.0; + + public static void main(String[] args){ + Application.launch(args); + } + @Override + public void start(Stage stage) { + //Preparamos el escenario + stage.setTitle("Óyeme Carlos llévame en tu Bicicleta"); + Pane root = new Pane(); + Scene scene = new Scene(root); + stage.setScene(scene); + //Preparamos el canvas y agregamos el canvas al escenario + Canvas canvas = new Canvas(1200,680); + //Preparamos las escuchadores del teclado, que nos serviran para mover + //la bicicleta con el teclado + ArrayList entrada = new ArrayList(); + scene.setOnKeyPressed( + new EventHandler() + { + public void handle(KeyEvent e) + { + String codigo = e.getCode().toString(); + if ( !entrada.contains(codigo) ) + entrada.add( codigo ); + } + }); + scene.setOnKeyReleased( + new EventHandler() + { + public void handle(KeyEvent e) + { + String codigo = e.getCode().toString(); + entrada.remove( codigo ); + } + }); + //Cargamos los dibujos al canvas + GraphicsContext gc = canvas.getGraphicsContext2D(); + //Obtenemos la imagen + Image bicicleta = new Image("bici.png",160,100,false,true); + ImageView mostrarBicicleta = new ImageView(bicicleta); + mostrarBicicleta.setX(pos_x); + mostrarBicicleta.setY(pos_y); + mostrarBicicleta.setRotate(0.0); + Image fondo = new Image("fondo.png"); + gc.drawImage(fondo, 0, 0, 1200, 680); + root.getChildren().addAll(canvas,mostrarBicicleta); + //Aqui es donde realizaremos la animacion + new AnimationTimer() + { + public void handle(long currentNanoTime) + { + + if(entrada.contains("LEFT") && entrada.contains("DOWN") ) { + if(pos_x > 0 && pos_y <=430) { + pos_x = pos_x-0.5; + pos_y = pos_y+0.5; + sentido = 0; + giro = Math.PI/4; + } + }else if(entrada.contains("RIGHT") && entrada.contains("DOWN")) { + if(pos_x <= 1060 && pos_y <=430) { + pos_x = pos_x+0.5; + pos_y = pos_y+0.5; + sentido = 1; + giro = -Math.PI/4; + } + }else if(entrada.contains("UP") && entrada.contains("LEFT")) { + if(pos_x<=1060 && pos_x >= 0 && pos_y >=150) { + pos_x = pos_x-0.5; + pos_y = pos_y-0.5; + sentido = 0; + giro = -Math.PI/4; + } + }else if(entrada.contains("UP") && entrada.contains("RIGHT")) { + if(pos_x <= 1060 && pos_y >=150) { + pos_x = pos_x+0.5; + pos_y = pos_y-0.5; + sentido = 1; + giro = Math.PI/4; + } + }else if(entrada.contains("UP")) { + if(pos_y>=150) { + pos_y = pos_y-0.5; + if(sentido == 0) { + giro = -Math.PI/2; + }else { + giro = Math.PI/2; + } + } + }else if(entrada.contains("DOWN")) { + if(pos_y<=430) {//580 + pos_y = pos_y+0.5; + giro = Math.PI/2; + } + }else if(entrada.contains("LEFT")) { + if(pos_x>=0) { + pos_x = pos_x-0.5; + sentido = 0; + giro = 0.0; + } + }else if(entrada.contains("RIGHT")) { + if(pos_x<=1060) { + pos_x = pos_x+0.5; + sentido = 1; + giro = 0.0; + } + }else if(entrada.contains("CONTROL")) { + mostrarBicicleta.setRotate(mostrarBicicleta.getRotate()-0.5); + }else if(entrada.contains("ALT")) { + mostrarBicicleta.setRotate(mostrarBicicleta.getRotate()+0.5); + } + double girar = (giro * 180) / Math.PI; + mostrarBicicleta.setX(pos_x); + mostrarBicicleta.setY(pos_y); + gc.drawImage(fondo, 0, 0, 1200, 680); + gc.fillText("Controles:\n" + + "Control: giro antihorario\n" + + "Alt: giro horario\n" + + "Fechas del teclado: Mueve a la bicicleta", 300, 600); + } + }.start(); + + stage.show(); + } +} \ No newline at end of file -- libgit2 0.26.0