47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
function РучноеТело(события) {
|
||
this.создать = function() {
|
||
события.подписать(this);
|
||
};
|
||
|
||
this.обработатьСобытие = function(событие) {
|
||
if (событие != "игрок начал прыжок")
|
||
{
|
||
return;
|
||
}
|
||
события.отписать(this);
|
||
this.настроить();
|
||
};
|
||
|
||
this.настроить = function()
|
||
{
|
||
|
||
var физика = {
|
||
inertia: Infinity,
|
||
};
|
||
this.тело = Matter.Bodies.rectangle(1200, 300, 40, 40, физика);
|
||
Matter.Composite.add(мир.физика.движок.world, this.тело);
|
||
|
||
this.элемент = document.createElement("div");
|
||
document.getElementById("корень").appendChild(this.элемент);
|
||
this.элемент.id = `рт`;
|
||
this.элемент.style.position = "absolute";
|
||
this.элемент.style.display = "block";
|
||
this.элемент.style.transformOrigin = "center";
|
||
this.элемент.style.width = `40px`;
|
||
this.элемент.style.height = `40px`;
|
||
this.элемент.style.setProperty("background", "url(р/отладка/основа.jpg)");
|
||
};
|
||
|
||
this.обновить = function()
|
||
{
|
||
if (!this.тело)
|
||
{
|
||
return;
|
||
}
|
||
мир.синхронизироватьЭлементТело(this.элемент, this.тело);
|
||
};
|
||
|
||
// Конструктор.
|
||
this.создать();
|
||
}
|