home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 51 / Mobiclic51.iso / mac / DATA / COMMUNS / MOBICLIC_MENUS.CST / 00009_Script_moteurs < prev    next >
Text File  |  2003-01-30  |  16KB  |  568 lines

  1. -- affiche un Θlastique entre un objet origine et un objet cible
  2.  
  3. global traitLiaison, volumeOn, menuOuvert
  4.  
  5. on initTraitLiaison sPoint,remplacement
  6.   -- initialisation d'une procΘdure traitLaison
  7.   -- sPoint est le numΘro de la piste portant le point mobile (ex: acteur TrL Point de menu.cst)
  8.   -- remplacement : si 0 l'acteur de la piste sPoint est utilisΘ, 1 il est remplacΘ par l'acteur
  9.   -- de la piste s
  10.   global traitLiaison
  11.   cursor 290
  12.   set s = the currentSpriteNum
  13.   set x = the mouseH
  14.   set y = the mouseV
  15.   if the paramCount =1 then
  16.     set remplacement=0
  17.   end if
  18.   jingle( 2, "poc", "OUT")
  19.   set the rect of sprite (sPoint -1) to rect(x,y,x,y)
  20.   set the locH of sprite sPoint = x
  21.   set the locV of sprite sPoint = y
  22.   if remplacement = 1 then
  23.     sprite(sPoint).member = sprite(s).member
  24.   end if
  25.   afficherPistes (sPoint -1),sPoint
  26.   set traitLiaison = [s,x,y]
  27.   updateStage
  28. end
  29.  
  30. on traitLiaison p1,p2,p3
  31.   -- p1 : piste du trait pente 1 (ex : acteur Trl 1 de la distribution menus.cst)
  32.   -- p2 : piste du trait pente -1  (ex : acteur TrL -1 de la distribution menus.cst)
  33.   -- p3 : piste du point mobile (ex : acteur TrL Point de la distribution menus.cst)
  34.   -- la variable liste traitLiaison contient :
  35.   ---- 1 : piste de l'objet origine
  36.   ---- 2 : locH de l'objet origine
  37.   ---- 3 : locV de l'objet origine
  38.   
  39.   set the locH of sprite p3 = the mouseH
  40.   set the locV of sprite p3 = the mouseV
  41.   set H = the locH of sprite p3
  42.   set V = the locV of sprite p3
  43.   
  44.   if V < getAt(traitLiaison,3) then
  45.     -- le point de choix est plus haut que l'objet de dΘpart
  46.     set y1 = V
  47.     set y2 = getAt(traitLiaison,3)
  48.     if abs(y1-y2)<4 then set y2 = y1 + 4
  49.     
  50.     if H > getAt(traitLiaison,2) then
  51.       -- le point de choix est α droite de l'objet de dΘpart
  52.       set h1 = getAt(traitLiaison,2)
  53.       set h2 = h
  54.       if abs(h1-h2)<4 then set h2 = h1 + 4
  55.       afficherPistes p1
  56.       masquerPistes p2
  57.       set the rect of sprite p1 to rect(h1,y1,h2,y2)
  58.     else
  59.       -- le point de choix est α gauche de l'objet de dΘpart
  60.       set h1 = h
  61.       set h2 = getAt(traitLiaison,2)
  62.       if abs(h1-h2)<4 then set h2 = h1 + 4
  63.       afficherPistes p2
  64.       masquerPistes p1
  65.       set the rect of sprite p2 to rect(h1,y1,h2,y2)
  66.     end if
  67.   else
  68.     -- le point de choix est plus bas que l'objet de dΘpart
  69.     set y1 = getAt(traitLiaison,3)
  70.     set y2 =  V
  71.     if abs(y1-y2)<4 then set y2 = y1 + 4
  72.     if H > getAt(traitLiaison,2) then
  73.       -- le point de choix est α droite de l'objet de dΘpart
  74.       set h1 = getAt(traitLiaison,2)
  75.       set h2 = h
  76.       if abs(h1-h2)<4 then set h2 = h1 + 4
  77.       afficherPistes p2
  78.       masquerPistes p1
  79.       set the rect of sprite p2 to rect(h1,y1,h2,y2)
  80.     else
  81.       -- le point de choix est α gauche de l'objet de dΘpart
  82.       set h1 = h
  83.       set h2 = getAt(traitLiaison,2)
  84.       if abs(h1-h2)<4 then set h2 = h1 + 4
  85.       afficherPistes p1
  86.       masquerPistes p2
  87.       set the rect of sprite p1 to rect(h1,y1,h2,y2)
  88.     end if
  89.   end if
  90.   updateStage
  91. end
  92.  
  93. on glisserDeposer s1,s2,s3,s4,mode
  94.   -- s1 : est la piste cible de plus bas numΘro
  95.   -- s2 : est la piste cible de numΘro le plus ΘlevΘ
  96.   -- s3 : piste acteur α dΘplacer de plus bas numΘro
  97.   -- s4 : piste point en bout d'Θlastique
  98.   -- mode : l'objet dΘplacΘ est supprimΘ si valeur 1, laissΘ en place si 0
  99.   if the paramCount =3 then
  100.     set mode = 0
  101.   end if
  102.   global traitLiaison, choix
  103.   if the visible of sprite s4 = 1 then
  104.     cursor -1
  105.     set s = getAt(traitLiaison,1)
  106.     repeat with i = s1 to s2
  107.       if sprite s4 intersects i then
  108.         -- emplacement occupΘ ? ------------------------------------
  109.         if getAt(choix,i+1-s1)<>0 then
  110.           if mode = 1 then
  111.             afficherPistes s3-1+getAt(choix,i-s1+1)
  112.           end if
  113.         end if
  114.         -- mise en place de l'ΘlΘment glissΘ -----------------------
  115.         set the memberNum of sprite i = the memberNum of sprite s4
  116.         updateStage
  117.         setAt choix,i-s1+1,s-s3+1
  118.         afficherPistes i
  119.         if mode = 1 then
  120.           masquerPistes s
  121.         end if
  122.         updateStage
  123.         puppetSound 2, "poc"
  124.         exit repeat
  125.       end if
  126.     end repeat
  127.     masquerPistes s4-2,s4-1,s4
  128.     -- l'ΘlΘment dΘposΘ n'est en intersection avec aucune zone
  129.     if i=1+s2 then
  130.       
  131.       jingle( 2, "echec_01", "OUT")
  132.     end if
  133.   end if
  134. end
  135.  
  136. on controlePanier
  137.   -- ce script est α recopier et placer dans un bouton au mouseUp
  138.   -- les valeurs utilisΘes sont indicatives
  139.   global choix
  140.   set L =[[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]]
  141.   -- s1 = numΘro de la piste cible de plus bas numΘro 
  142.   set s1 = 20
  143.   -- s2 = numΘro de la piste acteur α glisser la plus basse
  144.   set s2 = 40
  145.   set test = 0
  146.   -- test du premier panier --------------------------
  147.   set L1 = getAt(L,1)
  148.   repeat with i=1 to 3
  149.     if (getAt(choix,i)<>getAt(L1,1)) and (getAt(choix,i)<>getAt(L1,2)) and (getAt(choix,i)<>getAt(L1,3)) then
  150.       set test = 1
  151.       afficherPistes s2-1+getAt(choix,i)
  152.       masquerPistes s1-1+i
  153.       setAt choix,i,0
  154.     end if
  155.   end repeat
  156.   -- test du deuxiΦme panier --------------------------
  157.   set L1 = getAt(L,2)
  158.   repeat with i=4 to 6
  159.     if (getAt(choix,i)<>getAt(L1,1)) and (getAt(choix,i)<>getAt(L1,2)) and (getAt(choix,i)<>getAt(L1,3)) then
  160.       set test = 1
  161.       afficherPistes s2-1+getAt(choix,i)
  162.       masquerPistes s1-1+i
  163.       setAt choix,i,0
  164.     end if
  165.   end repeat
  166.   -- test du troisiΦme panier --------------------------
  167.   set L1 = getAt(L,3)
  168.   repeat with i=7 to 9
  169.     if (getAt(choix,i)<>getAt(L1,1)) and (getAt(choix,i)<>getAt(L1,2)) and (getAt(choix,i)<>getAt(L1,3)) then
  170.       set test = 1
  171.       afficherPistes s2-1+getAt(choix,i)
  172.       masquerPistes s1-1+i
  173.       setAt choix,i,0
  174.     end if
  175.   end repeat
  176.   -- test du quatriΦme panier ---------------------------
  177.   set L1 = getAt(L,4)
  178.   repeat with i=10 to 12
  179.     if (getAt(choix,i)<>getAt(L1,1)) and (getAt(choix,i)<>getAt(L1,2)) and (getAt(choix,i)<>getAt(L1,3)) then
  180.       set test = 1
  181.       afficherPistes s2-1+getAt(choix,i)
  182.       masquerPistes s1-1+i
  183.       setAt choix,i,0
  184.     end if
  185.   end repeat
  186.   -- test du cinquiΦme panier -----------------------------
  187.   set L1 = getAt(L,5)
  188.   repeat with i=13 to 15
  189.     if (getAt(choix,i)<>getAt(L1,1)) and (getAt(choix,i)<>getAt(L1,2)) and (getAt(choix,i)<>getAt(L1,3)) then
  190.       set test = 1
  191.       afficherPistes s2-1+getAt(choix,i)
  192.       masquerPistes s1-1+i
  193.       setAt choix,i,0
  194.     end if
  195.   end repeat
  196.   -- controle final -----------------------------------------
  197.   if test=0 then
  198.     -- son de rΘussite α placer ici
  199.     go to "fin"
  200.   else
  201.    jingle( 2, "echec_01","OUT")
  202.   end if
  203. end
  204.  
  205. -- test clic sur Θcran
  206. on testClic
  207.   if menuOuvert=0 and volumeOn<>1 then
  208.     return 1
  209.   else
  210.     return 0
  211.   end if
  212. end
  213.  
  214. -- repΘrage de coordonnΘes d'acteurs sur la scΦne
  215. on posXY a,b
  216.   -- un champ nommΘ "locHV" doit exister dans la distribution interne
  217.   repeat with i= a to b
  218.     put the locH of sprite i into word 1 of line(i-a+1) of field "locHV"
  219.     put the locV of sprite i into word 2 of line(i-a+1) of field "locHV"
  220.   end repeat
  221. end
  222.  
  223. -- impression de l'Θcran
  224. on imprime
  225.  prevue = the optionDown
  226.   doc = xtra("PrintOMatic").new()
  227.   if not objectP(doc) then exit
  228.   setPrintableMargins doc
  229.   if doPageSetUp (doc) = true then
  230.     newPage doc
  231.     H = getPageWidth(doc)
  232.     V = getPageHeight(doc)
  233.     X =(H-640)/2
  234.     Y =(V-480)/2
  235.     if H>640 then
  236.       drawStagePicture doc, Point(X,Y),Rect(1,1,640,480),true
  237.     else
  238.       drawStagePicture doc, rect(1,1,H,V),Rect(1,1,640,480),true
  239.     end if
  240.     if doJobSetup (doc) = TRUE then
  241.       if prevue = 1 then
  242.         printPreview doc
  243.       else
  244.         setProgressMsg doc , "Impression d'un Θcran Mobiclic en cours... "
  245.         print doc
  246.       end if
  247.     end if
  248.   end if
  249.   doc = 0
  250. end imprime
  251.  
  252. -- impression d'un acteur
  253. on imprimeActeur n,c
  254.   if the paramCount=1 then
  255.     set c=1
  256.   end if
  257.   set prevue = the optionDown
  258.   if prevue=1 then
  259.     printPreview member n of castLib c
  260.   else
  261.     print member n of castLib c
  262.   end if
  263. end imprimeActeur
  264.  
  265. -- impression d'une planche de cartes
  266. -- la zone placΘe sous le rectangle de la piste s est imprimΘe en optimisant
  267. -- le remplissage de la feuille (portrait ou paysage)
  268. on imprimeCartes s
  269.   updateStage
  270.   set prevue = the optionDown
  271.   -- gΘnΘrer le fichier impression si validation du format d'impression
  272.   doc = xtra("PrintOMatic").new()
  273.   if not objectP(doc) then exit
  274.   setPrintableMargins doc
  275.   if doPageSetUp (doc) = true then
  276.     newPage doc
  277.     H = getPageWidth(doc)
  278.     V = getPageHeight(doc)
  279.     H2 = 10+sprite(s).width
  280.     V2 = 10+sprite(s).height
  281.     nx = H/H2
  282.     ny = V/V2
  283.     r = sprite(s).rect
  284.     repeat with y = 1 to ny
  285.       repeat with x = 1 to nx
  286.         drawStagePicture doc, Point(1+(x-1)*H2,1+(y-1)*V2),r,true
  287.       end repeat
  288.     end repeat
  289.     if prevue=1 then
  290.       if doJobSetup (doc) = TRUE then
  291.         printPreview doc
  292.       end if
  293.     else
  294.       if doJobSetup (doc) = TRUE then
  295.         setProgressMsg doc , "Impression en cours... "
  296.         print doc
  297.       end if
  298.     end if
  299.   end if
  300.   doc = 0
  301. end
  302.  
  303. -- temporisation (en secondes)
  304. on temporise t
  305.   t= t*60.0
  306.   d = the timer
  307.   repeat while the timer - d < t
  308.   end repeat
  309. end temporise
  310.  
  311. -- conversion d'un chemin d'accΦs de Mac α Dos
  312. on nomDos nom
  313.   if the machineType = 256 then
  314.     repeat with i=1 to the number of chars of nom
  315.       if char i of nom = ":" then
  316.         put "\" into char i of nom
  317.       end if
  318.     end repeat
  319.   end if
  320.   return nom
  321. end nomDos
  322.  
  323. -- affichage successif des pistes d'un groupe de pistes
  324.  
  325. on choixElements a,b,mode,s
  326.   -- gΦre l'affichage alternatif d'une piste parmi un groupe
  327.   -- de pistes dont les numΘros sont compris entre a et b
  328.   -- mode : 0 passage par un Θtat vide, 1 pas d'Θtat vide
  329.   -- son : 0 pas de son poc, 1 son activΘ (1 par dΘfaut)
  330.   case the paramCount of
  331.     2:set mode=0
  332.       set s=1
  333.     3:set s=1
  334.   end case
  335.   
  336.   repeat with i=a to b
  337.     if the visible of sprite i=1 then
  338.       exit repeat
  339.     end if
  340.   end repeat
  341.   if i=b+1 then
  342.     -- aucune piste n'est affichΘe
  343.     set piste=a
  344.   else
  345.     if i=b then
  346.       -- derniΦre piste affichΘe : selon mode
  347.       if mode=0 then
  348.         set piste=value(field "PPGS")
  349.       else
  350.         set piste=a
  351.       end if
  352.     else
  353.       -- cas gΘnΘral : afficher la piste suivante
  354.       set piste=i+1
  355.     end if
  356.   end if
  357.   -- dissimulation de toutes les pistes
  358.   repeat with i=a to b
  359.     masquerPistes i
  360.   end repeat
  361.   -- affichage de la bonne piste
  362.   if piste<>value(field "PPGS") then
  363.     afficherPistes piste
  364.   end if
  365.   if s=1 then
  366.     sound(2).play(member "poc")
  367.   end if
  368. end
  369.  
  370. -- tirage d'une liste alΘatoire
  371. on randomList nbreElts, nbreMaxi
  372.   -- tirage alΘatoire d'une liste de nombres dont le nombre d'ΘlΘments est nbreElts
  373.   -- et dont chaque valeur est comprise entre 1 et nbreMaxi
  374.   ---- nbreElts = le nombre d'ΘlΘments de la liste
  375.   ---- nbreMaxi = nombre maximum pouvant Ωtre incorporΘ α la liste
  376.   randomList=[]
  377.   if the paramCount=1 then
  378.     nbreMaxi=nbreElts
  379.   end if
  380.   if nbreElts>0 then
  381.     repeat while count(randomList)<nbreElts
  382.       r = random(nbreMaxi)
  383.       if getPos(randomList,r)=0 then
  384.         append randomList, r
  385.       end if
  386.     end repeat
  387.   end if
  388.   return randomList
  389. end
  390.  
  391. -- positions dans liste
  392. on positionsListe liste1
  393.   -- α partir de la liste liste1 construit liste2 telle que les ΘlΘments de liste2
  394.   -- sont les positions occupΘes par les nombres de 1 α n dans liste1
  395.   n = count(liste1)
  396.   liste2=[]
  397.   liste2[n] = 0
  398.   repeat with i=1 to n
  399.     p = getPos(liste1,i)
  400.     liste2[i]=p
  401.   end repeat
  402.   return liste2
  403. end
  404.  
  405. -- somme des termes d'une liste
  406. on sommeListe L
  407.   somme = 0
  408.   repeat with i=1 to count(L)
  409.     somme = somme + L[i]
  410.   end repeat
  411.   return somme
  412. end
  413.  
  414. -- envoi direct d'un mouseUp α une image objet
  415. on click piste
  416.   -- passe le message mouseUp α l'image objet piste
  417.   mouseUp(script (the scriptNum of sprite piste))
  418. end
  419.  
  420. -- teste la visibilitΘ d'un groupe de pistes
  421. on test piste1,piste2
  422.   testM=0
  423.   repeat with i=piste1 to piste2
  424.     testM = testM + sprite(i).visible
  425.   end repeat
  426.   return testM
  427. end
  428.  
  429. -- calcul de la distance entre deux points
  430. on distance x1,y1,x2,y2
  431.   -- calcule la distance entre un point de coordonnΘes (x1,y1)
  432.   -- et un point de coordonnΘes (x2,y2)
  433.   d = sqrt(power(abs(x1-x2),2)+power(abs(y1-y2),2))
  434.   return d
  435. end
  436.  
  437. -- calcul d'angle
  438. on calculAngle centre
  439.   -- centre : numΘro de la piste du point marquant le centre de la rotation
  440.   x1 = the mouseH
  441.   y1 = the mouseV
  442.   x0 = the locH of sprite centre
  443.   y0 = the locV of sprite centre
  444.   if x1=x0 then
  445.     if y1<y0 then
  446.       alpha0 = 0
  447.     else
  448.       alpha0 = 180
  449.     end if
  450.   else
  451.     tgalpha = 1.0*(Y1-Y0)/(X1-X0)
  452.     alpha = atan(tgalpha)
  453.     alpha0 = alpha*180/pi()
  454.     -- calcul de la valeur rΘelle de l'angle
  455.     if x1>x0 then
  456.       alpha0=90+alpha0
  457.     end if
  458.     if x1<x0 then
  459.       alpha0=270+alpha0
  460.     end if
  461.   end if
  462.   return alpha0
  463. end
  464.  
  465. -- conversion de degrΘs en radians
  466. on convDegRad deg
  467.   rad = (deg*(PI))/180.0
  468.   return rad
  469. end
  470.  
  471. -- Importation d'un fichier dans un acteur (nΘcessite fileXtra)
  472. on importer numActeur, type
  473.   -- numActeur est le numΘro de l'acteur dans lequel
  474.   -- doit avoir lieu l'importation
  475.   
  476.   -- teste le numΘro d'acteur pour l'importation
  477.   if value(numActeur)=0 then exit
  478.   -- controle de la prΘsence d'un type de fichier
  479.   if the paramCount=1 then
  480.     set type=""
  481.   else
  482.     set type=string(type)
  483.   end if
  484.   -- affichage d'une boεte de dialogue ouvrir
  485.   put fileopenDialog("",type) into nom
  486.   if nom<> "" then
  487.     importFileInto member numActeur, nom
  488.   end if
  489. end importer
  490.  
  491. -- Enregistrement d'un fichier texte sur le disque
  492. on enregistre acteur,texte1,texte2,mode
  493.   -- nΘcessite fileIO et fileXtra
  494.   -- acteur : numΘro de l'acteur texte α enregistrer
  495.   -- texte1 : nom de fichier par dΘfaut
  496.   -- texte2 : message de la boεte de dialogue
  497.   -- mode : 0 affiche une boite de dialogue
  498.   --        1 enregistre l'acteur au mΩme niveau que le film
  499.   --        2 enregistre l'acteur dans le dossier systΦme
  500.   if the paramCount=3 then
  501.     set mode =0
  502.   end if
  503.   case mode of
  504.     0:-- affichage d'une boεte de dialogue enregistrer sous
  505.       put FileSaveAsDialog(the pathName, texte1, texte2) into cible
  506.     1:-- enregistrement au niveau du film
  507.       set cible = the pathName & texte1
  508.     2:-- enregistrement dans le dossier systΦme
  509.       if the machineType = 256 then
  510.         set cible = getOsDirectory() & "\" & texte1
  511.       else
  512.         set cible = getOsDirectory() & texte1
  513.       end if
  514.   end case
  515.   if cible<>"" then
  516.     set enreg = new(xtra "fileIO")
  517.     createFile(enreg,cible)
  518.     openFile(enreg,cible,2)
  519.     set chaine = field acteur
  520.     writeString(enreg, chaine)
  521.     closeFile(enreg)
  522.   end if
  523. end
  524.  
  525. -- donne le volume de dΘmarrage
  526. on disqueBoot
  527.   if the machineType=256 then
  528.     volume = baSysFolder("windows")
  529.     set disque = volume.char[1..3]
  530.   else
  531.     volume = baSysFolder("prefs")
  532.     set disque = volume.char[1..(offset(":", volume)-1)]
  533.   end if
  534.   return disque
  535. end
  536.  
  537. -- donne l'espace disponible sur le volume de dΘmarrage
  538. on espaceDisque disque
  539.   return baDiskInfo(disque, "free")
  540. end
  541.  
  542. -- copie des textes sur le disque dur
  543. on textes
  544.   global chemin,cheminTextes
  545.   set lTextes=0
  546.   -- repΘrage du chemin d'accΦs au bureau (nΘcessite buddy API)
  547.   set disque=baSysFolder("desktop")
  548.   -- crΘation d'un dossier sur le bureau (nΘcessite filextra)
  549.   if the machineType<>256 then
  550.     -- sur Mac
  551.     set nom = disque & "textesMobiclic:"
  552.     createdirectory nom
  553.     set lTextes=1
  554.   else
  555.     if the platform="Windows,32" then
  556.       -- sous Windows 95 et 98
  557.       set nom = disque & "textesMobiclic\"
  558.       createdirectory nom
  559.       set lTextes=2
  560.     end if
  561.   end if
  562.   -- copie des textes sur le disque dur
  563.   XcopyDirectory cheminTextes, nom
  564.   -- message d'alerte
  565.   alert line lTextes of field "alertes"
  566. end
  567.  
  568.