add example

This commit is contained in:
Alexander Popov 2023-11-14 00:44:26 +03:00
parent 37e14215b6
commit ddbde3a954
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
4 changed files with 95 additions and 2 deletions

View File

@ -1,10 +1,10 @@
# ⚠️ IN DEVELOPMENT # ⚠️ WARNING. IN DEVELOPMENT
![engine_icon](test/icons/apple-touch-icon.png) ![engine_icon](test/icons/apple-touch-icon.png)
# Documentation # Documentation
- 🇷🇺 [Russian](docs/ru/) - 🇷🇺 [Russian](README.ru.md)
# Build `ENGINE` # Build `ENGINE`

41
README.ru.md Normal file
View File

@ -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_).

View File

@ -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;
}
});

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>simple scene</title>
<script src="./game.js" type="module"></script>
</head>
<body>
</body>
</html>