Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example by Tom Igoe
- import processing.serial.*;
- Serial serial; // The serial port
- PFont myFont; // The display font
- String inString=""; // Input string from serial port
- int lf = 10; // ASCII linefeed
- PImage img;
- Juego n;
- int timeI=0;
- boolean presionar=false;
- int veces=0;
- int prsionar=0;
- void setup() {
- size(700,400);
- // You'll need to make this font with the Create Font Tool
- // myFont = loadFont("ArialMS-18.vlw");
- //textFont(myFont, 18);
- // List all the available serial ports:
- println(Serial.list());
- // I know that the first port in the serial list on my mac
- // is always my Keyspan adaptor, so I open Serial.list()[0].
- // Open whatever port is the one you're using.
- serial = new Serial(this, Serial.list()[0], 9600);
- // myPort.bufferUntil(lf);
- n = new Juego();
- timeI=2000;
- }
- void draw() {
- background(0);
- n.iniciar();
- if(img!=null)
- image(img, 490,100,200,200);
- if(presionar){
- fill(0,255,0);
- prsionar++;
- }else{
- fill(255,0,0);
- }
- ellipse(100,200,200,200);
- delay(1000);
- if(inString.length()>0)
- veces++;
- text("Tiempo Del Anterior: " + inString+" ", 10,70);
- inString="";
- serial.write('c');
- serial.write('b');
- inString="";
- timeI=0;
- }
- void serialEvent(Serial p) {
- inString += ""+p.readString();
- delay(2);
- }
- class Juego{
- XML xml;int cont=0;
- public Imags[] imagenes;
- public Juego(){
- xml = loadXML("imags.xml");
- XML[] children = xml.getChildren("image");
- imagenes=new Imags[children.length];
- for (int i = 0; i < children.length; i++) {
- String siono = children[i].getString("presionado");
- String name = children[i].getContent();
- imagenes[i]=new Imags(name, siono);
- }
- }
- void iniciar(){
- if(cont>=imagenes.length){
- if(veces==prsionar){
- println("Acertaste en todos");
- veces=0;
- prsionar=0;
- }
- cont=0;
- }
- img=loadImage(imagenes[cont].darImage());
- presionar=imagenes[cont].estaPresionado();
- if(timeI!=0)
- delay(timeI);
- serial.write('a');
- cont++;
- }
- }
- class Imags{
- public String imagenes="";
- public String presionado="";
- public Imags(String nimag, String f){
- imagenes=nimag;
- presionado=f;
- }
- public boolean estaPresionado(){
- if(presionado.equals("si"))
- return true;
- else
- return false;
- }
- public String darImage(){
- return imagenes;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement