projet Web 3Mic
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

canvas.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. let canvas = document.getElementById('canvas');
  2. let ctx = canvas.getContext('2d');
  3. //fonction pour dessiner un cube de bois du jeu
  4. function DrawGameCub(ctx, x, y){
  5. const a = 10;
  6. ctx.fillStyle='#DEB887';
  7. ctx.fillRect(x, y, a, a);
  8. ctx.save();
  9. }
  10. //fonction dessiner cube de bois avec img
  11. function imgDrawGameCub(ctx, x,y){
  12. const dim = 100;
  13. let cubebois = new Image();
  14. cubebois.src = //lien de l'image;
  15. cubebois.addEventListener('load',function(){
  16. ctx.drawImage(cubebois,x,y,dim,dim);
  17. },false);
  18. }
  19. //fonction pour dessiner des cercles du jeu
  20. function Drawcircle(ctx, x, y){
  21. //let context=canvas.getContext("2d");
  22. ctx.beginPath();
  23. ctx.lineWidth="2"
  24. ctx.arc(x,y,5, 0, 2*Math.PI);
  25. ctx.fillStyle="grey";
  26. ctx.stroke();
  27. ctx.save();
  28. }
  29. //function pour dessiner des cercles à partir de l'image
  30. function imgDrawcircle(ctx, x,y){
  31. const dim = 100;
  32. let circle = new Image();
  33. circle.src = //lien de l'image;
  34. circle.addEventListener('load',function(){
  35. ctx.drawImage(circle,x,y,dim,dim);
  36. },false);
  37. }
  38. //fonction pour dessiner un cube du labyrinthe
  39. function DrawLabCub(ctx){
  40. const a = 10;
  41. ctx.fillStyle="black";
  42. ctx.fillRect(x, y, a, a);
  43. ctx.save();
  44. }
  45. //inserer l image de Mario
  46. function Mario(ctx, x, y){
  47. const dim = 100;
  48. //let image=document.getElementByid=("id image en html");
  49. let Marioimg = new Image();
  50. Marioimg.src = './mario.png';
  51. //ctx.drawImage(image,x,y,dim,dim);
  52. Marioimg.addEventListener('load',function(){
  53. ctx.drawImage(Marioimg,x,y,dim,dim);
  54. },false);
  55. }
  56. //function généric qui dessine une image
  57. function DrawImg(ctx, tile){
  58. const dim = 20;
  59. let img= new Image();
  60. img.src = tile.image;//lien de l'image;
  61. img.addEventListener('load',function(){
  62. ctx.drawImage(img,tile.x,tile.y,dim,dim);
  63. },false);
  64. ctx.save();
  65. }
  66. //function qui met à jour le canvas
  67. function MajJeu(ctx, Mat){
  68. while(true){
  69. ctx.clearRect(0,0, canvas.width, canvas.height);
  70. let lignes= 0; // à définir plus tard
  71. let colones=0;// à définir plus tard
  72. for (let i=0; i< lignes; i++){
  73. for(let j=0; j< colones; j++){
  74. let obj = Mat[i][j];
  75. DrawImg(obj);
  76. }
  77. }
  78. }
  79. }
  80. DrawGameCub(ctx, 100,100);
  81. Mario(ctx, 200, 100);