Проверить Matter.js
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.

92 lines
3.4KB

  1. function РучноеТело(события) {
  2. this.создать = function() {
  3. //события.подписать(this);
  4. };
  5. /*
  6. this.обработатьСобытие = function(событие) {
  7. if (событие != "игрок начал прыжок")
  8. {
  9. return;
  10. }
  11. события.отписать(this);
  12. this.настроить();
  13. };
  14. */
  15. this.настроить = function()
  16. {
  17. /*
  18. if (!мир.физика.движок)
  19. {
  20. return;
  21. }
  22. */
  23. if (this.настроено)
  24. {
  25. return;
  26. }
  27. this.настроено = true;
  28. // 1.
  29. this.тело1 = Matter.Bodies.rectangle(125, 300, 40, 40, { isSensor: true });
  30. this.элемент1 = document.createElement("div");
  31. document.getElementById("корень").appendChild(this.элемент1);
  32. this.элемент1.style.position = "absolute";
  33. this.элемент1.style.display = "block";
  34. this.элемент1.style.transformOrigin = "center";
  35. this.элемент1.style.width = `40px`;
  36. this.элемент1.style.height = `40px`;
  37. this.элемент1.style.setProperty("background", "url(р/отладка/основа.jpg)");
  38. this.элемент1.style.setProperty("z-index", "100");
  39. // 2.
  40. this.тело2 = Matter.Bodies.rectangle(55, 300, 40, 40, { inertia: Infinity });
  41. this.элемент2 = document.createElement("div");
  42. document.getElementById("корень").appendChild(this.элемент2);
  43. this.элемент2.style.position = "absolute";
  44. this.элемент2.style.display = "block";
  45. this.элемент2.style.transformOrigin = "center";
  46. this.элемент2.style.width = `40px`;
  47. this.элемент2.style.height = `40px`;
  48. this.элемент2.style.setProperty("background", "url(р/отладка/основа.jpg)");
  49. this.элемент2.style.setProperty("z-index", "100");
  50. /*
  51. Matter.Composite.add(мир.физика.движок.world, this.тело1);
  52. Matter.Composite.add(мир.физика.движок.world, this.тело2);
  53. мир.объекты.тела["рт"] = this.тело2;
  54. this.тело = this.тело2;
  55. */
  56. // Compound.
  57. this.тело = Matter.Body.create({
  58. parts: [this.тело1, this.тело2],
  59. inertia: Infinity,
  60. });
  61. Matter.Composite.add(мир.физика.движок.world, this.тело);
  62. мир.объекты.тела["рт"] = this.тело;
  63. мир.объекты.тела["рт1"] = this.тело1;
  64. мир.объекты.имена[this.тело1.id] = "рт1";
  65. мир.объекты.тела["рт2"] = this.тело2;
  66. мир.объекты.имена[this.тело2.id] = "рт2";
  67. };
  68. this.обновить = function()
  69. {
  70. this.настроить();
  71. if (!this.тело)
  72. {
  73. return;
  74. }
  75. мир.синхронизироватьЭлементТело(this.элемент1, this.тело1);
  76. мир.синхронизироватьЭлементТело(this.элемент2, this.тело2);
  77. };
  78. // Конструктор.
  79. this.создать();
  80. }