Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

Nasty tracing code 2
Friday, June 1st, 2012 at 10:02:17am MDT 

  1. /*
  2. ---------------------------------------------------
  3. Variabler for mouseDown(), mouseUp(), trackMouse() og traceComplete()
  4. */
  5. /*
  6. var xList = new Array();        //DETTE ARRAYET SKAL FYLLES MED X-KOORDINATENE FRA KOORDINATFILENE
  7. var yList = new Array();        //DETTE ARRAYET SKAL FYLLES MED Y-KOORDINATENE FRA KOORDINATFILENE
  8. */
  9.  
  10. var xPos;
  11. var yPos;
  12. var i = 0;
  13. var iBreak = 0;
  14. var isMouseDown = false;
  15.  
  16. var points = 0;
  17. var pointCountdown = 100;
  18. var pointsTotal = 0;
  19.  
  20. var canvas = document.getElementById("content");
  21. var ctx = canvas.getContext("2d");
  22. ctx.font="12px Tahoma";
  23. ctx.fillStyle="#FF0000";
  24. ctx.shadowBlur=10;
  25. ctx.shadowOffsetX=10;
  26. ctx.shadowOffsetY=10;
  27. complete = false;
  28. /*
  29. ---------------------------------------------------
  30. Variabler for loadImage()
  31. */
  32. var arrST   =  new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Æ", "Ø", "Å", "Ferdig");
  33. var arrSM   =  new Array("a1", "b1", "c1", "d1", "e1", "f1", "g1", "h1", "i1", "j1", "k1", "l1", "m1", "n1", "o1", "p1", "q1", "r1", "s1", "t1", "u1", "v1", "w1", "x1", "y1", "z1", "æ1", "ø1", "å1", "Ferdig");
  34. var counterST = 0;
  35. var counterSM = 0;
  36. var counter = 0;
  37. var sel;
  38. /*
  39. ---------------------------------------------------
  40. MIDLERTIDIGE ARRAYS KUN FOR DEMOVERSJONEN
  41. Holder koordinatene til A, B, C for enkel fylling av xList og yList
  42. */
  43. var arrayAX = new Array("64","85","106","123","144","163","185","202","225","244","265","285","310","332","348","-","164","203","243","F");
  44. var arrayAY = new Array("427","382","337","294","248","201","153","121","171","211","255","305","347","399","435","-","283","283","283","F");
  45.  
  46. var arrayBX = new Array("118","118","118","118","118","118","118","118","118","118","118","-","117","161","215","250","270","272","251","220", "171","143","193","237","271","283","280","262","230","187","146","118","F");
  47. var arrayBY = new Array("77","111","141","175","208","246","282","313","345","377","408","-","77","75","78","97","133","171","203","230","238","237","239","250","277","313","343","378","400","407","408","408","F");
  48.  
  49. var arrayCX = new Array("327","285","237","185","139","101","79","73","85","114","157","217","288","342","F");
  50. var arrayCY = new Array("98","82","76","83","104","144","191","244","301","345","381","404","407","389","F");
  51.  
  52. //TESTVARIABLER
  53. var xList = arrayAX;
  54. var yList = arrayAY;
  55.  
  56. //DE TO FØLGENDE FUNKSJONER KALLES AV onmousedown OG onmouseup I HTML'EN ( <body onmouseup = mouseUp() onmousedown = mouseDown()> <img onmousemove = trackMouse() /> </body> )
  57. function mouseDown(){
  58.         isMouseDown = true;
  59. }
  60.  
  61. function mouseUp(){
  62.         isMouseDown = false;
  63.         if(!complete){
  64.                 i = iBreak;
  65.                 points = 0;
  66.                 ctx.clearRect(0,0,400,500);
  67.                 ctx.fillText(pointsTotal,130,11);
  68.         }
  69. }
  70.  
  71. function trackMouse(){
  72.         if(isMouseDown){
  73.                 complete = false;
  74.                 xPos = event.pageX;
  75.                 yPos = event.pageY;
  76.                 if(pointCountdown>0){
  77.                         pointCountdown--;
  78.                 }else{
  79.                         isMouseDown = false;
  80.                         i = iBreak;
  81.                 }
  82.                
  83.                 /*
  84.                 //Kode for å tegne streker med musepeker
  85.                 //VIRKER IKKE :(   
  86.                 ctx.strokeStyle = "black";
  87.                 ctx.lineWidth = 3;
  88.                 ctx.lineCap = "round";
  89.                
  90.                 ctx.beginPath();
  91.                 ctx.moveTo(xPos,yPos);
  92.                 ctx.lineTo(xPos+1,yPos+1);
  93.                 ctx.stroke();
  94.                 */
  95.                
  96.                 //Sjekk at både xPos og yPos er i nærheten av neste koordinat i rekkken
  97.                 //"I nærheten" betyr her at det gis en margin på pluss/minus 20 piksler (strekene i bokstavene er ca 50 piksler brede; pluss/minus 20 piksler fra midt i tar deg nesten ut til kanten)
  98.                 if(xPos<=(xList[i]+5) && xPos>=(xList[i]-5)){
  99.                         //xPos er i nærheten, da tester vi yPos - begge må være nært for å passere!
  100.                         if(yPos<=(yList[i]+5) && yPos>=(yList[i]-5)){
  101.                                 //HVIS DU NÅR INN HIT HAR MUSEPEKEREN PASSERT ET CHECKPOINT
  102.                                 i++;
  103.                                
  104.                                 points += pointCountdown; //Gi poeng
  105.                                
  106.                                 pointCountdown = 100; //Nullstill pointCountdown
  107.                                
  108.                                 ctx.clearRect(0,0,400,500);
  109.                                 ctx.fillText(pointsTotal + points,130,11);
  110.                                
  111.                                 //Vi må også sjekke om neste koordinat er et brytningspunkt (at bruker må løfte fingeren av skjermen/musen for å begynne på en ny strek)
  112.                                 //Disse indikeres i koordinatfilene og dermed også i xList og yList som en dash (bindestrek; "-")
  113.                                 if(xList[i] == "-" && yList[i] == "-"){
  114.                                         isMouseDown = false; //Ved å sette isMouseDown til false sørger vi for at trackMouse() ikke gjør noe inntil museknappen slippes og trykkes ned på nytt
  115.                                         i++; //Vi går videre i koordinatene og er klare for ny strek
  116.                                         iBreak = i; //Lagre hvor break'en er...
  117.                                         complete = true; //Første strek er complete, vi setter den til false ved neste klikk...
  118.                                 }else if(xList[i] == "F" && yList[i] == "F"){
  119.                                         traceComplete(); //Hvis bokstaven "F" dukker opp i koordinatarray'et har vi passert siste punkt og trace'en er ferdig. Da kjøres traceComplete()
  120.                                 }
  121.                                 //DU BØR OGSÅ GI VISUELL TILBAKEMELDING PÅ FREMGANG, DETTE GJØR FUNKSJONEN traceProgress()
  122.                                 //traceProgress();
  123.                         }
  124.                 }
  125.         }
  126. }
  127.  
  128. function traceComplete(){
  129.         pointsTotal += points;
  130.         complete = true;
  131.         ctx.clearRect(0,0,400,500);
  132.         i = 0;
  133.         iBreak = 0;
  134.         pointCountdown = 100;
  135.         document.getElementById('content').style.background = "url('./images/finish.png')";
  136.         if(xList == arrayAX){
  137.                 xList = arrayBX;
  138.                 yList = arrayBY;
  139.         }else if(xList == arrayBX){
  140.                 xList = arrayCX;
  141.                 yList = arrayCY;
  142.         }
  143.         setTimeout(function() {loadImage(sel);},5000);
  144. }
  145.  
  146. function loadImage(){
  147.         sel = arguments[0];
  148.         menu = arguments[1];
  149.         if(!complete && pointsTotal > 0 && menu == "m"){
  150.                 pointsTotal = 0;
  151.         }
  152.         complete = false;
  153.         ctx.clearRect(0,0,400,500);
  154.         ctx.fillText(pointsTotal,130,11);
  155.        
  156.         if (sel=="cap"){               
  157.                 if(counterST < arrST.length){
  158.                         var imag = './images/' +arrST[counterST]+'.png';
  159.                         document.getElementById('content').style.background = 'url('+imag+')';
  160.                         /*
  161.                         //Her skal funksjon for å hente tilsvarende koordinater være
  162.                         loadCoordinates(arrST[counterST]);
  163.                         */
  164.                 }else if(counterST == arrST.length){
  165.                         counterST = 0;
  166.                 }
  167.                
  168.                 counterST++;
  169.                 counterSM = 0;
  170.                 counter = 0;
  171.         }else if (sel=="small"){               
  172.                 if(counterSM < arrSM.length){
  173.                         var imag = 'images/' +arrSM[counterSM]+'.png';
  174.                         document.getElementById('content').style.background = 'url('+imag+')';
  175.                         /*
  176.                         //Her skal funksjon for å hente tilsvarende koordinater være
  177.                         loadCoordinates(arrSM[counterSM]);
  178.                         */
  179.                 }else if(counterSM == arrSM.length){
  180.                         counterST = 0;
  181.                 }
  182.                
  183.                 counterSM++;
  184.                 counterST = 0;
  185.                 counter = 0;
  186.         }else if (sel=="num"){
  187.                 if(counter < 10){
  188.                         var imag = 'images/' +counter+'.png';
  189.                         document.getElementById('content').style.background = 'url('+imag+')';
  190.                         /*
  191.                         //Her skal funksjon for å hente tilsvarende koordinater være
  192.                         loadCoordinates(arrST[counter]);
  193.                         */
  194.                 }else if(counter == 10 && sel == "num"){
  195.                         counter = 0;
  196.                         var imag = 'images/' +counter+'.png';
  197.                         document.getElementById('content').style.background = 'url('+imag+')';
  198.                 }
  199.                
  200.                 counter++;
  201.                 counterSM = 0;
  202.                 counterST = 0;
  203.         }else{
  204.                 alert("Invalid command! How did you do that? Naughty, naughty...");
  205.         }
  206. }

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right