Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Example by Tom Igoe
  2.  
  3. import processing.serial.*;
  4.  
  5. Serial serial; // The serial port
  6. PFont myFont; // The display font
  7. String inString=""; // Input string from serial port
  8. int lf = 10; // ASCII linefeed
  9. PImage img;
  10. Juego n;
  11. int timeI=0;
  12. boolean presionar=false;
  13. int veces=0;
  14. int prsionar=0;
  15. void setup() {
  16. size(700,400);
  17. // You'll need to make this font with the Create Font Tool
  18. // myFont = loadFont("ArialMS-18.vlw");
  19. //textFont(myFont, 18);
  20. // List all the available serial ports:
  21. println(Serial.list());
  22. // I know that the first port in the serial list on my mac
  23. // is always my Keyspan adaptor, so I open Serial.list()[0].
  24. // Open whatever port is the one you're using.
  25.  
  26.  
  27. serial = new Serial(this, Serial.list()[0], 9600);
  28. // myPort.bufferUntil(lf);
  29. n = new Juego();
  30. timeI=2000;
  31. }
  32.  
  33. void draw() {
  34.  
  35. background(0);
  36.  
  37.  
  38. n.iniciar();
  39.  
  40. if(img!=null)
  41. image(img, 490,100,200,200);
  42. if(presionar){
  43. fill(0,255,0);
  44. prsionar++;
  45. }else{
  46. fill(255,0,0);
  47. }
  48. ellipse(100,200,200,200);
  49.  
  50. delay(1000);
  51. if(inString.length()>0)
  52. veces++;
  53. text("Tiempo Del Anterior: " + inString+" ", 10,70);
  54. inString="";
  55. serial.write('c');
  56. serial.write('b');
  57. inString="";
  58. timeI=0;
  59. }
  60.  
  61. void serialEvent(Serial p) {
  62.  
  63.  
  64. inString += ""+p.readString();
  65. delay(2);
  66. }
  67.  
  68. class Juego{
  69. XML xml;int cont=0;
  70. public Imags[] imagenes;
  71. public Juego(){
  72.  
  73. xml = loadXML("imags.xml");
  74. XML[] children = xml.getChildren("image");
  75. imagenes=new Imags[children.length];
  76. for (int i = 0; i < children.length; i++) {
  77.  
  78. String siono = children[i].getString("presionado");
  79. String name = children[i].getContent();
  80. imagenes[i]=new Imags(name, siono);
  81. }
  82. }
  83. void iniciar(){
  84.  
  85. if(cont>=imagenes.length){
  86. if(veces==prsionar){
  87. println("Acertaste en todos");
  88. veces=0;
  89. prsionar=0;
  90. }
  91. cont=0;
  92. }
  93. img=loadImage(imagenes[cont].darImage());
  94. presionar=imagenes[cont].estaPresionado();
  95. if(timeI!=0)
  96. delay(timeI);
  97.  
  98. serial.write('a');
  99. cont++;
  100. }
  101.  
  102.  
  103. }
  104. class Imags{
  105. public String imagenes="";
  106. public String presionado="";
  107. public Imags(String nimag, String f){
  108. imagenes=nimag;
  109. presionado=f;
  110. }
  111.  
  112. public boolean estaPresionado(){
  113. if(presionado.equals("si"))
  114. return true;
  115. else
  116. return false;
  117. }
  118.  
  119. public String darImage(){
  120. return imagenes;
  121. }
  122.  
  123. }