Files
mjs/667.ручноетело.js

92 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function РучноеТело(события) {
this.создать = function() {
//события.подписать(this);
};
/*
this.обработатьСобытие = function(событие) {
if (событие != "игрок начал прыжок")
{
return;
}
события.отписать(this);
this.настроить();
};
*/
this.настроить = function()
{
/*
if (!мир.физика.движок)
{
return;
}
*/
if (this.настроено)
{
return;
}
this.настроено = true;
// 1.
this.тело1 = Matter.Bodies.rectangle(125, 300, 40, 40, { isSensor: true });
this.элемент1 = document.createElement("div");
document.getElementById("корень").appendChild(this.элемент1);
this.элемент1.style.position = "absolute";
this.элемент1.style.display = "block";
this.элемент1.style.transformOrigin = "center";
this.элемент1.style.width = `40px`;
this.элемент1.style.height = `40px`;
this.элемент1.style.setProperty("background", "url(р/отладка/основа.jpg)");
this.элемент1.style.setProperty("z-index", "100");
// 2.
this.тело2 = Matter.Bodies.rectangle(55, 300, 40, 40, { inertia: Infinity });
this.элемент2 = document.createElement("div");
document.getElementById("корень").appendChild(this.элемент2);
this.элемент2.style.position = "absolute";
this.элемент2.style.display = "block";
this.элемент2.style.transformOrigin = "center";
this.элемент2.style.width = `40px`;
this.элемент2.style.height = `40px`;
this.элемент2.style.setProperty("background", "url(р/отладка/основа.jpg)");
this.элемент2.style.setProperty("z-index", "100");
/*
Matter.Composite.add(мир.физика.движок.world, this.тело1);
Matter.Composite.add(мир.физика.движок.world, this.тело2);
мир.объекты.тела["рт"] = this.тело2;
this.тело = this.тело2;
*/
// Compound.
this.тело = Matter.Body.create({
parts: [this.тело1, this.тело2],
inertia: Infinity,
});
Matter.Composite.add(мир.физика.движок.world, this.тело);
мир.объекты.тела["рт"] = this.тело;
мир.объекты.тела["рт1"] = this.тело1;
мир.объекты.имена[this.тело1.id] = "рт1";
мир.объекты.тела["рт2"] = this.тело2;
мир.объекты.имена[this.тело2.id] = "рт2";
};
this.обновить = function()
{
this.настроить();
if (!this.тело)
{
return;
}
мир.синхронизироватьЭлементТело(this.элемент1, this.тело1);
мир.синхронизироватьЭлементТело(this.элемент2, this.тело2);
};
// Конструктор.
this.создать();
}