From ddbde3a9545402aee9e3aae8ca10dd4831bcacb1 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Tue, 14 Nov 2023 00:44:26 +0300 Subject: [PATCH] add example --- README.md | 4 ++-- README.ru.md | 41 ++++++++++++++++++++++++++++++++ examples/simple_scene/game.js | 41 ++++++++++++++++++++++++++++++++ examples/simple_scene/index.html | 11 +++++++++ 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 README.ru.md create mode 100644 examples/simple_scene/game.js create mode 100644 examples/simple_scene/index.html diff --git a/README.md b/README.md index ece5d96..e0a03e0 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# ⚠️ IN DEVELOPMENT +# ⚠️ WARNING. IN DEVELOPMENT ![engine_icon](test/icons/apple-touch-icon.png) # Documentation -- 🇷🇺 [Russian](docs/ru/) +- 🇷🇺 [Russian](README.ru.md) # Build `ENGINE` diff --git a/README.ru.md b/README.ru.md new file mode 100644 index 0000000..9f4c90b --- /dev/null +++ b/README.ru.md @@ -0,0 +1,41 @@ +# ⚠️ ВНИМАНИЕ. В РАЗРАБОТКЕ + +![engine_icon](test/icons/apple-touch-icon.png) + +# ujs + +**ujs** — JavaScript библиотека для разработки игр на HTML5/Canvas. + +# ⚙️ Сборка **ujs** + +Сборка осуществляется с помощью `npm` и `rollup`. + +Запустите следующие команды, чтобы запустить процесс сборки `ujs`. + +```sh +npm install +npm run build +``` + +По окончанию сборки, в директории `dist` будут находится собранные файлы `ujs`. + +# 👋🏻 Использование + +... + +# 🧰 Contribute + +## Branch info + +- `master` — current `dev` branch. +- `release` — latest **stable** version branch. + +## Git hooks + +### pre-commit + +**Requiments:** + +1. NPM module `prettier`. +2. [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) + (_Go application_). diff --git a/examples/simple_scene/game.js b/examples/simple_scene/game.js new file mode 100644 index 0000000..dc248ac --- /dev/null +++ b/examples/simple_scene/game.js @@ -0,0 +1,41 @@ +import * as ujs from './engine.js'; + +let app = new ujs.App(400, 400); + +let player = { + x: 200 - 25, + y: 200 - 25, + obj: null, +}; + +player.obj = new ujs.Rect(player.x, player.y, 50, 50, 'red'); +player.obj.ticker = () => { + player.obj.y = player.y; + player.obj.x = player.x; +}; + +let firstScene = new ujs.Scene(app.canvas, app.context, 400, 400); +let layerInstances = new ujs.SceneLayer('Instances', [player.obj]); +firstScene.addLayer(layerInstances); +app.scene = firstScene; + +window.addEventListener('DOMContentLoaded', () => { + document.body.appendChild(app.view); +}); + +document.addEventListener('keydown', (e) => { + switch (e.code) { + case 'ArrowUp': + player.y -= 10; + break; + case 'ArrowDown': + player.y += 10; + break; + case 'ArrowLeft': + player.x -= 10; + break; + case 'ArrowRight': + player.x += 10; + break; + } +}); diff --git a/examples/simple_scene/index.html b/examples/simple_scene/index.html new file mode 100644 index 0000000..6f1d070 --- /dev/null +++ b/examples/simple_scene/index.html @@ -0,0 +1,11 @@ + + + + + + simple scene + + + + +