Advertisement
AdslHouba

CC : Compteur score avec target

Aug 2nd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. os.loadAPI("ahb")
  2. score=0
  3. cibles={
  4.     {
  5.         cote="top",
  6.         coef=1,
  7.         qte=0,
  8.         reds=ahb.addPeripheral("hb_interupteur_28")
  9.     },
  10.     {
  11.         cote="right",
  12.         coef=1.5,
  13.         qte=0,
  14.         reds=ahb.addPeripheral("hb_interupteur_29")
  15.     },
  16.     {
  17.         cote="left",
  18.         coef=2,
  19.         qte=0,
  20.         reds=ahb.addPeripheral("hb_interupteur_30")
  21.     },
  22.     {
  23.         cote="back",
  24.         coef=2.5,
  25.         qte=0,
  26.         reds=ahb.addPeripheral("hb_interupteur_31")
  27.     }
  28. }
  29. cibles[1].reds.pp.set(0)
  30. cibles[2].reds.pp.set(0)
  31. cibles[3].reds.pp.set(0)
  32. cibles[4].reds.pp.set(0)
  33. moniteur=ahb.addPeripheral("monitor_3")
  34. moniteur.pp.setBackgroundColor(colors.black)
  35. moniteur.pp.setTextScale(5)
  36. son=ahb.addPeripheral("noteBlock_1")
  37.  
  38. distri=ahb.addPeripheral("hb_interupteur_36")
  39. distri.pp.set(0)
  40. function cibleSuivante()
  41.     cible=cible+1
  42.     cibles[1].reds.pp.set(0)
  43.     cibles[2].reds.pp.set(0)
  44.     cibles[3].reds.pp.set(0)
  45.     cibles[4].reds.pp.set(0)
  46.     if cible==1 then
  47.         score=0
  48.         moniteur.pp.clear()
  49.         moniteur.pp.setCursorPos(1,1)
  50.         moniteur.pp.write(score)
  51.     end
  52.     if cible<5 then
  53.         distri.pp.set(15)
  54.         os.sleep(0.2)
  55.         distri.pp.set(0)
  56.         os.sleep(0.2)
  57.         distri.pp.set(15)
  58.         os.sleep(0.2)
  59.         distri.pp.set(0)
  60.         print("Cible "..tostring(cible).." "..cibles[cible].cote)
  61.         cibles[cible]['qte']=0
  62.         cibles[cible].reds.pp.set(15)
  63.     else
  64.         cible=0
  65.     end
  66. end
  67. cible=0
  68. while true do
  69.     local event = os.pullEvent("redstone")
  70.     print("Redstone")
  71.     if redstone.getInput("front") then
  72.         cibleSuivante()
  73.     else
  74.         if not(cible==0) then
  75.             cibles[cible]['force']=redstone.getAnalogInput(cibles[cible]["cote"])
  76.             if not(cibles[cible]['force']==0) then
  77.                 print(cibles[cible]['force'])
  78.                 if cibles[cible]['qte']<2 then
  79.                     son.pp.playNote(0,cibles[cible]['force'])                  
  80.                     score=score+(cibles[cible]['force']*cibles[cible]['coef'])
  81.                     moniteur.pp.clear()
  82.                     moniteur.pp.setCursorPos(1,1)
  83.                     moniteur.pp.write(score)
  84.                     cibles[cible]['qte']=cibles[cible]['qte']+1
  85.                     if cibles[cible]['qte']==2 then
  86.                         cibleSuivante()
  87.                     end
  88.                 else
  89.                     cibleSuivante()
  90.                 end
  91.             end
  92.         end
  93.     end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement