Advertisement
xerpi

xerpi XkeyBoard

Mar 9th, 2011
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. --cargamos images
  2. seleccion = image.load("imgXkey/cuadrado.png")
  3. --el tiempo para que "parpadee"
  4. tiempo = timer.new()
  5. tiempo:start()
  6. --tablas con los teclados
  7. minus = {
  8. {"q","w","e","r","t","y","u","i","o","p"},
  9. {"a","s","d","f","g","h","j","k","l","ñ"},
  10. {"mayus","z","x","c","v","b","n","m","esp","OK"},
  11. img  = image.load("imgXkey/tecladominus.png")
  12. }
  13. mayus= {
  14. {"Q","W","E","R","T","Y","U","I","O","P"},
  15. {"A","S","D","F","G","H","J","K","L","Ñ"},
  16. {"num","Z","X","C","V","B","N","M","esp","OK"},
  17. img = image.load("imgXkey/tecladomayus.png")
  18. }
  19. num= {
  20. {"0","1","2","3","4","5","6","7","8","9"},
  21. {".",",","-","_","(",")","[","]","!","?"},
  22. {"minus","á","é","í","ó","ú","`","´","esp","OK"},
  23. img = image.load("imgXkey/tecladosimb.png")
  24. }
  25.  
  26. function xkeyboard(Xteclado,Yteclado,Xtexto,Ytexto,texto,comentario)
  27. --hacemos captura
  28. local tmp = screen.toimage()
  29. --definimos la posicion del "seleccionador " del teclado
  30. local x=1
  31. local y=1
  32. --empezamos con el teclado minusculas
  33. local tecladoactual=minus
  34. --para que "texto,comentario" sea opcional
  35. if not texto then texto = "" end
  36. if not comentario then comentario = "" end
  37.  
  38. while true do
  39. --leemos controles y bliteamos la captura previamente hecha antes de entrar en el bucle
  40. controls.read()
  41. tmp:blit(0,0)
  42.  
  43. --si pulsanmos un boton que se mueva el "seleccionador"
  44. if controls.press("right") then x=x+1 end
  45. if controls.press("left") then x=x-1 end
  46. if controls.press("up") then y=y-1 end
  47. if controls.press("down") then y=y+1 end
  48.  
  49. --limites para el seleccionador
  50. if y>=4 then y=1 end
  51. if y<=0 then y=3 end
  52. if x>=11 then x=1 end
  53. if x<=0 then x=10 end
  54.  
  55. --si pulsamos cruz que escriba que haga lo que tenga que hacer
  56. if controls.press("cross") then
  57.     if tecladoactual[y][x] != "mayus" and tecladoactual[y][x] != "minus" and tecladoactual[y][x] != "num" and
  58.     tecladoactual[y][x] != "esp" and tecladoactual[y][x] != "OK" then texto = texto..tecladoactual[y][x] end
  59.     if tecladoactual[y][x] == "mayus" then tecladoactual = num
  60.     elseif tecladoactual[y][x] == "num" then tecladoactual = minus
  61.     elseif tecladoactual[y][x] == "minus" then tecladoactual = mayus
  62.     elseif tecladoactual[y][x] == "OK" then break
  63.     elseif tecladoactual[y][x] == "esp" then texto = texto.." " end
  64. end
  65.  
  66. --complementa a la parida monumental
  67. if controls.cross() then screen.print(Xtexto+screen.textwidth(comentario..texto,0.7),Ytexto,"|") end
  68. --para poder eliminar una letra
  69. if controls.press("square") then texto = string.sub(texto,1,#texto-1) end
  70. --poner un espacio
  71. if controls.press("triangle") then texto = texto.." " end
  72. --eliminar todo
  73. if controls.press("circle") then texto = "" end
  74. --cambiar de teclado pulsando select
  75. if controls.press("select") then
  76.     if tecladoactual ==  mayus then tecladoactual = num
  77.     elseif tecladoactual == num then tecladoactual = minus
  78.     elseif tecladoactual == minus then tecladoactual = mayus end   
  79. end
  80. --mover el teclado con el joystick
  81. if math.abs(controls.analogx())>15 then Xteclado = Xteclado + controls.analogx()/10 end
  82. if math.abs(controls.analogy())>15 then Yteclado = Yteclado + controls.analogy()/10 end
  83. --imprimir y blitear el teclado, el "seleccionador" y el texto k tamos escribiendo
  84. tecladoactual.img:blit(Xteclado,Yteclado)
  85. seleccion:blit(Xteclado+(21*x)-10,Yteclado+(21*y)-(9+y))
  86. screen.print(Xtexto,Ytexto,comentario..texto)
  87.  
  88. --bye bye teclado
  89. if controls.press("start") then
  90.          tmp:free()
  91.          break       
  92. end
  93.  
  94. screen.print(5,5,tiempo:time())------------------------------------------------------------
  95.  
  96. --parida monumental(hace el efecto de barra parpadeante)
  97. if not controls.cross() and tiempo:time() >= 0 and tiempo:time() < 500 then
  98.     screen.print(Xtexto+screen.textwidth(comentario..texto,0.7),Ytexto,"|")
  99. elseif tiempo:time() >= 1000 then tiempo:reset()
  100. end
  101.  
  102. --flipeamos un poko
  103. screen.flip()
  104. if controls.press("l") then xerpi() end ----------------------------------------------------
  105. end
  106. return texto
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement