Commit 18520b1f by Pedro Rolon

Se agregó música de fondo

parent a6178413
......@@ -16,6 +16,9 @@ import javafx.event.EventHandler;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.scene.media.*;
import java.io.File;
import java.io.*;
//import Bicicleta;
public class Something extends Application
......@@ -28,52 +31,35 @@ public class Something extends Application
@Override
public void start(Stage stage)
{
//Variable para la distancia que va a avanzar la bici
double distancia = 10;
Canvas canvas = new Canvas(1300, 800);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setLineWidth(5.0);
//gc.setStroke(Color.BLUE);
//gc.setStroke(Color.BLUE); //Para poner en azul la linea
Pane root = new Pane();
ImageView imagen;
Bicicleta bicicleta = new Bicicleta();
try{
//FileInputStream inputstream = new FileInputStream("file:javacleta.png");
FileInputStream inputstream = new FileInputStream("bici.png");
//se setea el tamaño de la imagen!
Image img = new Image(inputstream, 60, 60, false, false);
//gc.drawImage(img, 0, 0);
//es 350 menos porque se toma en cuenta el tamaño de la imagen!
//gc.drawImage(img, bicicleta.x, 350-bicicleta.y);
imagen = new ImageView(img);
imagen.setX(5+bicicleta.x);
imagen.setY(bicicleta.y-40);
root.getChildren().add(imagen);
/*
mover(gc, bicicleta, 50);
mover(gc, bicicleta, 50, 1.5708);
mover(gc, bicicleta, 50, 0);
mover(gc, bicicleta, 50, 1.5708);
mover(gc, bicicleta, 50, 0);
mover(gc, bicicleta, 50, 1.5708);
mover(gc, bicicleta, 50, 3.14159);
mover(gc, bicicleta, 25, 4.71239);
mover(gc, bicicleta, 100, 0.523599);
mover(gc, bicicleta, 100, 5.23599);
*/
//gc.strokeLine(200, 50, 300, 50);
//gc.strokeLine(0, 0, 300, 50);
......@@ -86,12 +72,56 @@ public class Something extends Application
Button boton6 = new Button();
Button boton7 = new Button();
Button boton8 = new Button();
boton1.setText("NO");
//Setea el texto de los botones
boton1.setText("NO");
boton2.setText("N");
boton3.setText("NE");
boton4.setText("O");
boton5.setText("E");
boton6.setText("SO");
boton7.setText("S");
boton8.setText("SE");
//Se define el tamaño de los botones
boton1.setPrefSize(40, 40);
boton2.setPrefSize(40, 40);
boton3.setPrefSize(40, 40);
boton4.setPrefSize(40, 40);
boton5.setPrefSize(40, 40);
boton6.setPrefSize(40, 40);
boton7.setPrefSize(40, 40);
boton8.setPrefSize(40, 40);
//Se setea la ubicación de los botones
boton1.setLayoutX(0);
boton1.setLayoutY(0);
boton2.setLayoutX(50);
boton2.setLayoutY(0);
boton3.setLayoutX(100);
boton3.setLayoutY(0);
boton4.setLayoutX(0);
boton4.setLayoutY(50);
boton5.setLayoutX(100);
boton5.setLayoutY(50);
boton6.setLayoutX(0);
boton6.setLayoutY(100);
boton7.setLayoutX(50);
boton7.setLayoutY(100);
boton8.setLayoutX(100);
boton8.setLayoutY(100);
//Se agrega el eventHandler a cada boton
//Se setea la acción que va a ejecutar al
//ser Clickeado
boton1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -99,10 +129,6 @@ public class Something extends Application
}
});
boton2.setText("N");
boton2.setPrefSize(40, 40);
boton2.setLayoutX(50);
boton2.setLayoutY(0);
boton2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -110,10 +136,6 @@ public class Something extends Application
}
});
boton3.setText("NE");
boton3.setPrefSize(40, 40);
boton3.setLayoutX(100);
boton3.setLayoutY(0);
boton3.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -121,10 +143,6 @@ public class Something extends Application
}
});
boton4.setText("O");
boton4.setPrefSize(40, 40);
boton4.setLayoutX(0);
boton4.setLayoutY(50);
boton4.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -132,10 +150,6 @@ public class Something extends Application
}
});
boton5.setText("E");
boton5.setPrefSize(40, 40);
boton5.setLayoutX(100);
boton5.setLayoutY(50);
boton5.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -143,10 +157,6 @@ public class Something extends Application
}
});
boton6.setText("SO");
boton6.setPrefSize(40, 40);
boton6.setLayoutX(0);
boton6.setLayoutY(100);
boton6.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -154,10 +164,6 @@ public class Something extends Application
}
});
boton7.setText("S");
boton7.setPrefSize(40, 40);
boton7.setLayoutX(50);
boton7.setLayoutY(100);
boton7.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -165,10 +171,6 @@ public class Something extends Application
}
});
boton8.setText("SE");
boton8.setPrefSize(40, 40);
boton8.setLayoutX(100);
boton8.setLayoutY(100);
boton8.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -177,10 +179,13 @@ public class Something extends Application
});
//Se setea el background de la ventana
root.setStyle("-fx-background-image: url(\"mapamundi.jpg\");");
//Se agrega el canvas al root
root.getChildren().add(canvas);
//Agrega los botones al root
root.getChildren().add(boton1);
root.getChildren().add(boton2);
root.getChildren().add(boton3);
......@@ -190,9 +195,10 @@ public class Something extends Application
root.getChildren().add(boton7);
root.getChildren().add(boton8);
//No sé que hace pero vos podés googlear tigre
Scene scene = new Scene(root);
//Agrega los eventos del teclado numérico
scene.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.NUMPAD1) {
mover(gc, bicicleta, distancia, 3.9269908169775, imagen);
......@@ -227,9 +233,18 @@ public class Something extends Application
});
//Para agregar la música
Media media = new Media(new File("audio.mp3").toURI().toString());
MediaPlayer player = new MediaPlayer(media);
player.setAutoPlay(true);
MediaView mediaView = new MediaView(player);
root.getChildren().add(mediaView);
stage.setScene(scene);
stage.setTitle("Óyeme Carlos llévame en tu Bicicleta");
stage.setTitle("izi pizi me paseo en BICI");
stage.show();
}catch(FileNotFoundException e){
System.out.println("Ocurió un error en la carga de imagen!");
System.out.println(e.getMessage());
......
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment