ресурсы колобка

This commit is contained in:
2021-05-22 15:13:39 +03:00
parent 0a88a267fe
commit 1d643a6ec7
57 changed files with 125 additions and 231 deletions

View File

@@ -1,190 +0,0 @@
/*
*
* Реализация шаблона "издатель-подписчик"
*
*/
function Уведомитель()
{
function Подписка(id, отклик, уведомитель)
{
this.id = id;
this.отклик = отклик;
this.уведомитель = уведомитель;
};
this.уведомить = function()
{
// Попутно собираем подписки без отклика.
var безотклика = [];
for (var номер in this.подписки)
{
var подписка = this.подписки[номер];
if (подписка.отклик)
{
подписка.отклик();
}
else
{
безотклика.push(подписка);
}
}
// И удаляем их.
if (безотклика.length)
{
this._удалитьПодпискиБезОтклика(безотклика);
}
};
this.подписать = function(отклик)
{
var id = this._сгенерироватьUUID();
var подписка = new Подписка(id, отклик, this);
this.подписки.push(подписка);
return подписка;
};
this.отписать = function(подписка)
{
подписка.отклик = null;
};
this._удалитьПодпискиБезОтклика = function(удалить)
{
var подписка = удалить.shift()
while (подписка)
{
var индекс = this.подписки.indexOf(подписка);
if (индекс !== -1)
{
this.подписки.splice(индекс, 1);
}
var подписка = удалить.shift()
}
};
this._сгенерироватьUUID = function()
{
// https://stackoverflow.com/a/2117523
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
/[xy]/g,
function(c)
{
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}
);
};
// Конструктор.
this.подписки = [];
}
/*
*
* Связь событий и реакций в виде последовательности (череды)
*
*/
function Мир()
{
// Разобрать события и реакции, выраженные в тексте.
this.разобрать = function(череда)
{
var соответствия = this._событияРеакции(череда);
for (var событие in соответствия)
{
if (!(событие in this.события))
{
this.события[событие] = new Уведомитель();
}
var реакции = соответствия[событие];
for (var номер in реакции)
{
const реакция = реакции[номер];
const название = this._имяФункцииИзРеакции(реакция);
const функция = eval(название);
var тут = this;
this.события[событие].подписать(function(){
функция(тут);
});
}
}
};
// Уведомить о событии при его наличии.
this.уведомить = function(событие)
{
if (событие in this.события)
{
this.события[событие].уведомить();
}
};
// Разобрать текст с событиями и реакциями, вернуть словарь их соответствия.
this._событияРеакции = function(текст)
{
var соответствие = {};
var элементы = текст.split("\n");
var имяСобытия = null;
for (var номер in элементы)
{
var элемент = элементы[номер];
// Пропускаем комментарии.
if (элемент.charAt(0) == "#")
{
continue;
}
var имя = элемент.trim();
// Пропускаем пустые строки.
if (!имя.length)
{
continue;
}
// Событие.
if (имя == элемент)
{
if (!(имя in соответствие))
{
имяСобытия = имя;
соответствие[имя] = [];
}
}
// Реакция.
else
{
соответствие[имяСобытия].push(имя);
}
}
return соответствие;
};
// Преобразовать имя реакции в название функции.
this._имяФункцииИзРеакции = function(реакция)
{
var имя = "";
var части = реакция.split(" ");
for (var номер in части)
{
var часть = части[номер];
имя += часть.charAt(0).toUpperCase() + часть.slice(1);
}
return имя;
};
// Конструктор.
this.события = {};
}
/*
*
* Создание глобального мира.
*
*/
мир = new Мир();

View File

@@ -1,9 +1,9 @@
мир.ресурсы = {
изображения: {
основа: "основа.jpg",
основа: "р/отладка/основа.jpg",
},
звуки: {
цикл: "loop.wav",
цикл: "р/звуки/555803__ddmyzik__sunset-loop.wav",
},
};

View File

@@ -1 +0,0 @@
мир.уведомить("пуск");

View File

@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>J 0.1.0</title>
<title>K 0.9.0</title>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.min.js"></script>
<style>
html, body {
@@ -25,8 +25,11 @@
</head>
<body>
<div id="родитель"></div>
<script src="001.мир.js"></script>
<script src="011.phaser.js"></script>
<script src="499.пуск.js"></script>
<script>
var мир = {};
</script>
<script src="011.настройки.js"></script>
<script src="101.ресурсы.js"></script>
<script src="999.игра.js"></script>
</body>
</html>

View File

@@ -1 +0,0 @@
var мир = {};

View File

@@ -1,33 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>J 0.1.0</title>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.min.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
overflow: hidden;
}
body {
height: 100vh;
width: 100vw;
}
#родитель
{
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="родитель"></div>
<script src="001.мир.js"></script>
<script src="011.настройки.js"></script>
<script src="101.ресурсы.js"></script>
<script src="999.игра.js"></script>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 KiB

Binary file not shown.

BIN
р/вещи/лужа.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
р/вещи/лужа.xcf Normal file

Binary file not shown.

BIN
р/вещи/окно.xcf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

10
р/звуки/README.md Normal file
View File

@@ -0,0 +1,10 @@
* https://freesound.org/people/DDmyzik/sounds/555803/
* https://freesound.org/people/Setuniman/sounds/387922/
* https://freesound.org/people/qubodup/sounds/331381/
* https://freesound.org/people/davethetech/sounds/360432/
* https://freesound.org/people/omerbhatti34/sounds/521552/
* https://freesound.org/people/Czarcazas/sounds/330800/
* https://freesound.org/people/Kneeling/sounds/448004/
* https://freesound.org/people/EminYILDIRIM/sounds/543927/
* https://freesound.org/people/tcrocker68/sounds/235596/
* https://freesound.org/people/cabled_mess/sounds/352065/

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<spriter_data scml_version="1.0" generator="BrashMonkey Spriter" generator_version="r9">
<folder id="0">
<file id="0" name="колобок_вращение.png" width="70" height="70" pivot_x="0.5" pivot_y="0.5"/>
<file id="1" name="колобок_прыжок.png" width="56" height="90" pivot_x="0.5" pivot_y="0.357143"/>
</folder>
<entity id="0" name="колобок">
<animation id="0" name="крутится-прыгает" length="1500" interval="100">
<mainline>
<key id="0">
<object_ref id="0" timeline="0" key="0" z_index="0"/>
</key>
<key id="1" time="200">
<object_ref id="0" timeline="0" key="1" z_index="0"/>
</key>
<key id="2" time="400">
<object_ref id="0" timeline="0" key="2" z_index="0"/>
</key>
<key id="3" time="600">
<object_ref id="0" timeline="0" key="3" z_index="0"/>
</key>
<key id="4" time="800">
<object_ref id="0" timeline="0" key="4" z_index="0"/>
</key>
<key id="5" time="1000">
<object_ref id="0" timeline="1" key="0" z_index="0"/>
</key>
</mainline>
<timeline id="0" name="колобок_вращение">
<key id="0">
<object folder="0" file="0" angle="0"/>
</key>
<key id="1" time="200">
<object folder="0" file="0" angle="90"/>
</key>
<key id="2" time="400">
<object folder="0" file="0" angle="180"/>
</key>
<key id="3" time="600">
<object folder="0" file="0" angle="270"/>
</key>
<key id="4" time="800" spin="0">
<object folder="0" file="0" angle="0"/>
</key>
</timeline>
<timeline id="1" name="колобок_прыжок">
<key id="0" time="1000" spin="0">
<object folder="0" file="1"/>
</key>
</timeline>
</animation>
</entity>
</spriter_data>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<spriter_data scml_version="1.0" generator="BrashMonkey Spriter" generator_version="r9">
<folder id="0">
<file id="0" name="колобок_вращение.png" width="70" height="70" pivot_x="0.5" pivot_y="0.5"/>
<file id="1" name="колобок_прыжок.png" width="56" height="90" pivot_x="0.5" pivot_y="0.357143"/>
</folder>
<entity id="0" name="колобок">
<animation id="0" name="крутится-прыгает" length="1500" interval="100">
<mainline>
<key id="0">
<object_ref id="0" timeline="0" key="0" z_index="0"/>
</key>
<key id="1" time="200">
<object_ref id="0" timeline="0" key="1" z_index="0"/>
</key>
<key id="2" time="400">
<object_ref id="0" timeline="0" key="2" z_index="0"/>
</key>
<key id="3" time="600">
<object_ref id="0" timeline="0" key="3" z_index="0"/>
</key>
<key id="4" time="800">
<object_ref id="0" timeline="0" key="4" z_index="0"/>
</key>
<key id="5" time="1000">
<object_ref id="0" timeline="1" key="0" z_index="0"/>
</key>
</mainline>
<timeline id="0" name="колобок_вращение">
<key id="0">
<object folder="0" file="0" angle="0"/>
</key>
<key id="1" time="200">
<object folder="0" file="0" angle="90"/>
</key>
<key id="2" time="400">
<object folder="0" file="0" angle="180"/>
</key>
<key id="3" time="600">
<object folder="0" file="0" angle="270"/>
</key>
<key id="4" time="800" spin="0">
<object folder="0" file="0" angle="0"/>
</key>
</timeline>
<timeline id="1" name="колобок_прыжок">
<key id="0" time="1000" spin="0">
<object folder="0" file="1"/>
</key>
</timeline>
</animation>
</entity>
</spriter_data>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

BIN
р/сцены/изба.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

BIN
р/сцены/изба.xcf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.