├── .gitattributes
├── .gitignore
├── 01_heaps_color_tile
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
└── game.hxml
├── 02_heaps_mouse
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
└── game.hxml
├── 03_heaps_texture_tile
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ ├── haxeLogo.png
│ └── particlesJson.json
├── 04_heaps_anim
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ └── haxeLogo.png
├── 05_heaps_tile_group
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ └── haxeLogo.png
├── 06_heaps_graphics
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ └── haxeLogo.png
├── 07_heaps_wait_event
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ └── haxeLogo.png
├── 08_heaps_shader
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ ├── haxeLogo.png
│ └── particlesJson.json
├── 09_heaps_text
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ ├── haxeLogo.png
│ └── particlesJson.json
├── 10_heaps_load_model
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ ├── .tmp
│ ├── Model.hmd
│ ├── hashes.json
│ └── times.dat
│ ├── Model.FBX
│ ├── Skeleton01.png
│ └── Sword01.png
├── 11_heaps_shader3d
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ ├── .tmp
│ ├── Model.hmd
│ ├── hashes.json
│ └── times.dat
│ └── hxlogo.png
├── 12_heaps_bitmap_font
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game_hl.hxml
├── game_js.hxml
├── index.html
└── res
│ ├── font.fnt
│ ├── font.png
│ └── project.ltr
├── 13_heaps_camera_scroll
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Camera.hx
├── Game.hx
├── game.hxml
├── game_hl.hxml
├── game_js.hxml
├── index.html
└── res
│ ├── haxeLogo.png
│ └── particlesJson.json
├── 14_heaps_texture_atlas
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
├── game_hl.hxml
├── game_js.hxml
├── index.html
└── res
│ ├── haxeLogo.png
│ ├── spineboy-pro.atlas
│ └── spineboy-pro.png
├── 15_heaps_box2d
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Actor.hx
├── Constants.hx
├── Game.hx
├── game.hxml
├── game_hl.hxml
├── game_js.hxml
├── index.html
└── res
│ ├── ball.png
│ └── crate.jpg
├── 16_heaps_console
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
├── game_hl.hxml
├── game_js.hxml
├── index.html
└── res
│ └── haxeLogo.png
├── 17_heaps_3d_scene
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── PlayerMovement.hx
├── index.html
├── interactive.js
├── interactive.js.map
├── interactive_hl.hxml
├── interactive_js.hxml
├── interactive_swf.hxml
└── res
│ ├── .tmp
│ ├── Model.hmd
│ ├── hashes.json
│ └── times.dat
│ ├── Model.FBX
│ ├── Skeleton01.png
│ ├── Sword01.png
│ └── hxlogo.png
├── 18_heaps_scaleGrid
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
├── game_hl.hxml
├── game_js.hxml
├── index.html
└── res
│ └── space.png
├── 19_heaps_layers
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
├── game_hl.hxml
├── game_js.hxml
├── index.html
└── res
│ ├── sewer_tileset.png
│ └── sewers.tmx
├── 20_heaps_flow
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
├── game_hl.hxml
├── game_js.hxml
├── index.html
└── res
│ └── space.png
├── 21_heaps_sound_effects
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
├── game.js
├── game.js.map
├── game_hl.hxml
├── game_js.hxml
├── index.html
└── res
│ └── sound_fx.wav
├── 22_heaps_flambe_behaviors
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── flambe
│ ├── animation
│ │ ├── AnimatedFloat.hx
│ │ ├── Behavior.hx
│ │ ├── Binding.hx
│ │ ├── Ease.hx
│ │ ├── Jitter.hx
│ │ └── Tween.hx
│ ├── math
│ │ └── FMath.hx
│ ├── script
│ │ ├── Action.hx
│ │ ├── AnimateBy.hx
│ │ ├── AnimateFrom.hx
│ │ ├── AnimateTo.hx
│ │ ├── CallFunction.hx
│ │ ├── Delay.hx
│ │ ├── FirstOf.hx
│ │ ├── Parallel.hx
│ │ ├── Repeat.hx
│ │ ├── Script.hx
│ │ └── Sequence.hx
│ └── util
│ │ ├── Disposable.hx
│ │ └── Value.hx
├── game.hxml
└── res
│ ├── haxeLogo.png
│ └── particlesJson.json
├── 23_heaps_read_write_file
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Game.hx
├── game.hxml
└── res
│ ├── haxeLogo.png
│ └── particlesJson.json
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows thumbnail cache files
2 | Thumbs.db
3 | ehthumbs.db
4 | ehthumbs_vista.db
5 |
6 | # Folder config file
7 | Desktop.ini
8 |
9 | # Recycle Bin used on file shares
10 | $RECYCLE.BIN/
11 |
12 | # Windows Installer files
13 | *.cab
14 | *.msi
15 | *.msm
16 | *.msp
17 |
18 | # Windows shortcuts
19 | *.lnk
20 |
21 | # =========================
22 | # Operating System Files
23 | # =========================
24 |
--------------------------------------------------------------------------------
/01_heaps_color_tile/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/01_heaps_color_tile/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/01_heaps_color_tile/Game.hx:
--------------------------------------------------------------------------------
1 | import h2d.Bitmap;
2 |
3 | class Game extends hxd.App
4 | {
5 | static function main()
6 | {
7 | new Game();
8 | }
9 |
10 | var b:h2d.Bitmap;
11 |
12 | override function init()
13 | {
14 | trace("Hello world!!!");
15 |
16 | b = new h2d.Bitmap(h2d.Tile.fromColor(0xff0000, 60, 60), s2d);
17 | b.x = 50;
18 | b.y = 100;
19 | // центрируем тайл (задаем ему якорную точку),
20 | // таким образом все трансформации объекта на экране
21 | // будут рассчитываться относительно центра тайла.
22 | // Если данный метод не вызывать, то тайл будет трансформироваться
23 | // относительно его левой верхней точки
24 | b.tile = b.tile.center();
25 | b.rotation = Math.PI / 4; // повороты задаются в радианах
26 | }
27 |
28 | override function update(dt:Float)
29 | {
30 | b.rotation += 0.01;
31 | }
32 | }
--------------------------------------------------------------------------------
/01_heaps_color_tile/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/02_heaps_mouse/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/02_heaps_mouse/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/02_heaps_mouse/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | new Game();
6 | }
7 |
8 | var b:h2d.Bitmap;
9 |
10 | override function init()
11 | {
12 | b = new h2d.Bitmap(h2d.Tile.fromColor(0xff0000, 60, 60), s2d);
13 | b.x = 50;
14 | b.y = 100;
15 | // центрируем тайл (задаем ему якорную точку),
16 | // таким образом все трансформации объекта на экране
17 | // будут рассчитываться относительно центра тайла.
18 | // Если данный метод не вызывать, то тайл будет трансформироваться
19 | // относительно его левой верхней точки
20 | b.tile = b.tile.center();
21 | b.rotation = Math.PI / 4; // повороты задаются в радианах
22 |
23 | // Интерактивный объект для обработки событий мыши
24 | // По умолчанию он задает прямоугольную область.
25 | // Добавляем этот объект как дочерний,
26 | // чтобы он обрабатывал события для родительского объекта b
27 | var i = new h2d.Interactive(b.tile.width, b.tile.height, b);
28 | // необходимо сместить интерактивный объект для учета его якорной точки,
29 | // которая находится посередине тайла
30 | i.x = -0.5 * b.tile.width;
31 | i.y = -0.5 * b.tile.height;
32 |
33 | // Обработчики событий
34 | i.onOver = function(_) b.alpha = 0.5;
35 | i.onOut = function(_) b.alpha = 1.0;
36 | }
37 |
38 | override function update(dt:Float)
39 | {
40 | b.rotation += 0.01;
41 | }
42 | }
--------------------------------------------------------------------------------
/02_heaps_mouse/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/03_heaps_texture_tile/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/03_heaps_texture_tile/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/03_heaps_texture_tile/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | hxd.Res.initLocal();
6 |
7 | new Game();
8 | }
9 |
10 | var b:h2d.Bitmap;
11 |
12 | override function init()
13 | {
14 | // b = new h2d.Bitmap(hxd.Res.haxeLogo.toTile(), s2d);
15 | b = new h2d.Bitmap(hxd.Res.load("haxeLogo.png").toImage().toTile(), s2d);
16 | b.x = 250;
17 | b.y = 250;
18 | // центрируем тайл (задаем ему якорную точку),
19 | // таким образом все трансформации объекта на экране
20 | // будут рассчитываться относительно центра тайла.
21 | // Если данный метод не вызывать, то тайл будет трансформироваться
22 | // относительно его левой верхней точки
23 | b.tile = b.tile.center();
24 | b.rotation = Math.PI / 4; // повороты задаются в радианах
25 | }
26 |
27 | override function update(dt:Float)
28 | {
29 | b.rotation += 0.01;
30 | }
31 | }
--------------------------------------------------------------------------------
/03_heaps_texture_tile/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/03_heaps_texture_tile/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/03_heaps_texture_tile/res/haxeLogo.png
--------------------------------------------------------------------------------
/03_heaps_texture_tile/res/particlesJson.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/03_heaps_texture_tile/res/particlesJson.json
--------------------------------------------------------------------------------
/04_heaps_anim/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/04_heaps_anim/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/04_heaps_anim/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | hxd.Res.initLocal();
6 |
7 | new Game();
8 | }
9 |
10 | var b:h2d.Anim;
11 |
12 | override function init()
13 | {
14 | var animationSpeed = 15;
15 | b = new h2d.Anim(hxd.Res.haxeLogo.toTile().split(10, false), animationSpeed, s2d);
16 | b.x = 250;
17 | b.y = 250;
18 | }
19 | }
--------------------------------------------------------------------------------
/04_heaps_anim/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/04_heaps_anim/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/04_heaps_anim/res/haxeLogo.png
--------------------------------------------------------------------------------
/05_heaps_tile_group/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/05_heaps_tile_group/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/05_heaps_tile_group/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | hxd.Res.initLocal();
6 |
7 | new Game();
8 | }
9 |
10 | var g:h2d.TileGroup;
11 |
12 | override function init()
13 | {
14 | // Разбиваем текстуру на кадры по сетке
15 | var tiles = hxd.Res.haxeLogo.toTile().gridFlatten(10, 0, 0);
16 | // создаем группу
17 | g = new h2d.TileGroup(tiles[0], s2d);
18 | // отключим blend mode для группы, это ускорит отрисовку тайлов
19 | g.blendMode = None;
20 | // и добавляем в нее тайлы, произвольно расположенные на экране
21 | for (i in 0...1000)
22 | {
23 | g.add(Std.random(s2d.width), Std.random(s2d.height), tiles[i % tiles.length]);
24 | }
25 | }
26 |
27 | override function update(dt:Float)
28 | {
29 | g.rotation += 0.01;
30 | }
31 | }
--------------------------------------------------------------------------------
/05_heaps_tile_group/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/05_heaps_tile_group/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/05_heaps_tile_group/res/haxeLogo.png
--------------------------------------------------------------------------------
/06_heaps_graphics/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/06_heaps_graphics/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/06_heaps_graphics/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | hxd.Res.initLocal();
6 |
7 | new Game();
8 | }
9 |
10 | var g:h2d.Graphics;
11 |
12 | override function init()
13 | {
14 | g = new h2d.Graphics(s2d);
15 | g.beginFill(0xff00ff, 0.5);
16 | g.drawCircle(150, 150, 100);
17 | }
18 |
19 | override function update(dt:Float)
20 | {
21 | if (hxd.Key.isDown(hxd.Key.RIGHT))
22 | {
23 | g.x++;
24 | }
25 | else if (hxd.Key.isDown(hxd.Key.LEFT))
26 | {
27 | g.x--;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/06_heaps_graphics/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/06_heaps_graphics/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/06_heaps_graphics/res/haxeLogo.png
--------------------------------------------------------------------------------
/07_heaps_wait_event/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/07_heaps_wait_event/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/07_heaps_wait_event/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | hxd.Res.initLocal();
6 |
7 | new Game();
8 | }
9 |
10 | var w:hxd.WaitEvent;
11 |
12 | override function init()
13 | {
14 | w = new hxd.WaitEvent();
15 | // Отложенное выполнение функции
16 | w.wait(2, function() {trace("Kept you waiting, huh?");});
17 | // функция everyFrameRoutine будет выполняться каждый кадр
18 | w.add(everyFrameRoutine);
19 | }
20 |
21 | override function update(dt:Float)
22 | {
23 | w.update(dt);
24 | }
25 |
26 | function everyFrameRoutine(dt:Float):Bool
27 | {
28 | trace("everyFrameRoutine");
29 | return false;
30 | }
31 | }
--------------------------------------------------------------------------------
/07_heaps_wait_event/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/07_heaps_wait_event/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/07_heaps_wait_event/res/haxeLogo.png
--------------------------------------------------------------------------------
/08_heaps_shader/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/08_heaps_shader/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/08_heaps_shader/Game.hx:
--------------------------------------------------------------------------------
1 | class MyShader extends hxsl.Shader
2 | {
3 | static var SRC = {
4 |
5 | // Шейдер, от которого мы наследуемся.
6 | // Из него мы имеем доступ ко всем его
7 | // аттрибутам и константам
8 | @:import h3d.shader.Base2d;
9 |
10 | // Определяем параметр шейдера,
11 | // к которому можно будет обратиться из кода
12 | @param var color:Vec4;
13 |
14 | // Простейший фрагментный шейдер,
15 | // в котором мы переопределяем цвет на выходе
16 | function fragment()
17 | {
18 | output.color = color;
19 | }
20 | };
21 | }
22 |
23 | class MyShader2 extends hxsl.Shader
24 | {
25 | static var SRC = {
26 |
27 | @:import h3d.shader.Base2d;
28 |
29 | @param var color:Vec4;
30 |
31 | function fragment()
32 | {
33 | output.color += color;
34 | }
35 | };
36 | }
37 |
38 | class Game extends hxd.App
39 | {
40 | static function main()
41 | {
42 | hxd.Res.initLocal();
43 |
44 | new Game();
45 | }
46 |
47 | var b:h2d.Bitmap;
48 |
49 | override function init()
50 | {
51 | b = new h2d.Bitmap(hxd.Res.haxeLogo.toTile(), s2d);
52 | var s = new MyShader();
53 | // задаем значение параметра шейдера,
54 | // который мы добавили ранее
55 | s.color.set(1.0, 0.0, 0.0, 1.0);
56 | b.addShader(s);
57 |
58 | // Добавляем объекту второй шейдер
59 | var s2 = new MyShader2();
60 | s2.color.set(0.0, 0.0, 1.0, 0.0);
61 | b.addShader(s2);
62 |
63 | b.x = 250;
64 | b.y = 250;
65 | // центрируем тайл (задаем ему якорную точку),
66 | // таким образом все трансформации объекта на экране
67 | // будут рассчитываться относительно центра тайла.
68 | // Если данный метод не вызывать, то тайл будет трансформироваться
69 | // относительно его левой верхней точки
70 | b.tile = b.tile.center();
71 | b.rotation = Math.PI / 4; // повороты задаются в радианах
72 | }
73 |
74 | override function update(dt:Float)
75 | {
76 | b.rotation += 0.01;
77 | }
78 | }
--------------------------------------------------------------------------------
/08_heaps_shader/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/08_heaps_shader/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/08_heaps_shader/res/haxeLogo.png
--------------------------------------------------------------------------------
/08_heaps_shader/res/particlesJson.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/08_heaps_shader/res/particlesJson.json
--------------------------------------------------------------------------------
/09_heaps_text/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/09_heaps_text/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/09_heaps_text/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | hxd.Res.initLocal();
6 |
7 | new Game();
8 | }
9 |
10 | override function init()
11 | {
12 | var t = new h2d.Text(hxd.res.DefaultFont.get(), s2d);
13 | t.scale(10);
14 | t.text = "Haxe Rocks!!!";
15 |
16 | var t = new h2d.HtmlText(hxd.res.DefaultFont.get(), s2d);
17 | t.scale(10);
18 | t.y = 100;
19 | t.text = "Haxe Rocks!!!";
20 |
21 | var t = new h2d.TextInput(hxd.res.DefaultFont.get(), s2d);
22 | t.scale(10);
23 | t.y = 200;
24 | t.text = "Input text";
25 | }
26 | }
--------------------------------------------------------------------------------
/09_heaps_text/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/09_heaps_text/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/09_heaps_text/res/haxeLogo.png
--------------------------------------------------------------------------------
/09_heaps_text/res/particlesJson.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/09_heaps_text/res/particlesJson.json
--------------------------------------------------------------------------------
/10_heaps_load_model/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/10_heaps_load_model/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/10_heaps_load_model/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | hxd.Res.initLocal();
6 |
7 | new Game();
8 | }
9 |
10 | var obj:h3d.scene.Object;
11 |
12 | override function init()
13 | {
14 | // Загружаем модель и добавляем объект на сцену
15 | var cache = new h3d.prim.ModelCache();
16 | obj = cache.loadModel(hxd.Res.Model);
17 | obj.scale(0.05);
18 | obj.rotate(0, 0, Math.PI);
19 | s3d.addChild(obj);
20 |
21 | // Загружаем анимацию, зашитую в Model.fbx
22 | var anim = cache.loadAnimation(hxd.Res.Model);
23 | // Воспроизводим анимацию
24 | // Обратите внимание, что одну и ту же анимацию
25 | // можно применять к разным моделям
26 | obj.playAnimation(anim);
27 |
28 | // Настраиваем освещение на сцене
29 | var light = new h3d.scene.DirLight(new h3d.Vector( 0.3, -0.4, -0.9), s3d);
30 | light.enableSpecular = true;
31 | light.color.set(0.28, 0.28, 0.28);
32 | s3d.lightSystem.ambientLight.set(0.74, 0.74, 0.74);
33 |
34 | // Создаем простой контроллер для камеры,
35 | // чтобы ей можно было управлять мышью
36 | new h3d.scene.CameraController(s3d).loadFromCamera();
37 |
38 | engine.backgroundColor = 0xFF808080;
39 | }
40 | }
--------------------------------------------------------------------------------
/10_heaps_load_model/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/10_heaps_load_model/res/.tmp/Model.hmd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/10_heaps_load_model/res/.tmp/Model.hmd
--------------------------------------------------------------------------------
/10_heaps_load_model/res/.tmp/hashes.json:
--------------------------------------------------------------------------------
1 | {
2 | "Model.FBX": "b709d3e52d1ef2f375e76a42d85b6927dd71f053"
3 | }
--------------------------------------------------------------------------------
/10_heaps_load_model/res/.tmp/times.dat:
--------------------------------------------------------------------------------
1 | by9:Model.FBXi1534003375h
--------------------------------------------------------------------------------
/10_heaps_load_model/res/Skeleton01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/10_heaps_load_model/res/Skeleton01.png
--------------------------------------------------------------------------------
/10_heaps_load_model/res/Sword01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/10_heaps_load_model/res/Sword01.png
--------------------------------------------------------------------------------
/11_heaps_shader3d/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/11_heaps_shader3d/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/11_heaps_shader3d/Game.hx:
--------------------------------------------------------------------------------
1 | class EffectShader extends hxsl.Shader
2 | {
3 | static var SRC = {
4 |
5 | // Импортируем все определения из
6 | // базового шейдера для 3D
7 | @:import h3d.shader.BaseMesh;
8 |
9 | // Вершинный шейдер
10 | function vertex()
11 | {
12 | transformedPosition.z += sin(transformedPosition.y * 3 + global.time * 4) * 0.5;
13 | }
14 |
15 | // Фрагментный шейдер
16 | function fragment()
17 | {
18 | output.color.r *= transformedPosition.z;
19 | }
20 | };
21 | }
22 |
23 | class Game extends hxd.App
24 | {
25 | static function main()
26 | {
27 | hxd.Res.initLocal();
28 |
29 | new Game();
30 | }
31 |
32 | var obj:h3d.scene.Mesh;
33 |
34 | override function init()
35 | {
36 | // Создаем простой куб и подготавливаем его для текстурирования
37 | var prim = new h3d.prim.Cube();
38 | prim.translate( -0.5, -0.5, -0.5);
39 | // Данная операция необходима для расчета нормалей каждой грани
40 | prim.unindex();
41 | // Добавление данных о нормалях вершин
42 | prim.addNormals();
43 | // Добавление данных о текстурных координатах
44 | prim.addUVs();
45 |
46 | // Загрузка текстуры для нашего куба
47 | var tex = hxd.Res.hxlogo.toTexture();
48 |
49 | // Создаем текстурированный материал
50 | var mat = h3d.mat.Material.create(tex);
51 |
52 | // Создаем Меш и добавляем его на сцену
53 | obj = new h3d.scene.Mesh(prim, mat, s3d);
54 | // Отключаем тени у материала куба
55 | obj.material.shadows = false;
56 |
57 | // Задаем шейдер для нашего объекта типа Mesh
58 | obj.material.mainPass.addShader(new EffectShader());
59 |
60 | // Настройка освещения на сцене
61 | var light = new h3d.scene.DirLight(new h3d.Vector(0.5, 0.5, -0.5), s3d);
62 | light.enableSpecular = true;
63 |
64 | s3d.lightSystem.ambientLight.set(0.3, 0.3, 0.3);
65 |
66 | // Создаем простой контроллер для камеры,
67 | // чтобы ей можно было управлять мышью
68 | new h3d.scene.CameraController(s3d).loadFromCamera();
69 |
70 | engine.backgroundColor = 0xFF808080;
71 | }
72 | }
--------------------------------------------------------------------------------
/11_heaps_shader3d/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/11_heaps_shader3d/res/.tmp/Model.hmd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/11_heaps_shader3d/res/.tmp/Model.hmd
--------------------------------------------------------------------------------
/11_heaps_shader3d/res/.tmp/hashes.json:
--------------------------------------------------------------------------------
1 | {
2 | "Model.FBX": "b709d3e52d1ef2f375e76a42d85b6927dd71f053"
3 | }
--------------------------------------------------------------------------------
/11_heaps_shader3d/res/.tmp/times.dat:
--------------------------------------------------------------------------------
1 | by9:Model.FBXi1534003375h
--------------------------------------------------------------------------------
/11_heaps_shader3d/res/hxlogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/11_heaps_shader3d/res/hxlogo.png
--------------------------------------------------------------------------------
/12_heaps_bitmap_font/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "game_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/12_heaps_bitmap_font/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "game_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "game_hl.hxml"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/12_heaps_bitmap_font/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | hxd.Res.initEmbed();
6 | new Game();
7 | }
8 |
9 | override function init()
10 | {
11 | // For bitmap font generation
12 | // use https://github.com/andryblack/fontbuilder/downloads (export to XML divo format)
13 | // or http://www.kvazars.com/littera/ (export to XML format).
14 | // BMFont tool doesn't supported (will throw exceprions all the time)
15 |
16 | var bmp = new hxd.res.BitmapFont(hxd.Res.load("font.fnt").entry);
17 | var fnt = bmp.toFont();
18 |
19 | var t = new h2d.Text(fnt, s2d);
20 | t.text = "Haxe Rocks!!!";
21 | }
22 | }
--------------------------------------------------------------------------------
/12_heaps_bitmap_font/game_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hlsdl
3 | -hl game.hl
4 | -main Game
5 |
6 |
--------------------------------------------------------------------------------
/12_heaps_bitmap_font/game_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -js game.js
3 | -main Game
4 | -debug
5 |
6 |
--------------------------------------------------------------------------------
/12_heaps_bitmap_font/index.html:
--------------------------------------------------------------------------------
1 |
2 |
BitmapFont
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/12_heaps_bitmap_font/res/font.fnt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
--------------------------------------------------------------------------------
/12_heaps_bitmap_font/res/font.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/12_heaps_bitmap_font/res/font.png
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "game_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "game_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "game_hl.hxml"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/Camera.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import h2d.Scene;
4 |
5 | class Camera extends h2d.Sprite
6 | {
7 | public var viewX(get, set):Float;
8 | public var viewY(get, set):Float;
9 |
10 | var scene:Scene;
11 |
12 | public function new(scene:Scene)
13 | {
14 | super(scene);
15 | this.scene = scene;
16 | }
17 |
18 | private function set_viewX(value:Float):Float
19 | {
20 | this.x = 0.5 * scene.width - value;
21 | return value;
22 | }
23 |
24 | private function get_viewX():Float
25 | {
26 | return 0.5 * scene.width - this.x;
27 | }
28 |
29 | private function set_viewY(value:Float):Float
30 | {
31 | this.y = 0.5 * scene.height - value;
32 | return value;
33 | }
34 |
35 | private function get_viewY():Float
36 | {
37 | return 0.5 * scene.height - this.y;
38 | }
39 | }
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/Game.hx:
--------------------------------------------------------------------------------
1 | import h2d.TileGroup;
2 | import hxd.Key;
3 | import hxd.App;
4 |
5 | class Game extends hxd.App
6 | {
7 | static function main()
8 | {
9 | hxd.Res.initEmbed();
10 |
11 | new Game();
12 | }
13 |
14 | var camera:Camera;
15 |
16 | var char:h2d.Bitmap;
17 | var map:TileGroup;
18 |
19 | override function init()
20 | {
21 | camera = new Camera(s2d);
22 |
23 | var tile = h2d.Tile.fromColor(0x00ff00, 16, 16);
24 | map = new TileGroup(tile, camera);
25 |
26 | for (i in 0...1000)
27 | {
28 | map.add(Std.int(s2d.width * Math.random()), Std.int(s2d.height * Math.random()), tile);
29 | }
30 |
31 | char = new h2d.Bitmap(hxd.Res.load("haxeLogo.png").toImage().toTile(), camera);
32 | char.x = 250;
33 | char.y = 250;
34 |
35 | char.tile = char.tile.center();
36 | char.scaleX = char.scaleY = 0.25;
37 | }
38 |
39 | override function update(dt:Float)
40 | {
41 | if (Key.isDown(Key.LEFT))
42 | {
43 | char.x--;
44 | }
45 | else if (Key.isDown(Key.RIGHT))
46 | {
47 | char.x++;
48 | }
49 |
50 | if (Key.isDown(Key.UP))
51 | {
52 | char.y--;
53 | }
54 | else if (Key.isDown(Key.DOWN))
55 | {
56 | char.y++;
57 | }
58 |
59 | camera.viewX = char.x;
60 | camera.viewY = char.y;
61 | }
62 | }
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/game_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hlsdl
3 | -hl game.hl
4 | -main Game
5 |
6 |
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/game_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -js game.js
3 | -main Game
4 | -debug
5 |
6 |
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/index.html:
--------------------------------------------------------------------------------
1 |
2 | BitmapFont
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/13_heaps_camera_scroll/res/haxeLogo.png
--------------------------------------------------------------------------------
/13_heaps_camera_scroll/res/particlesJson.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/13_heaps_camera_scroll/res/particlesJson.json
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "game_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "game_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "game_hl.hxml"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/Game.hx:
--------------------------------------------------------------------------------
1 | class Game extends hxd.App
2 | {
3 | static function main()
4 | {
5 | hxd.Res.initEmbed();
6 |
7 | new Game();
8 | }
9 |
10 | var b:h2d.Bitmap;
11 |
12 | override function init()
13 | {
14 | var atlas:hxd.res.Atlas = hxd.Res.load("spineboy-pro.atlas").to(hxd.res.Atlas);
15 | var tile = atlas.get("crosshair");
16 |
17 | b = new h2d.Bitmap(tile, s2d);
18 | b.tile = b.tile.center();
19 | }
20 |
21 | override function update(dt:Float)
22 | {
23 | b.x = s2d.mouseX;
24 | b.y = s2d.mouseY;
25 | }
26 | }
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/game_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hlsdl
3 | -hl game.hl
4 | -main Game
5 |
6 |
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/game_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -js game.js
3 | -main Game
4 | -debug
5 |
6 |
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/index.html:
--------------------------------------------------------------------------------
1 |
2 | Atlas
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/14_heaps_texture_atlas/res/haxeLogo.png
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/res/spineboy-pro.atlas:
--------------------------------------------------------------------------------
1 |
2 | spineboy-pro.png
3 | size: 2048,1024
4 | format: RGBA8888
5 | filter: Linear,Linear
6 | repeat: none
7 | crosshair
8 | rotate: false
9 | xy: 1053, 13
10 | size: 89, 89
11 | orig: 89, 89
12 | offset: 0, 0
13 | index: -1
14 | dust01
15 | rotate: false
16 | xy: 1239, 11
17 | size: 96, 73
18 | orig: 96, 73
19 | offset: 0, 0
20 | index: -1
21 | dust02
22 | rotate: false
23 | xy: 1409, 44
24 | size: 86, 88
25 | orig: 86, 88
26 | offset: 0, 0
27 | index: -1
28 | dust03
29 | rotate: false
30 | xy: 1831, 416
31 | size: 62, 52
32 | orig: 62, 52
33 | offset: 0, 0
34 | index: -1
35 | eye-indifferent
36 | rotate: false
37 | xy: 1144, 18
38 | size: 93, 89
39 | orig: 93, 89
40 | offset: 0, 0
41 | index: -1
42 | eye-surprised
43 | rotate: false
44 | xy: 1314, 43
45 | size: 93, 89
46 | orig: 93, 89
47 | offset: 0, 0
48 | index: -1
49 | front-bracer
50 | rotate: false
51 | xy: 1749, 410
52 | size: 58, 80
53 | orig: 58, 80
54 | offset: 0, 0
55 | index: -1
56 | front-fist-closed
57 | rotate: false
58 | xy: 1592, 396
59 | size: 75, 82
60 | orig: 75, 82
61 | offset: 0, 0
62 | index: -1
63 | front-fist-open
64 | rotate: false
65 | xy: 1504, 391
66 | size: 86, 87
67 | orig: 86, 87
68 | offset: 0, 0
69 | index: -1
70 | front-foot
71 | rotate: false
72 | xy: 580, 33
73 | size: 126, 69
74 | orig: 126, 69
75 | offset: 0, 0
76 | index: -1
77 | front-shin
78 | rotate: false
79 | xy: 496, 51
80 | size: 82, 184
81 | orig: 82, 184
82 | offset: 0, 0
83 | index: -1
84 | front-thigh
85 | rotate: false
86 | xy: 1504, 277
87 | size: 48, 112
88 | orig: 48, 112
89 | offset: 0, 0
90 | index: -1
91 | front-upper-arm
92 | rotate: false
93 | xy: 1554, 292
94 | size: 54, 97
95 | orig: 54, 97
96 | offset: 0, 0
97 | index: -1
98 | goggles
99 | rotate: false
100 | xy: 1136, 109
101 | size: 261, 166
102 | orig: 261, 166
103 | offset: 0, 0
104 | index: -1
105 | gun
106 | rotate: false
107 | xy: 1463, 480
108 | size: 210, 203
109 | orig: 210, 203
110 | offset: 0, 0
111 | index: -1
112 | head
113 | rotate: false
114 | xy: 1753, 724
115 | size: 271, 298
116 | orig: 271, 298
117 | offset: 0, 0
118 | index: -1
119 | hoverboard-board
120 | rotate: false
121 | xy: 2, 83
122 | size: 492, 152
123 | orig: 492, 152
124 | offset: 0, 0
125 | index: -1
126 | hoverboard-thruster
127 | rotate: false
128 | xy: 1207, 372
129 | size: 60, 64
130 | orig: 60, 64
131 | offset: 0, 0
132 | index: -1
133 | hoverglow-small
134 | rotate: false
135 | xy: 2, 6
136 | size: 274, 75
137 | orig: 274, 75
138 | offset: 0, 0
139 | index: -1
140 | mouth-grind
141 | rotate: false
142 | xy: 1610, 301
143 | size: 93, 59
144 | orig: 93, 59
145 | offset: 0, 0
146 | index: -1
147 | mouth-oooo
148 | rotate: false
149 | xy: 1486, 139
150 | size: 93, 59
151 | orig: 93, 59
152 | offset: 0, 0
153 | index: -1
154 | mouth-smile
155 | rotate: false
156 | xy: 1497, 44
157 | size: 93, 59
158 | orig: 93, 59
159 | offset: 0, 0
160 | index: -1
161 | muzzle-glow
162 | rotate: false
163 | xy: 1304, 234
164 | size: 198, 198
165 | orig: 198, 198
166 | offset: 0, 0
167 | index: -1
168 | muzzle-ring
169 | rotate: false
170 | xy: 278, 32
171 | size: 49, 209
172 | orig: 49, 209
173 | offset: 0, 0
174 | index: -1
175 | muzzle01
176 | rotate: false
177 | xy: 667, 673
178 | size: 542, 349
179 | orig: 542, 349
180 | offset: 0, 0
181 | index: -1
182 | muzzle02
183 | rotate: false
184 | xy: 1211, 685
185 | size: 540, 337
186 | orig: 540, 337
187 | offset: 0, 0
188 | index: -1
189 | muzzle03
190 | rotate: false
191 | xy: 2, 597
192 | size: 663, 425
193 | orig: 663, 425
194 | offset: 0, 0
195 | index: -1
196 | muzzle04
197 | rotate: false
198 | xy: 2, 237
199 | size: 596, 358
200 | orig: 596, 358
201 | offset: 0, 0
202 | index: -1
203 | muzzle05
204 | rotate: false
205 | xy: 667, 372
206 | size: 538, 299
207 | orig: 538, 299
208 | offset: 0, 0
209 | index: -1
210 | neck
211 | rotate: false
212 | xy: 1504, 234
213 | size: 36, 41
214 | orig: 36, 41
215 | offset: 0, 0
216 | index: -1
217 | portal-bg
218 | rotate: false
219 | xy: 600, 104
220 | size: 266, 266
221 | orig: 266, 266
222 | offset: 0, 0
223 | index: -1
224 | portal-flare1
225 | rotate: false
226 | xy: 940, 42
227 | size: 111, 60
228 | orig: 111, 60
229 | offset: 0, 0
230 | index: -1
231 | portal-flare2
232 | rotate: false
233 | xy: 600, 375
234 | size: 114, 61
235 | orig: 114, 61
236 | offset: 0, 0
237 | index: -1
238 | portal-flare3
239 | rotate: false
240 | xy: 708, 43
241 | size: 115, 59
242 | orig: 115, 59
243 | offset: 0, 0
244 | index: -1
245 | portal-shade
246 | rotate: false
247 | xy: 868, 104
248 | size: 266, 266
249 | orig: 266, 266
250 | offset: 0, 0
251 | index: -1
252 | portal-streaks1
253 | rotate: false
254 | xy: 1753, 470
255 | size: 252, 256
256 | orig: 252, 256
257 | offset: 0, 0
258 | index: -1
259 | portsl-streaks2
260 | rotate: false
261 | xy: 1211, 434
262 | size: 250, 249
263 | orig: 250, 249
264 | offset: 0, 0
265 | index: -1
266 | rear-bracer
267 | rotate: false
268 | xy: 1675, 447
269 | size: 56, 72
270 | orig: 56, 72
271 | offset: 0, 0
272 | index: -1
273 | rear-foot
274 | rotate: false
275 | xy: 825, 42
276 | size: 113, 60
277 | orig: 113, 60
278 | offset: 0, 0
279 | index: -1
280 | rear-shin
281 | rotate: false
282 | xy: 1675, 505
283 | size: 75, 178
284 | orig: 75, 178
285 | offset: 0, 0
286 | index: -1
287 | rear-thigh
288 | rotate: false
289 | xy: 600, 491
290 | size: 65, 104
291 | orig: 65, 104
292 | offset: 0, 0
293 | index: -1
294 | rear-upper-arm
295 | rotate: false
296 | xy: 489, 2
297 | size: 47, 87
298 | orig: 47, 87
299 | offset: 0, 0
300 | index: -1
301 | torso
302 | rotate: false
303 | xy: 1304, 134
304 | size: 98, 180
305 | orig: 98, 180
306 | offset: 0, 0
307 | index: -1
308 |
--------------------------------------------------------------------------------
/14_heaps_texture_atlas/res/spineboy-pro.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/14_heaps_texture_atlas/res/spineboy-pro.png
--------------------------------------------------------------------------------
/15_heaps_box2d/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "game_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/15_heaps_box2d/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "game_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "game_hl.hxml"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/15_heaps_box2d/Actor.hx:
--------------------------------------------------------------------------------
1 | import h2d.Bitmap;
2 | import box2D.dynamics.B2Body;
3 |
4 | class Actor extends Bitmap
5 | {
6 | public var body:B2Body;
7 |
8 | public function new(tile:h2d.Tile, ?parent:h2d.Object)
9 | {
10 | super(tile, parent);
11 | }
12 |
13 | public function centerTile():Void
14 | {
15 | if (tile == null) return;
16 | tile = tile.center();
17 | }
18 |
19 | public function update():Void
20 | {
21 | var p = body.getPosition();
22 | this.x = p.x * Constants.PIXELS_IN_METER; // updating actor
23 | this.y = p.y * Constants.PIXELS_IN_METER;
24 | this.rotation = body.getAngle();
25 | }
26 | }
--------------------------------------------------------------------------------
/15_heaps_box2d/Constants.hx:
--------------------------------------------------------------------------------
1 | class Constants
2 | {
3 | // I decided that 1 meter = 100 pixels
4 | public static inline var PIXELS_IN_METER:Int = 100;
5 | }
--------------------------------------------------------------------------------
/15_heaps_box2d/Game.hx:
--------------------------------------------------------------------------------
1 | import box2D.dynamics.B2World;
2 | import box2D.common.math.B2Vec2;
3 | import box2D.dynamics.B2Body;
4 | import box2D.dynamics.B2BodyDef;
5 | import box2D.dynamics.B2BodyType;
6 | import box2D.dynamics.B2Fixture;
7 | import box2D.dynamics.B2FixtureDef;
8 | import box2D.collision.B2AABB;
9 | import box2D.collision.shapes.B2Shape;
10 | import box2D.collision.shapes.B2PolygonShape;
11 | import box2D.collision.shapes.B2CircleShape;
12 |
13 | /**
14 | * In order to compile it you would need to use version of box2d library
15 | * installed from https://github.com/openfl/box2d (not from haxelib, which is outdated)
16 | */
17 | class Game extends hxd.App
18 | {
19 | static function main()
20 | {
21 | hxd.Res.initEmbed();
22 |
23 | new Game();
24 | }
25 |
26 | var world:B2World;
27 | var actors:Array = []; // instances of Bitmap (from Heaps)
28 | var up:B2Vec2;
29 |
30 | override function init()
31 | {
32 | world = new B2World(new B2Vec2(0, 10), true);
33 | up = new B2Vec2(0, -5);
34 |
35 | var bxFixDef = new B2FixtureDef(); // box fixture definition
36 |
37 | var blFixDef = new B2FixtureDef(); // ball fixture definition
38 | var bxCircleShape = new B2CircleShape();
39 | blFixDef.shape = bxCircleShape;
40 | bxFixDef.density = blFixDef.density = 1;
41 |
42 | var bodyDef = new B2BodyDef();
43 | bodyDef.type = B2BodyType.STATIC_BODY;
44 |
45 | // create ground
46 | var bxPolygonShape = new B2PolygonShape();
47 | bxPolygonShape.setAsBox(10, 1);
48 | bxFixDef.shape = bxPolygonShape;
49 | bodyDef.position.set(9, s2d.height / Constants.PIXELS_IN_METER + 1);
50 | world.createBody(bodyDef).createFixture(bxFixDef);
51 |
52 | bxPolygonShape.setAsBox(1, 100);
53 | bxFixDef.shape = bxPolygonShape;
54 | // left wall
55 | bodyDef.position.set(-1, 3);
56 | world.createBody(bodyDef).createFixture(bxFixDef);
57 | // right wall
58 | bodyDef.position.set(s2d.width / Constants.PIXELS_IN_METER + 1, 3);
59 | world.createBody(bodyDef).createFixture(bxFixDef);
60 |
61 | // both images are 200 x 200 px
62 | var bxBD = hxd.Res.load("crate.jpg").toImage().toTile();
63 | var blBD = hxd.Res.load("ball.png").toImage().toTile();
64 |
65 | // let's add 25 boxes and 25 balls!
66 | bodyDef.type = B2BodyType.DYNAMIC_BODY;
67 | for (i in 0...50)
68 | {
69 | var hw = 0.1 + Math.random() * 0.45; // "half width"
70 | var hh = 0.1 + Math.random() * 0.45; // "half height"
71 |
72 | var isCircle:Bool = (i >= 25);
73 |
74 | bxPolygonShape.setAsBox(hw, hh);
75 | bxFixDef.shape = bxPolygonShape;
76 |
77 | bxCircleShape.setRadius(hw);
78 | blFixDef.shape = bxCircleShape;
79 |
80 | bodyDef.position.set(Math.random() * 7, -5 + Math.random() * 5);
81 |
82 | var body = world.createBody(bodyDef);
83 | if (!isCircle)
84 | {
85 | body.createFixture(bxFixDef); // box
86 | }
87 | else
88 | {
89 | body.createFixture(blFixDef); // ball
90 | hh = hw;
91 | }
92 |
93 | var actor = new Actor(isCircle ? blBD : bxBD, s2d);
94 | actor.body = body;
95 | actor.centerTile();
96 |
97 | // Need to adjust scale since tile scale
98 | actor.scaleX = hw;
99 | actor.scaleY = hh;
100 |
101 | actors.push(actor);
102 | }
103 | }
104 |
105 | override function update(dt:Float)
106 | {
107 | world.step(1 / 60, 3, 3);
108 | world.clearForces();
109 |
110 | for (actor in actors)
111 | {
112 | actor.update();
113 | }
114 |
115 | if (hxd.Key.isPressed(hxd.Key.MOUSE_LEFT))
116 | {
117 | var body = getBodyAtMouse();
118 | if (body != null)
119 | {
120 | body.applyImpulse(up, body.getWorldCenter());
121 | }
122 | }
123 | }
124 |
125 | //======================
126 | // GetBodyAtMouse
127 | //======================
128 | private var mousePVec:B2Vec2 = new B2Vec2();
129 | public function getBodyAtMouse(includeStatic:Bool = false):B2Body
130 | {
131 | // Make a small box.
132 | var mouseXWorldPhys = s2d.mouseX / Constants.PIXELS_IN_METER;
133 | var mouseYWorldPhys = s2d.mouseY / Constants.PIXELS_IN_METER;
134 | mousePVec.set(mouseXWorldPhys, mouseYWorldPhys);
135 | var aabb:B2AABB = new B2AABB();
136 | aabb.lowerBound.set(mouseXWorldPhys - 0.001, mouseYWorldPhys - 0.001);
137 | aabb.upperBound.set(mouseXWorldPhys + 0.001, mouseYWorldPhys + 0.001);
138 | var body:B2Body = null;
139 | var fixture:B2Fixture;
140 |
141 | // Query the world for overlapping shapes.
142 | function getBodyCallback(fixture:B2Fixture):Bool
143 | {
144 | var shape:B2Shape = fixture.getShape();
145 | if (fixture.getBody().getType() != 0 || includeStatic)
146 | {
147 | var inside:Bool = shape.testPoint(fixture.getBody().getTransform(), mousePVec);
148 | if (inside)
149 | {
150 | body = fixture.getBody();
151 | return false;
152 | }
153 | }
154 |
155 | return true;
156 | }
157 |
158 | world.queryAABB(getBodyCallback, aabb);
159 | return body;
160 | }
161 | }
--------------------------------------------------------------------------------
/15_heaps_box2d/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | -lib box2d
7 | # Задаем основной класс приложения с точкой входа
8 | -main Game
9 | # Выходной файл
10 | -hl game.hl
--------------------------------------------------------------------------------
/15_heaps_box2d/game_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hldx
3 | -lib box2d
4 | -hl game.hl
5 | -main Game
6 |
7 |
--------------------------------------------------------------------------------
/15_heaps_box2d/game_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib box2d
3 | -js game.js
4 | -main Game
5 | -debug
--------------------------------------------------------------------------------
/15_heaps_box2d/index.html:
--------------------------------------------------------------------------------
1 |
2 | Box2D
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/15_heaps_box2d/res/ball.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/15_heaps_box2d/res/ball.png
--------------------------------------------------------------------------------
/15_heaps_box2d/res/crate.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/15_heaps_box2d/res/crate.jpg
--------------------------------------------------------------------------------
/16_heaps_console/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "game_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/16_heaps_console/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "game_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "game_hl.hxml"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/16_heaps_console/Game.hx:
--------------------------------------------------------------------------------
1 | import h2d.TileGroup;
2 | import hxd.Key;
3 | import hxd.App;
4 |
5 | class Game extends hxd.App
6 | {
7 | static function main()
8 | {
9 | hxd.Res.initEmbed();
10 |
11 | new Game();
12 | }
13 |
14 | var char:h2d.Bitmap;
15 | var map:TileGroup;
16 |
17 | override function init()
18 | {
19 | var tile = h2d.Tile.fromColor(0x00ff00, 16, 16);
20 | map = new TileGroup(tile, null);
21 |
22 | for (i in 0...100)
23 | {
24 | map.add(Std.int(s2d.width * Math.random()), Std.int(s2d.height * Math.random()), tile);
25 | }
26 |
27 | char = new h2d.Bitmap(hxd.Res.load("haxeLogo.png").toImage().toTile(), s2d);
28 | char.x = 0.5 * s2d.width;
29 | char.y = 0.5 * s2d.height;
30 |
31 | char.tile = char.tile.center();
32 | char.scaleX = char.scaleY = 0.25;
33 |
34 | // add console to the game
35 | var console = new h2d.Console(hxd.res.DefaultFont.get(), s2d);
36 | // redefine key to show console on screen
37 | console.shortKeyChar = "`".charCodeAt(0);
38 |
39 | // or you can call console from code
40 | console.show();
41 | // and type some info here...
42 | console.log("Hello from console :)", 0x00ff00);
43 | console.log("Warning!", 0xff0000);
44 |
45 | // you can add custom commands to your console which can take various types of arguments
46 | // (Int, Float, String, Bool and even Enums):
47 |
48 | // 1. command without arguments:
49 | console.addCommand("remove_tiles", "Remove all green tiles", [], function() {
50 | s2d.removeChild(map);
51 | });
52 |
53 | console.addCommand("add_tiles", "Add all green tiles back to the scene", [], function() {
54 | s2d.addChildAt(map, 0);
55 | });
56 |
57 | // you can run registered console command from code:
58 | console.runCommand("add_tiles");
59 |
60 | // 2. command with 2 floating point number arguments
61 | console.addCommand( "move_logo", "Moves logo to specified position",
62 | [ { name : "x", t : AFloat, opt : false }, { name : "y", t : AFloat, opt : false } ],
63 | function(x:Float, y:Float) {
64 | char.x = x;
65 | char.y = y;
66 | });
67 |
68 | // 3. command with optional bool argument
69 | console.addCommand( "show_logo", "Shows or hides logo",
70 | [ { name : "visible", t : ABool, opt : true } ],
71 | function(?visible:Bool = true) {
72 | char.visible = visible;
73 | });
74 |
75 | // you can call scroll through previous called commands by pressing up and down buttons
76 | // (while cursor is focused in console)
77 |
78 | // and you can add short alias name for your commands
79 | console.addAlias("mv", "move_logo");
80 | }
81 | }
--------------------------------------------------------------------------------
/16_heaps_console/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/16_heaps_console/game_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hlsdl
3 | -hl game.hl
4 | -main Game
5 |
6 |
--------------------------------------------------------------------------------
/16_heaps_console/game_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -js game.js
3 | -main Game
4 | -debug
5 |
6 |
--------------------------------------------------------------------------------
/16_heaps_console/index.html:
--------------------------------------------------------------------------------
1 |
2 | BitmapFont
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/16_heaps_console/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/16_heaps_console/res/haxeLogo.png
--------------------------------------------------------------------------------
/17_heaps_3d_scene/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "interactive_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | },
23 | {
24 | "name": "Flash",
25 | "type": "fdb",
26 | "request": "launch",
27 | "program": "${workspaceRoot}/interactive.swf",
28 | "preLaunchTask": "HeapsSWF"
29 | }
30 | ]
31 | }
--------------------------------------------------------------------------------
/17_heaps_3d_scene/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "interactive_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "interactive_hl.hxml"
23 | },
24 | {
25 | "label": "HeapsSWF",
26 | "type": "hxml",
27 | "file": "interactive_swf.hxml"
28 | }
29 | ]
30 | }
--------------------------------------------------------------------------------
/17_heaps_3d_scene/PlayerMovement.hx:
--------------------------------------------------------------------------------
1 | // just helper class to hold object position on plane
2 | class Point
3 | {
4 | public var x:Float;
5 | public var y:Float;
6 |
7 | public function new(x:Float = 0, y:Float = 0)
8 | {
9 | this.x = x;
10 | this.y = y;
11 | }
12 | }
13 |
14 | // just helper class to hold world bounds
15 | class Rect
16 | {
17 | public var x:Float;
18 | public var y:Float;
19 | public var width:Float;
20 | public var height:Float;
21 |
22 | public function new(x:Float = 0, y:Float = 0, width:Float = 0, height:Float = 0)
23 | {
24 | this.x = x;
25 | this.y = y;
26 | this.width = width;
27 | this.height = height;
28 | }
29 | }
30 |
31 | /**
32 | * This example uses `differ` library for collision detection.
33 | * You can install it from git: `haxelib git differ https://github.com/snowkit/differ.git`
34 | * (haxelib version of `differ` currently is incompatible with Haxe 4.0.0.5preview or higher)
35 | **/
36 | class PlayerMovement extends hxd.App {
37 |
38 | // Light source for our scene
39 | var light : h3d.scene.DirLight;
40 |
41 | // player object, which we will controll
42 | var player : h3d.scene.Object;
43 |
44 | // just a cube representing floor
45 | var floor: h3d.scene.Object;
46 |
47 | // position of our player in the world
48 | var playerPosition:Point;
49 | // movement direction of player (angle in radians)
50 | var playerDirection:Float;
51 |
52 | // distance from camera to player
53 | var cameraDistance:Float;
54 | // camera height from floor level
55 | var cameraHeight:Float;
56 |
57 | // model cache, used for model and animation loading
58 | var cache : h3d.prim.ModelCache;
59 |
60 | // tells us whether player is currently moving or not
61 | var isMoving:Bool = false;
62 | // current movement speed of player
63 | var movementSpeed:Float = 0.0;
64 |
65 | // some player movement characteristics
66 | var walkSpeed:Float = 0.04;
67 | var turnSpeed:Float = 0.01;
68 |
69 | // world's bounding rectangle
70 | var worldBounds:Rect;
71 |
72 | var walkingAnimation:h3d.anim.Animation;
73 |
74 | // Cylinder mesh to visualize collision bounds of player object
75 | var cylinder:h3d.scene.Mesh;
76 |
77 | // Actual collision object for player object
78 | var circle:differ.shapes.Circle;
79 | // Collision bounds for every obstacle in the scene
80 | var obstacles:Array;
81 |
82 | var interactive:h3d.scene.Interactive;
83 |
84 | override function init()
85 | {
86 | // let's create and setup lighing on the scene
87 | light = new h3d.scene.DirLight(new h3d.Vector( 0.3, -0.4, -0.9), s3d);
88 | light.enableSpecular = true;
89 | light.color.set(0.28, 0.28, 0.28);
90 | s3d.lightSystem.ambientLight.set(0.74, 0.74, 0.74);
91 |
92 | // load model and create player object
93 | cache = new h3d.prim.ModelCache();
94 | player = cache.loadModel(hxd.Res.Model);
95 | player.scale(1 / 20);
96 | player.rotate(0, 0, Math.PI / 2);
97 | s3d.addChild(player);
98 |
99 | playerPosition = new Point(player.x, player.y);
100 | playerDirection = Math.PI / 2;
101 |
102 | // load walking animation from the cache
103 | walkingAnimation = cache.loadAnimation(hxd.Res.Model);
104 |
105 | worldBounds = new Rect(-10, -10, 20, 20);
106 |
107 | // create cube primitive which we will use for floor object
108 | var prim = new h3d.prim.Cube(worldBounds.width, worldBounds.height, 1.0);
109 | // translate it so its center will be at the center of the cube
110 | // prim.translate( -0.5 * worldBounds.width, -0.5 * worldBounds.height, -0.5);
111 | // unindex the faces to create hard edges normals
112 | prim.unindex();
113 | // add face normals
114 | prim.addNormals();
115 | // add texture coordinates
116 | prim.addUVs();
117 | // access the logo resource and convert it to a texture
118 | var tex = hxd.Res.load("hxlogo.png").toImage().toTexture();
119 | // create a material with this texture
120 | var mat = h3d.mat.Material.create(tex);
121 | // create textured floor
122 | var floor = new h3d.scene.Mesh(prim, mat, s3d);
123 | // set the cube color
124 | floor.material.color.setColor(0xFFB280);
125 | // put it under player
126 | floor.x = worldBounds.x;
127 | floor.y = worldBounds.y;
128 | floor.z = -1;
129 |
130 | obstacles = [];
131 | // create wall obstacles for our location (they won't have visual representation):
132 | // 1. upper wall
133 | obstacles.push(differ.shapes.Polygon.rectangle(worldBounds.x - 1, worldBounds.y - 1, worldBounds.width + 1, 1, false));
134 | // 2. right wall
135 | obstacles.push(differ.shapes.Polygon.rectangle(worldBounds.x + worldBounds.width, worldBounds.y - 1, 1, worldBounds.height + 1, false));
136 | // 3. bottom wall
137 | obstacles.push(differ.shapes.Polygon.rectangle(worldBounds.x, worldBounds.y + worldBounds.height, worldBounds.width + 1, 1, false));
138 | // 4. left wall
139 | obstacles.push(differ.shapes.Polygon.rectangle(worldBounds.x - 1, worldBounds.y, 1, worldBounds.height + 1, false));
140 |
141 | // create cylinder primitive to visualize collision shape of character.
142 | var prim = new h3d.prim.Cylinder(12, 0.35, 0.1);
143 | // translate it so its center will be at the bottom's center
144 | // unindex the faces to create hard edges normals
145 | // add face normals
146 | prim.addNormals();
147 | // add texture coordinates
148 | prim.addTCoords();
149 | // create colored mesh
150 | cylinder = new h3d.scene.Mesh(prim, s3d);
151 | // set the cylinder color
152 | cylinder.material.color.setColor(0x00ff00);
153 | cylinder.material.receiveShadows = false;
154 | cylinder.material.mainPass.culling = None;
155 |
156 | // create actual collision object for player
157 | circle = new differ.shapes.Circle(0, 0, 0.35);
158 |
159 | // let's create obstacles for our level:
160 | // create cube primitive which we will use for obstacle objects
161 | var prim = new h3d.prim.Cube(1.0, 1.0, 1.0);
162 | // unindex the faces to create hard edges normals
163 | prim.unindex();
164 | // add face normals
165 | prim.addNormals();
166 | // add texture coordinates
167 | prim.addUVs();
168 | for (i in 0...50)
169 | {
170 | // create mesh object which will be rendered on the scene
171 | var cube = new h3d.scene.Mesh(prim, s3d);
172 | // set random color
173 | cube.material.color.setColor(Std.int(Math.random() * 0xff0000));
174 | // disable shadows
175 | cube.material.receiveShadows = false;
176 | cube.material.shadows = false;
177 | // scale and place it randomly on the scene
178 | var scale = 0.3 + 0.7 * Math.random(); // scale will be in the range from 0.3 to 1.0
179 | cube.scale(scale);
180 | cube.x = worldBounds.x + Math.random() * (worldBounds.width - scale);
181 | cube.y = worldBounds.y + Math.random() * (worldBounds.height - scale);
182 |
183 | // create actual collision object for obstacle
184 | obstacles.push(differ.shapes.Polygon.square(cube.x, cube.y, scale, false));
185 | }
186 |
187 | collideWithObstacles();
188 |
189 | // setup camera params
190 | cameraDistance = 15;
191 | cameraHeight = 5;
192 | updateCamera();
193 |
194 | interactive = new h3d.scene.Interactive(floor.getCollider(), s3d);
195 | interactive.onMove = function(e:hxd.Event)
196 | {
197 | if (hxd.Key.isDown(hxd.Key.MOUSE_LEFT))
198 | {
199 | var dx = e.relX - playerPosition.x;
200 | var dy = e.relY - playerPosition.y;
201 | playerDirection = Math.atan2(dy, dx);
202 | }
203 | }
204 | }
205 |
206 | override function update(dt:Float)
207 | {
208 | // check whether player moves forward or backward
209 | var playerSpeed = 0.0;
210 |
211 | if (hxd.Key.isDown(hxd.Key.UP))
212 | {
213 | playerSpeed += 1;
214 | }
215 | if (hxd.Key.isDown(hxd.Key.DOWN))
216 | {
217 | playerSpeed -= 1;
218 | }
219 |
220 | if (hxd.Key.isDown(hxd.Key.MOUSE_LEFT))
221 | {
222 | playerSpeed = 1;
223 | }
224 |
225 | // check if player is running
226 | var runningMultiplicator = 1.0;
227 | if (hxd.Key.isDown(hxd.Key.SHIFT))
228 | {
229 | // running forward should be faster than backward
230 | if (playerSpeed < 0)
231 | {
232 | runningMultiplicator = 1.3;
233 | }
234 | else
235 | {
236 | runningMultiplicator = 2;
237 | }
238 | }
239 |
240 | // check if player is turning
241 | if (hxd.Key.isDown(hxd.Key.LEFT))
242 | {
243 | playerDirection -= turnSpeed * runningMultiplicator;
244 | }
245 | if (hxd.Key.isDown(hxd.Key.RIGHT))
246 | {
247 | playerDirection += turnSpeed * runningMultiplicator;
248 | }
249 |
250 | if (playerSpeed != 0)
251 | {
252 | // update player's position if its moving
253 | playerSpeed *= runningMultiplicator;
254 |
255 | playerPosition.x += Math.cos(playerDirection) * walkSpeed * playerSpeed;
256 | playerPosition.y += Math.sin(playerDirection) * walkSpeed * playerSpeed;
257 |
258 | // Check collisions with each obstacle on the scene
259 | collideWithObstacles();
260 |
261 | // change player's animation if its speed has been changed
262 | if (movementSpeed != playerSpeed)
263 | {
264 | if (playerSpeed > 0)
265 | {
266 | // playing animation for walking forward
267 | // if player is running or walking, then we need to adjust animations speed
268 | player.playAnimation(walkingAnimation).speed = runningMultiplicator;
269 | }
270 | else
271 | {
272 | // need to play backward animation, but i don't have one
273 | // so i won't play anything :(
274 | }
275 |
276 | movementSpeed = playerSpeed;
277 | }
278 |
279 | isMoving = true;
280 | }
281 | else
282 | {
283 | // if player isn't moving we need to reset some of its params
284 | if (isMoving)
285 | {
286 | player.stopAnimation();
287 | // or migth play idle animation (use switchAnimation() method)...
288 | }
289 |
290 | movementSpeed = 0;
291 | isMoving = false;
292 | }
293 |
294 | // update player's rotation
295 | player.setRotation(0, 0, playerDirection + Math.PI / 2);
296 |
297 | // and don't forget to update camera's position
298 | updateCamera();
299 | }
300 |
301 | function collideWithObstacles()
302 | {
303 | circle.x = playerPosition.x;
304 | circle.y = playerPosition.y;
305 |
306 | for (i in 0...obstacles.length)
307 | {
308 | var obstacle = obstacles[i];
309 |
310 | // check collision between circle (player) and rectangular obstacle (box or wall)
311 | var collideInfo = differ.Collision.shapeWithShape(circle, obstacle);
312 | if (collideInfo != null)
313 | {
314 | // if there is collision then we need to resolve collision.
315 | // in our case we just move player outside of bounds of the box
316 | circle.x += collideInfo.separationX;
317 | circle.y += collideInfo.separationY;
318 | }
319 | }
320 |
321 | playerPosition.x = circle.x;
322 | playerPosition.y = circle.y;
323 |
324 | // and finally set player's position
325 | player.x = playerPosition.x;
326 | player.y = playerPosition.y;
327 |
328 | // and player's marker position
329 | cylinder.x = playerPosition.x;
330 | cylinder.y = playerPosition.y;
331 | }
332 |
333 | function updateCamera()
334 | {
335 | var cameraZ = cameraHeight;
336 | var cameraXYDist = Math.sqrt(cameraDistance * cameraDistance - cameraHeight * cameraHeight);
337 | var cameraXYAngle = Math.PI / 4;
338 | var cameraX = player.x - cameraXYDist * Math.cos(cameraXYAngle);
339 | var cameraY = player.y - cameraXYDist * Math.sin(cameraXYAngle);
340 |
341 | s3d.camera.pos.set(cameraX, cameraY, cameraZ);
342 | s3d.camera.target.set(player.x, player.y, player.z);
343 | }
344 |
345 | static function main() {
346 | hxd.Res.initEmbed();
347 | new PlayerMovement();
348 | }
349 | }
--------------------------------------------------------------------------------
/17_heaps_3d_scene/index.html:
--------------------------------------------------------------------------------
1 |
2 | interactive
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/17_heaps_3d_scene/interactive_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hlsdl
3 | -lib differ
4 | -hl interactive.hl
5 | -main PlayerMovement
6 | -D windowSize=1024x768
7 |
--------------------------------------------------------------------------------
/17_heaps_3d_scene/interactive_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib differ
3 | -js interactive.js
4 | -main PlayerMovement
5 | -debug
6 |
--------------------------------------------------------------------------------
/17_heaps_3d_scene/interactive_swf.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib differ
3 | -swf interactive.swf
4 | -swf-header 1280:800:60:FFFFFF
5 | -swf-version 15.0
6 | -main PlayerMovement
7 |
--------------------------------------------------------------------------------
/17_heaps_3d_scene/res/.tmp/Model.hmd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/17_heaps_3d_scene/res/.tmp/Model.hmd
--------------------------------------------------------------------------------
/17_heaps_3d_scene/res/.tmp/hashes.json:
--------------------------------------------------------------------------------
1 | {
2 | "Model.FBX": "b709d3e52d1ef2f375e76a42d85b6927dd71f053"
3 | }
--------------------------------------------------------------------------------
/17_heaps_3d_scene/res/.tmp/times.dat:
--------------------------------------------------------------------------------
1 | by9:Model.FBXi1538393086h
--------------------------------------------------------------------------------
/17_heaps_3d_scene/res/Skeleton01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/17_heaps_3d_scene/res/Skeleton01.png
--------------------------------------------------------------------------------
/17_heaps_3d_scene/res/Sword01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/17_heaps_3d_scene/res/Sword01.png
--------------------------------------------------------------------------------
/17_heaps_3d_scene/res/hxlogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/17_heaps_3d_scene/res/hxlogo.png
--------------------------------------------------------------------------------
/18_heaps_scaleGrid/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "game_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/18_heaps_scaleGrid/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "game_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "game_hl.hxml"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/18_heaps_scaleGrid/Game.hx:
--------------------------------------------------------------------------------
1 | import h2d.TileGroup;
2 | import hxd.Key;
3 | import hxd.App;
4 |
5 | /**
6 | * ScaleGrid usage example.
7 | * ScaleGrid class implements https://en.wikipedia.org/wiki/9-slice_scaling for Heaps.
8 | * Asset taken from Kenney's asset pack: https://opengameart.org/content/pixel-ui-pack-750-assets
9 | */
10 | class Game extends hxd.App
11 | {
12 | static function main()
13 | {
14 | hxd.Res.initEmbed();
15 |
16 | new Game();
17 | }
18 |
19 | override function init()
20 | {
21 | var tile = hxd.Res.load("space.png").toImage().toTile();
22 |
23 | // first argument is tile which will be sliced and tiled
24 | // second argument is border width, which is the same on the left and on the right
25 | // third argument is border height, which is the same on the top and on the bottom
26 | var scaleGrid = new h2d.ScaleGrid(tile, 2, 2, s2d);
27 | scaleGrid.width = 300;
28 | scaleGrid.height = 200;
29 | scaleGrid.x = scaleGrid.y = 100;
30 | }
31 | }
--------------------------------------------------------------------------------
/18_heaps_scaleGrid/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/18_heaps_scaleGrid/game_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hlsdl
3 | -hl game.hl
4 | -main Game
5 |
6 |
--------------------------------------------------------------------------------
/18_heaps_scaleGrid/game_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -js game.js
3 | -main Game
4 | -debug
5 |
6 |
--------------------------------------------------------------------------------
/18_heaps_scaleGrid/index.html:
--------------------------------------------------------------------------------
1 |
2 | BitmapFont
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/18_heaps_scaleGrid/res/space.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/18_heaps_scaleGrid/res/space.png
--------------------------------------------------------------------------------
/19_heaps_layers/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "game_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/19_heaps_layers/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "game_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "game_hl.hxml"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/19_heaps_layers/Game.hx:
--------------------------------------------------------------------------------
1 | import hxd.Key;
2 | import hxd.res.TiledMap;
3 | import hxd.App;
4 |
5 | /**
6 | * Layers usage example.
7 | * h2d.Layers class could be used as a lighter alternative to object hierarchies.
8 | * As you could guess from its name, this class organizes its children in separate layers.
9 | * Layers are divided by their indices. Layers with lower indices are drawn first, and layer with higher indices are drawn later.
10 | * In Heaps this class is used in h2d.CdvLevel class, so each "layer" is used for separate tile layer from tilemap.
11 | *
12 | * For this example we'll try to load Tiled map.
13 | * This example is modified version of "Drawing tiles" example from official Heaps site: https://heaps.io/documentation/drawing-tiles.html
14 | *
15 | * Assets for this project taken from official Tiled examples: https://github.com/bjorn/tiled/tree/master/examples/
16 | */
17 | class Game extends hxd.App
18 | {
19 | static function main()
20 | {
21 | hxd.Res.initEmbed();
22 | new Game();
23 | }
24 |
25 | var layers:h2d.Layers;
26 |
27 | override function init()
28 | {
29 | // load map data
30 | var mapData:TiledMapData = hxd.Res.sewers.toMap();
31 |
32 | // get tile image (tiles.png) from resources
33 | var tileImage = hxd.Res.load("sewer_tileset.png").toImage().toTile();
34 | // tile size
35 | var tw:Int = 24;
36 | var th:Int = 24;
37 | // map size
38 | var mw = mapData.width;
39 | var mh = mapData.height;
40 |
41 | // make sub tiles from tile
42 | var tiles = [];
43 | for (y in 0...Std.int(tileImage.height / th))
44 | {
45 | for (x in 0...Std.int(tileImage.width / tw))
46 | {
47 | var t = tileImage.sub(x * tw, y * th, tw, th, 0, 0);
48 | tiles.push(t);
49 | }
50 | }
51 |
52 | // create h2d.Layers object and add it to 2d scene
53 | layers = new h2d.Layers(s2d);
54 |
55 | // iterate over all layers
56 | for (layer in mapData.layers)
57 | {
58 | // get layer index
59 | var layerIndex:Int = mapData.layers.indexOf(layer);
60 | // create tile group for this layer
61 | var layerGroup:h2d.TileGroup = new h2d.TileGroup(tiles[0]);
62 | // and add it to layers object at specified index
63 | layers.add(layerGroup, layerIndex);
64 | // you can also add objects to layer over and under specified objects
65 | // by using `over()` and `under()` methods
66 |
67 | // iterate on x and y
68 | for (y in 0...mh)
69 | {
70 | for (x in 0...mw)
71 | {
72 | // get the tile id at the current position
73 | var tid = layer.data[x + y * mw];
74 | if (tid != 0) // skip transparent tiles
75 | {
76 | // add a tile to layer
77 | layerGroup.add(x * tw, y * tw, tiles[tid - 1]);
78 | }
79 | }
80 | }
81 |
82 | // you can also iterate through all objects on specified layer with `getLayer()` method
83 | for (object in layers.getLayer(1))
84 | {
85 | object.alpha = 0.5;
86 | }
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/19_heaps_layers/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/19_heaps_layers/game_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hlsdl
3 | -hl game.hl
4 | -main Game
5 |
6 |
--------------------------------------------------------------------------------
/19_heaps_layers/game_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -js game.js
3 | -main Game
4 | -debug
5 |
6 |
--------------------------------------------------------------------------------
/19_heaps_layers/index.html:
--------------------------------------------------------------------------------
1 |
2 | BitmapFont
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/19_heaps_layers/res/sewer_tileset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/19_heaps_layers/res/sewer_tileset.png
--------------------------------------------------------------------------------
/19_heaps_layers/res/sewers.tmx:
--------------------------------------------------------------------------------
1 |
2 |
17 |
--------------------------------------------------------------------------------
/20_heaps_flow/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "game_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/20_heaps_flow/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "game_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "game_hl.hxml"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/20_heaps_flow/Game.hx:
--------------------------------------------------------------------------------
1 | import h3d.mat.Material;
2 | import hxd.App;
3 |
4 | /**
5 | * h2d.Flow usage example.
6 | * Flow can be seen as flexible container
7 | */
8 | class Game extends hxd.App
9 | {
10 | static function main()
11 | {
12 | hxd.Res.initEmbed();
13 | new Game();
14 | }
15 |
16 | var flow:h2d.Flow;
17 |
18 | override function init()
19 | {
20 | flow = new h2d.Flow(s2d);
21 | // set flow direction
22 | // horizontal flow means that elements will placed horizontally until max width is reached
23 | flow.isVertical = false;
24 | // set max width
25 | flow.maxWidth = s2d.width - 100;
26 |
27 | // set min width, so width of Flow object won't be less than this value
28 | flow.minWidth = 200;
29 | // set multiline to true, so if total width of added objects is more than max width, then new line will be started
30 | flow.multiline = true;
31 | flow.x = 0.5 * (s2d.width - flow.maxWidth);
32 | flow.y = 50;
33 | // set alignment
34 | flow.horizontalAlign = Middle;
35 | flow.verticalAlign = Top;
36 | // set spacing between added objects
37 | flow.horizontalSpacing = 10;
38 | flow.verticalSpacing = 15;
39 | // set padding between objects and outer borders
40 | flow.padding = 10;
41 |
42 | // let's add some objects to flow
43 | var tile = h2d.Tile.fromColor(0xffffff, 64, 64);
44 | for (i in 0...30)
45 | {
46 | var b = new h2d.Bitmap(tile);
47 | b.scaleX = b.scaleY = Math.random() + 1;
48 | b.color.set(Math.random(), Math.random(), Math.random());
49 | flow.addChild(b);
50 | }
51 |
52 | // set flow border, so we can see its actual size
53 | flow.backgroundTile = hxd.Res.load("space.png").toImage().toTile();
54 | flow.borderWidth = flow.borderHeight = 2;
55 |
56 | // Get flow properties of the first element added to flow object.
57 | // We use index of 1 because first actual child of flow object is background border object.
58 | var flowProp = flow.getProperties(flow.getChildAt(1));
59 | if (flowProp != null)
60 | {
61 | // set align specific to this object
62 | flowProp.horizontalAlign = Left;
63 | flowProp.verticalAlign = Bottom;
64 | }
65 |
66 | // recalculate positions of added objects
67 | flow.needReflow = true;
68 | flow.reflow();
69 | }
70 |
71 | override function update(dt:Float)
72 | {
73 | // lets change size of flow object, so we could see it in action
74 | flow.maxWidth = Std.int(s2d.mouseX - flow.x);
75 | // and recalculate object positions inside
76 | flow.reflow();
77 | }
78 | }
--------------------------------------------------------------------------------
/20_heaps_flow/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/20_heaps_flow/game_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hlsdl
3 | -hl game.hl
4 | -main Game
5 |
6 |
--------------------------------------------------------------------------------
/20_heaps_flow/game_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -js game.js
3 | -main Game
4 | -debug
5 |
6 |
--------------------------------------------------------------------------------
/20_heaps_flow/index.html:
--------------------------------------------------------------------------------
1 |
2 | BitmapFont
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/20_heaps_flow/res/space.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/20_heaps_flow/res/space.png
--------------------------------------------------------------------------------
/21_heaps_sound_effects/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3 | // Pointez pour afficher la description des attributs existants.
4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "chrome",
9 | "request": "launch",
10 | "name": "Chrome WebGL",
11 | "url": "file://${workspaceFolder}/index.html",
12 | "webRoot": "${workspaceFolder}",
13 | "preLaunchTask": "HeapsJS"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "launch",
18 | "type": "hl",
19 | "hxml": "game_hl.hxml",
20 | "cwd": "${workspaceRoot}",
21 | "preLaunchTask": "HeapsHL"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/21_heaps_sound_effects/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "haxe",
8 | "args": "active configuration",
9 | "group": {
10 | "kind": "build",
11 | "isDefault": true
12 | }
13 | },
14 | {
15 | "label": "HeapsJS",
16 | "type": "hxml",
17 | "file": "game_js.hxml"
18 | },
19 | {
20 | "label": "HeapsHL",
21 | "type": "hxml",
22 | "file": "game_hl.hxml"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/21_heaps_sound_effects/Game.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Heaps sound effect usage example.
3 | * Sound effects modify how it will sound :)
4 | * You can find all supported effects in hxd.snd.effect package:
5 | * Reverb, LowPass, Pitch, Spatialization are in Heaps v. 1.5.0
6 | * This demo will work correctly only on HashLink target.
7 | * (i think that sound effects are not supported on html5 target currently)
8 | */
9 | class Game extends hxd.App
10 | {
11 | static function main()
12 | {
13 | hxd.Res.initEmbed();
14 | new Game();
15 | }
16 |
17 | // Array of reverb effect presets we will be using in this demo
18 | var presets:Array;
19 | // current index of preset to use
20 | var presetIndex:Int = 0;
21 |
22 | override function init()
23 | {
24 | presets = [];
25 |
26 | // Let's just read all presets that are avaiable in ReverbPreset class.
27 | // They are static fields of this class (for example, DEFAULT and GENERIC).
28 | // You can see this list yourself just by opening `hxd.snd.effect.ReverbPreset` file
29 | // But i just lazy to manually type their names here, so i'll use some reflection:
30 | var presetsFields = Reflect.fields(hxd.snd.effect.ReverbPreset);
31 | for (f in presetsFields)
32 | {
33 | var firstChar = f.charAt(0);
34 | if (firstChar.toUpperCase() == firstChar)
35 | {
36 | presets.push(Reflect.field(hxd.snd.effect.ReverbPreset, f));
37 | }
38 | }
39 | }
40 |
41 | override function update(dt:Float)
42 | {
43 | // we will be listening for Space key to play sound with applied effect.
44 | if (hxd.Key.isPressed(hxd.Key.SPACE))
45 | {
46 | // let's play sound
47 | var channel = hxd.Res.sound_fx.play();
48 | // and apply sound effect to newly created sound channel
49 | channel.addEffect(new hxd.snd.effect.Reverb(presets[presetIndex]));
50 |
51 | // btw, usually you'll apply it this way:
52 | // channel.addEffect(new hxd.snd.effect.Reverb(hxd.snd.effect.ReverbPreset.CONCERTHALL));
53 |
54 | // update preset index so it will be in array bounds
55 | presetIndex++;
56 | presetIndex %= presets.length;
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/21_heaps_sound_effects/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/21_heaps_sound_effects/game_hl.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -lib hldx
3 | -hl game.hl
4 | -main Game
5 |
6 |
--------------------------------------------------------------------------------
/21_heaps_sound_effects/game_js.hxml:
--------------------------------------------------------------------------------
1 | -lib heaps
2 | -js game.js
3 | -main Game
4 | -debug
5 |
6 |
--------------------------------------------------------------------------------
/21_heaps_sound_effects/index.html:
--------------------------------------------------------------------------------
1 |
2 | Sound Effect
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/21_heaps_sound_effects/res/sound_fx.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/21_heaps_sound_effects/res/sound_fx.wav
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/Game.hx:
--------------------------------------------------------------------------------
1 |
2 | // this example contains modified code from Flambe game engine: https://github.com/aduros/flambe
3 | class Game extends hxd.App
4 | {
5 | static function main()
6 | {
7 | hxd.Res.initLocal();
8 |
9 | new Game();
10 | }
11 |
12 | var b:h2d.Bitmap;
13 |
14 | var script:flambe.script.Script;
15 |
16 | override function init()
17 | {
18 | b = new h2d.Bitmap(hxd.Res.haxeLogo.toTile(), s2d);
19 | b.x = 250;
20 | b.y = 250;
21 |
22 | // sequence of actions
23 | var sequence = new flambe.script.Sequence([
24 | // first action is just delay for 2.5 seconds
25 | new flambe.script.Delay(2.5),
26 | // then we just set color to red
27 | new flambe.script.CallFunction(function() { b.color = new h3d.Vector(1.0, 0.0, 0.0, 1.0); }),
28 | // then again delay for another 3.5 seconds
29 | new flambe.script.Delay(3.5),
30 | // and set color to blue
31 | new flambe.script.CallFunction(function() { b.color = new h3d.Vector(0.0, 0.0, 1.0, 1.0); }),
32 | // wait another 1.5 seconds
33 | new flambe.script.Delay(1.5),
34 | // and set color to normal
35 | new flambe.script.CallFunction(function() { b.color = new h3d.Vector(1.0, 1.0, 1.0, 1.0); })
36 | ]);
37 |
38 | // let's repeat this sequence forever (-1 means forever)
39 | var repeat = new flambe.script.Repeat(sequence, -1);
40 |
41 | // and create script object, which will run our repeat action
42 | script = new flambe.script.Script();
43 | script.run(repeat);
44 |
45 | // you want to execute this sequence just one time, then you could just call script.run(sequence);
46 | }
47 |
48 | override function update(dt:Float)
49 | {
50 | // update script object
51 | script.update(hxd.Timer.elapsedTime);
52 |
53 | // if you'll want to stop this script, then you can just call script.stopAll() method.
54 | }
55 | }
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/animation/AnimatedFloat.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.animation;
6 |
7 | import flambe.animation.Binding;
8 | import flambe.animation.Ease;
9 | import flambe.util.Value;
10 |
11 | /**
12 | * A Float value that may be animated over time.
13 | */
14 | class AnimatedFloat extends Value
15 | {
16 | /**
17 | * The behavior that is currently animating the value, or null if the value is not being
18 | * animated.
19 | */
20 | public var behavior (get, set) :Behavior;
21 |
22 | public function new (value :Float)
23 | {
24 | super(value);
25 | }
26 |
27 | override private function set__ (value :Float) :Float
28 | {
29 | _behavior = null;
30 | return super.set__(value);
31 | }
32 |
33 | public function update (dt :Float)
34 | {
35 | if (_behavior != null) {
36 | super.set__(_behavior.update(dt));
37 | if (_behavior.isComplete()) {
38 | _behavior = null;
39 | }
40 | }
41 | }
42 |
43 | /**
44 | * Animates between the two given values.
45 | *
46 | * @param from The initial value.
47 | * @param to The target value.
48 | * @param seconds The animation duration, in seconds.
49 | * @param easing The easing function to use, defaults to `Ease.linear`.
50 | */
51 | public function animate (from :Float, to :Float, seconds :Float, ?easing :EaseFunction)
52 | {
53 | set__(from);
54 | animateTo(to, seconds, easing);
55 | }
56 |
57 | /**
58 | * Animates between the current value and the given value.
59 | *
60 | * @param to The target value.
61 | * @param seconds The animation duration, in seconds.
62 | * @param easing The easing function to use, defaults to `Ease.linear`.
63 | */
64 | public function animateTo (to :Float, seconds :Float, ?easing :EaseFunction)
65 | {
66 | behavior = new Tween(_value, to, seconds, easing);
67 | }
68 |
69 | /**
70 | * Animates the current value by the given delta.
71 | *
72 | * @param by The delta added to the current value to get the target value.
73 | * @param seconds The animation duration, in seconds.
74 | * @param easing The easing function to use, defaults to `Ease.linear`.
75 | */
76 | public function animateBy (by :Float, seconds :Float, ?easing :EaseFunction)
77 | {
78 | behavior = new Tween(_value, _value + by, seconds, easing);
79 | }
80 |
81 | inline public function bindTo (to :Value, ?fn :BindingFunction)
82 | {
83 | behavior = new Binding(to, fn);
84 | }
85 |
86 | private function set_behavior (behavior :Behavior) :Behavior
87 | {
88 | _behavior = behavior;
89 | update(0);
90 | return behavior;
91 | }
92 |
93 | inline private function get_behavior () :Behavior
94 | {
95 | return _behavior;
96 | }
97 |
98 | private var _behavior :Behavior = null;
99 | }
100 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/animation/Behavior.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.animation;
6 |
7 | interface Behavior
8 | {
9 | function update (dt :Float) :Float;
10 | function isComplete () :Bool;
11 | }
12 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/animation/Binding.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.animation;
6 |
7 | import flambe.util.Value;
8 |
9 | typedef BindingFunction = Float -> Float;
10 |
11 | class Binding
12 | implements Behavior
13 | {
14 | public function new (target :Value, ?fn :BindingFunction)
15 | {
16 | _target = target;
17 | _fn = fn;
18 | }
19 |
20 | public function update (dt :Float) :Float
21 | {
22 | var value = _target._;
23 | // TODO: Be lazy and only call _fn when the value is changed?
24 | if (_fn != null) {
25 | return _fn(value);
26 | } else {
27 | return value;
28 | }
29 | }
30 |
31 | public function isComplete () :Bool
32 | {
33 | return false;
34 | }
35 |
36 | private var _target :Value;
37 | private var _fn :BindingFunction;
38 | }
39 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/animation/Ease.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.animation;
6 |
7 | import flambe.math.FMath;
8 |
9 | /** Receives and returns a number between [0,1]. */
10 | typedef EaseFunction = Float -> Float;
11 |
12 | /**
13 | * Easing functions that can be used to animate values. For a cheat sheet, see .
14 | */
15 | class Ease
16 | {
17 | // Adapted from FlashPunk:
18 | // https://github.com/Draknek/FlashPunk/blob/master/net/flashpunk/utils/Ease.as
19 | //
20 | // Operation of in/out easers:
21 | //
22 | // in(t)
23 | // return t;
24 | // out(t)
25 | // return 1 - in(1 - t);
26 | // inOut(t)
27 | // return (t <= .5) ? in(t * 2) / 2 : out(t * 2 - 1) / 2 + .5;
28 |
29 | /** Linear, no easing. */
30 | public static function linear (t :Float) :Float
31 | {
32 | return t;
33 | }
34 |
35 | /** Quadratic in. */
36 | public static function quadIn (t :Float) :Float
37 | {
38 | return t * t;
39 | }
40 |
41 | /** Quadratic out. */
42 | public static function quadOut (t :Float) :Float
43 | {
44 | return t * (2 - t);
45 | }
46 |
47 | /** Quadratic in and out. */
48 | public static function quadInOut (t :Float) :Float
49 | {
50 | return t <= .5 ? t * t * 2 : 1 - (--t) * t * 2;
51 | }
52 |
53 | /** Quadratic out and in */
54 | static public function quadOutIn(t:Float):Float
55 | {
56 | return (t < 0.5) ? -0.5 * (t = (t * 2)) * (t - 2) : 0.5 * (t = (t * 2 - 1)) * t + 0.5;
57 | }
58 |
59 | /** Cubic in. */
60 | public static function cubeIn (t :Float) :Float
61 | {
62 | return t * t * t;
63 | }
64 |
65 | /** Cubic out. */
66 | public static function cubeOut (t :Float) :Float
67 | {
68 | return 1 + (--t) * t * t;
69 | }
70 |
71 | /** Cubic in and out. */
72 | public static function cubeInOut (t :Float) :Float
73 | {
74 | return t <= .5 ? t * t * t * 4 : 1 + (--t) * t * t * 4;
75 | }
76 |
77 | /** Cubic out and in. */
78 | static public function cubeOutIn(t:Float):Float
79 | {
80 | return 0.5 * ((t = t * 2 - 1) * t * t + 1);
81 | }
82 |
83 | /** Quartic in. */
84 | public static function quartIn (t :Float) :Float
85 | {
86 | return t * t * t * t;
87 | }
88 |
89 | /** Quartic out. */
90 | public static function quartOut (t :Float) :Float
91 | {
92 | return 1 - (--t) * t * t * t;
93 | }
94 |
95 | /** Quartic in and out. */
96 | public static function quartInOut (t :Float) :Float
97 | {
98 | return t <= .5 ? t * t * t * t * 8 : (1 - (t = t * 2 - 2) * t * t * t) / 2 + .5;
99 | }
100 |
101 | /** Quartic out and in */
102 | static public function quartOutIn(t:Float):Float
103 | {
104 | return (t < 0.5) ? -0.5 * (t = t * 2 - 1) * t * t * t + 0.5 : 0.5 * (t = t * 2 - 1) * t * t * t + 0.5;
105 | }
106 |
107 | /** Quintic in. */
108 | public static function quintIn (t :Float) :Float
109 | {
110 | return t * t * t * t * t;
111 | }
112 |
113 | /** Quintic out. */
114 | public static function quintOut (t :Float) :Float
115 | {
116 | return (t = t - 1) * t * t * t * t + 1;
117 | }
118 |
119 | /** Quintic in and out. */
120 | public static function quintInOut (t :Float) :Float
121 | {
122 | return ((t *= 2) < 1) ? (t * t * t * t * t) / 2 : ((t -= 2) * t * t * t * t + 2) / 2;
123 | }
124 |
125 | /** Quintic out and in. */
126 | static public function quintOutIn(t:Float):Float
127 | {
128 | return 0.5 * ((t = t * 2 - 1) * t * t * t * t + 1);
129 | }
130 |
131 | /** Sine in. */
132 | public static function sineIn (t :Float) :Float
133 | {
134 | return 1 - Math.cos(PIhalf * t);
135 | }
136 |
137 | /** Sine out. */
138 | public static function sineOut (t :Float) :Float
139 | {
140 | return Math.sin(PIhalf * t);
141 | }
142 |
143 | /** Sine in and out. */
144 | public static function sineInOut (t :Float) :Float
145 | {
146 | return .5 - Math.cos(PI * t) / 2;
147 | }
148 |
149 | /** Sine out and in. */
150 | static public function sineOutIn(t:Float):Float {
151 | if (t == 0) return 0
152 | else if (t == 1) return 1
153 | else return (t < 0.5) ? 0.5 * Math.sin((t * 2) * PIhalf) : -0.5 * Math.cos((t * 2 - 1) * PIhalf) + 1;
154 | }
155 |
156 | /** Bounce in. */
157 | public static function bounceIn (t :Float) :Float
158 | {
159 | t = 1 - t;
160 | if (t < B1) return 1 - 7.5625 * t * t;
161 | if (t < B2) return 1 - (7.5625 * (t - B3) * (t - B3) + .75);
162 | if (t < B4) return 1 - (7.5625 * (t - B5) * (t - B5) + .9375);
163 | return 1 - (7.5625 * (t - B6) * (t - B6) + .984375);
164 | }
165 |
166 | /** Bounce out. */
167 | public static function bounceOut (t :Float) :Float
168 | {
169 | if (t < B1) return 7.5625 * t * t;
170 | if (t < B2) return 7.5625 * (t - B3) * (t - B3) + .75;
171 | if (t < B4) return 7.5625 * (t - B5) * (t - B5) + .9375;
172 | return 7.5625 * (t - B6) * (t - B6) + .984375;
173 | }
174 |
175 | /** Bounce in and out. */
176 | public static function bounceInOut (t :Float) :Float
177 | {
178 | if (t < .5) {
179 | t = 1 - t * 2;
180 | if (t < B1) return (1 - 7.5625 * t * t) / 2;
181 | if (t < B2) return (1 - (7.5625 * (t - B3) * (t - B3) + .75)) / 2;
182 | if (t < B4) return (1 - (7.5625 * (t - B5) * (t - B5) + .9375)) / 2;
183 | return (1 - (7.5625 * (t - B6) * (t - B6) + .984375)) / 2;
184 | }
185 | t = t * 2 - 1;
186 | if (t < B1) return (7.5625 * t * t) / 2 + .5;
187 | if (t < B2) return (7.5625 * (t - B3) * (t - B3) + .75) / 2 + .5;
188 | if (t < B4) return (7.5625 * (t - B5) * (t - B5) + .9375) / 2 + .5;
189 | return (7.5625 * (t - B6) * (t - B6) + .984375) / 2 + .5;
190 | }
191 |
192 | /** Circle in. */
193 | public static function circIn (t :Float) :Float
194 | {
195 | return 1 - Math.sqrt(1 - t * t);
196 | }
197 |
198 | /** Circle out. */
199 | public static function circOut (t :Float) :Float
200 | {
201 | --t;
202 | return Math.sqrt(1 - t * t);
203 | }
204 |
205 | /** Circle in and out. */
206 | public static function circInOut (t :Float) :Float
207 | {
208 | return t <= .5 ? (Math.sqrt(1 - t * t * 4) - 1) / -2 : (Math.sqrt(1 - (t * 2 - 2) * (t * 2 - 2)) + 1) / 2;
209 | }
210 |
211 | /** Circle out and in. */
212 | static public function circOutIn(t:Float):Float
213 | {
214 | return (t < 0.5) ? 0.5 * Math.sqrt(1 - (t = t * 2 - 1) * t) : -0.5 * ((Math.sqrt(1 - (t = t * 2 - 1) * t) - 1) - 1);
215 | }
216 |
217 | /** Exponential in. */
218 | public static function expoIn (t :Float) :Float
219 | {
220 | return Math.pow(2, 10 * (t - 1));
221 | }
222 |
223 | /** Exponential out. */
224 | public static function expoOut (t :Float) :Float
225 | {
226 | return -Math.pow(2, -10 * t) + 1;
227 | }
228 |
229 | /** Exponential in and out. */
230 | public static function expoInOut (t :Float) :Float
231 | {
232 | return t < .5 ? Math.pow(2, 10 * (t * 2 - 1)) / 2 : (-Math.pow(2, -10 * (t * 2 - 1)) + 2) / 2;
233 | }
234 |
235 | /** Exponential out and in. */
236 | static public function expoOutIn(t:Float):Float
237 | {
238 | return (t < 0.5) ? 0.5 * (1 - Math.pow(2, -20 * t)) : (t == 0.5) ? 0.5 : 0.5 * (Math.pow(2, 20 * (t - 1)) + 1);
239 | }
240 |
241 | /** Back in. */
242 | public static function backIn (t :Float) :Float
243 | {
244 | return t * t * (2.70158 * t - 1.70158);
245 | }
246 |
247 | /** Back out. */
248 | public static function backOut (t :Float) :Float
249 | {
250 | return 1 - (--t) * (t) * (-2.70158 * t - 1.70158);
251 | }
252 |
253 | /** Back in and out. */
254 | public static function backInOut (t :Float) :Float
255 | {
256 | t *= 2;
257 | if (t < 1) return t * t * (2.70158 * t - 1.70158) / 2;
258 | t -= 2;
259 | return (1 - t * t * (-2.70158 * t - 1.70158)) / 2 + .5;
260 | }
261 |
262 | /** Elastic in. */
263 | public static function elasticIn (t :Float) :Float
264 | {
265 | return -(ELASTIC_AMPLITUDE * Math.pow(2, 10 * (t -= 1)) * Math.sin( (t - (ELASTIC_PERIOD / PI2 * Math.asin(1 / ELASTIC_AMPLITUDE))) * PI2 / ELASTIC_PERIOD));
266 | }
267 |
268 | /** Elastic out. */
269 | public static function elasticOut (t :Float) :Float
270 | {
271 | return (ELASTIC_AMPLITUDE * Math.pow(2, -10 * t) * Math.sin((t - (ELASTIC_PERIOD / PI2 * Math.asin(1 / ELASTIC_AMPLITUDE))) * PI2 / ELASTIC_PERIOD) + 1);
272 | }
273 |
274 | /** Elastic in and out. */
275 | public static function elasticInOut (t :Float) :Float
276 | {
277 | if (t < 0.5) {
278 | return -0.5 * (Math.pow(2, 10 * (t -= 0.5)) * Math.sin((t - (ELASTIC_PERIOD / 4)) * PI2 / ELASTIC_PERIOD));
279 | }
280 | return Math.pow(2, -10 * (t -= 0.5)) * Math.sin((t - (ELASTIC_PERIOD / 4)) * PI2 / ELASTIC_PERIOD) * 0.5 + 1;
281 | }
282 |
283 | private static inline var PIhalf :Float = FMath.PI / 2;
284 | private static inline var PI :Float = FMath.PI;
285 | private static inline var PI2 :Float = FMath.PI * 2;
286 | private static inline var B1 :Float = 1 / 2.75;
287 | private static inline var B2 :Float = 2 / 2.75;
288 | private static inline var B3 :Float = 1.5 / 2.75;
289 | private static inline var B4 :Float = 2.5 / 2.75;
290 | private static inline var B5 :Float = 2.25 / 2.75;
291 | private static inline var B6 :Float = 2.625 / 2.75;
292 | private static inline var ELASTIC_AMPLITUDE :Float = 1;
293 | private static inline var ELASTIC_PERIOD :Float = 0.4;
294 | }
295 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/animation/Jitter.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.animation;
6 |
7 | class Jitter
8 | implements Behavior
9 | {
10 | public var base (default, null) :Float;
11 | public var strength (default, null) :Float;
12 |
13 | public function new (base :Float, strength :Float)
14 | {
15 | this.base = base;
16 | this.strength = strength;
17 | }
18 |
19 | public function update (dt :Float) :Float
20 | {
21 | return base + 2*Math.random()*strength - strength;
22 | }
23 |
24 | public function isComplete () :Bool
25 | {
26 | return false;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/animation/Tween.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.animation;
6 |
7 | import flambe.animation.Ease;
8 |
9 | class Tween
10 | implements Behavior
11 | {
12 | public var elapsed (default, null) :Float;
13 |
14 | public function new (from :Float, to :Float, seconds :Float, ?easing :EaseFunction)
15 | {
16 | _from = from;
17 | _to = to;
18 | _duration = seconds;
19 | elapsed = 0;
20 | _easing = (easing != null) ? easing : Ease.linear;
21 | }
22 |
23 | public function update (dt :Float) :Float
24 | {
25 | elapsed += dt;
26 |
27 | if (elapsed >= _duration) {
28 | return _to;
29 | } else {
30 | return _from + (_to - _from)*_easing(elapsed/_duration);
31 | }
32 | }
33 |
34 | public function isComplete () :Bool
35 | {
36 | return elapsed >= _duration;
37 | }
38 |
39 | private var _from :Float;
40 | private var _to :Float;
41 | private var _duration :Float;
42 | private var _easing :EaseFunction;
43 | }
44 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/math/FMath.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.math;
6 |
7 | /**
8 | * Some handy math functions, and inlinable constants.
9 | */
10 | class FMath
11 | {
12 | public static inline var E = 2.718281828459045;
13 | public static inline var LN2 = 0.6931471805599453;
14 | public static inline var LN10 = 2.302585092994046;
15 | public static inline var LOG2E = 1.4426950408889634;
16 | public static inline var LOG10E = 0.43429448190325176;
17 | public static inline var PI = 3.141592653589793;
18 | public static inline var SQRT1_2 = 0.7071067811865476;
19 | public static inline var SQRT2 = 1.4142135623730951;
20 |
21 | // Haxe doesn't specify the size of an int or float, in practice it's 32 bits
22 | /** The lowest integer value in Flash and JS. */
23 | public static inline var INT_MIN :Int = -2147483648;
24 |
25 | /** The highest integer value in Flash and JS. */
26 | public static inline var INT_MAX :Int = 2147483647;
27 |
28 | /** The lowest float value in Flash and JS. */
29 | public static inline var FLOAT_MIN = -1.79769313486231e+308;
30 |
31 | /** The highest float value in Flash and JS. */
32 | public static inline var FLOAT_MAX = 1.79769313486231e+308;
33 |
34 | /** Converts an angle in degrees to radians. */
35 | inline public static function toRadians (degrees :Float) :Float
36 | {
37 | return degrees * PI/180;
38 | }
39 |
40 | /** Converts an angle in radians to degrees. */
41 | inline public static function toDegrees (radians :Float) :Float
42 | {
43 | return radians * 180/PI;
44 | }
45 |
46 | #if !js @:generic #end
47 | inline public static function max (a :T, b :T) :T
48 | {
49 | return (a > b) ? a : b;
50 | }
51 |
52 | #if !js @:generic #end
53 | inline public static function min (a :T, b :T) :T
54 | {
55 | return (a < b) ? a : b;
56 | }
57 |
58 | #if !js @:generic #end
59 | public static function clamp (value :T, min :T, max :T) :T
60 | {
61 | return if (value < min) min
62 | else if (value > max) max
63 | else value;
64 | }
65 |
66 | public static function sign (value :Float) :Int
67 | {
68 | return if (value < 0) -1
69 | else if (value > 0) 1
70 | else 0;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/Action.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | /**
8 | * Represents a unit of execution that is called over time.
9 | */
10 | interface Action
11 | {
12 | /**
13 | * Called when the acting entity has been updated.
14 | *
15 | * @param dt The time elapsed since the last frame, in seconds.
16 | * @returns The amount of time in seconds spent this frame to finish the action, which may be
17 | * less than dt. Or -1 if the action is not yet finished.
18 | */
19 | function update (dt :Float) :Float;
20 | }
21 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/AnimateBy.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | import flambe.animation.AnimatedFloat;
8 | import flambe.animation.Ease;
9 | import flambe.animation.Tween;
10 |
11 | /**
12 | * An action that tweens an AnimatedFloat by a certain delta.
13 | */
14 | class AnimateBy
15 | implements Action
16 | {
17 | public function new (value :AnimatedFloat, by :Float, seconds :Float, ?easing :EaseFunction)
18 | {
19 | _value = value;
20 | _by = by;
21 | _seconds = seconds;
22 | _easing = easing;
23 | }
24 |
25 | public function update (dt :Float) :Float
26 | {
27 | if (_tween == null) {
28 | _tween = new Tween(_value._, _value._ + _by, _seconds, _easing);
29 | _value.behavior = _tween;
30 | _value.update(dt); // Fake an update to account for this frame
31 | }
32 | if (_value.behavior != _tween) {
33 | var overtime = _tween.elapsed - _seconds;
34 | _tween = null;
35 | return (overtime > 0) ? Math.max(0, dt - overtime) : 0;
36 | }
37 | return -1;
38 | }
39 |
40 | private var _tween :Tween;
41 |
42 | private var _value :AnimatedFloat;
43 | private var _by :Float;
44 | private var _seconds :Float;
45 | private var _easing :EaseFunction;
46 | }
47 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/AnimateFrom.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | import flambe.animation.AnimatedFloat;
8 | import flambe.animation.Ease;
9 | import flambe.animation.Tween;
10 |
11 | /**
12 | * An action that tweens an AnimatedFloat from a certain value to its current value.
13 | */
14 | class AnimateFrom
15 | implements Action
16 | {
17 | public function new (value :AnimatedFloat, from :Float, seconds :Float, ?easing :EaseFunction)
18 | {
19 | _value = value;
20 | _from = from;
21 | _to = value._;
22 | _seconds = seconds;
23 | _easing = easing;
24 |
25 | // Move to initial value
26 | value._ = _from;
27 | }
28 |
29 | public function update (dt :Float) :Float
30 | {
31 | if (_tween == null) {
32 | _tween = new Tween(_value._, _to, _seconds, _easing);
33 | _value.behavior = _tween;
34 | _value.update(dt); // Fake an update to account for this frame
35 | }
36 | if (_value.behavior != _tween) {
37 | var overtime = _tween.elapsed - _seconds;
38 | _tween = null;
39 | return (overtime > 0) ? Math.max(0, dt - overtime) : 0;
40 | }
41 | return -1;
42 | }
43 |
44 | private var _tween :Tween;
45 |
46 | private var _value :AnimatedFloat;
47 | private var _from :Float;
48 | private var _to :Float;
49 | private var _seconds :Float;
50 | private var _easing :EaseFunction;
51 | }
52 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/AnimateTo.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | import flambe.animation.AnimatedFloat;
8 | import flambe.animation.Ease;
9 | import flambe.animation.Tween;
10 |
11 | /**
12 | * An action that tweens an AnimatedFloat to a certain value.
13 | */
14 | class AnimateTo
15 | implements Action
16 | {
17 | public function new (value :AnimatedFloat, to :Float, seconds :Float, ?easing :EaseFunction)
18 | {
19 | _value = value;
20 | _to = to;
21 | _seconds = seconds;
22 | _easing = easing;
23 | }
24 |
25 | public function update (dt :Float) :Float
26 | {
27 | if (_tween == null) {
28 | _tween = new Tween(_value._, _to, _seconds, _easing);
29 | _value.behavior = _tween;
30 | _value.update(dt); // Fake an update to account for this frame
31 | }
32 | if (_value.behavior != _tween) {
33 | var overtime = _tween.elapsed - _seconds;
34 | _tween = null;
35 | return (overtime > 0) ? Math.max(0, dt - overtime) : 0;
36 | }
37 | return -1;
38 | }
39 |
40 | private var _tween :Tween;
41 |
42 | private var _value :AnimatedFloat;
43 | private var _to :Float;
44 | private var _seconds :Float;
45 | private var _easing :EaseFunction;
46 | }
47 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/CallFunction.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | /**
8 | * An action that calls a given function once and immediately completes.
9 | */
10 | class CallFunction
11 | implements Action
12 | {
13 | /**
14 | * @param fn The function to call when this action is run.
15 | */
16 | public function new (fn :Void -> Void)
17 | {
18 | _fn = fn;
19 | }
20 |
21 | public function update (dt :Float)
22 | {
23 | _fn();
24 | return 0;
25 | }
26 |
27 | private var _fn :Void -> Void;
28 | }
29 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/Delay.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | /**
8 | * An action that simply waits for a certain amount of time to pass before finishing.
9 | */
10 | class Delay
11 | implements Action
12 | {
13 | public function new (seconds :Float)
14 | {
15 | _duration = seconds;
16 | _elapsed = 0;
17 | }
18 |
19 | public function update (dt :Float) :Float
20 | {
21 | _elapsed += dt;
22 | if (_elapsed >= _duration) {
23 | var overtime = _elapsed - _duration;
24 | _elapsed = 0;
25 | return dt - overtime;
26 | }
27 | return -1;
28 | }
29 |
30 | private var _duration :Float;
31 | private var _elapsed :Float;
32 | }
33 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/FirstOf.hx:
--------------------------------------------------------------------------------
1 | package flambe.script;
2 |
3 | using Lambda;
4 |
5 | /**
6 | * An action that manages a list of other actions, running them together in parallel until the
7 | * first of them finishes.
8 | */
9 | class FirstOf
10 | implements Action
11 | {
12 | public function new (?actions :Array)
13 | {
14 | _runningActions = (actions != null) ? cast actions.copy() : [];
15 | }
16 |
17 | public function add (action :Action)
18 | {
19 | _runningActions.push(action);
20 | }
21 |
22 | public function remove (action :Action) :Bool
23 | {
24 | var idx = _runningActions.indexOf(action);
25 | if (idx < 0) {
26 | return false;
27 | }
28 | _runningActions[idx] = null;
29 | return true;
30 | }
31 |
32 | public function removeAll ()
33 | {
34 | _runningActions = [];
35 | }
36 |
37 | public function update (dt :Float) :Float
38 | {
39 | for (action in _runningActions) {
40 | if (action != null) {
41 | var spent = action.update(dt);
42 | if (spent >= 0) {
43 | return spent;
44 | }
45 | }
46 | }
47 |
48 | return -1;
49 | }
50 |
51 | private var _runningActions :Array;
52 | }
53 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/Parallel.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | using Lambda;
8 |
9 | /**
10 | * An action that manages a list of other actions, running them together in parallel until they all
11 | * finish.
12 | */
13 | class Parallel
14 | implements Action
15 | {
16 | public function new (?actions :Array)
17 | {
18 | _completedActions = [];
19 | _runningActions = (actions != null) ? cast actions.copy() : [];
20 | }
21 |
22 | public function add (action :Action)
23 | {
24 | _runningActions.push(action);
25 | }
26 |
27 | public function remove (action :Action) :Bool
28 | {
29 | var idx = _runningActions.indexOf(action);
30 | if (idx < 0) {
31 | return false;
32 | }
33 | _runningActions[idx] = null;
34 | return true;
35 | }
36 |
37 | public function removeAll ()
38 | {
39 | _runningActions = [];
40 | _completedActions = [];
41 | }
42 |
43 | public function update (dt :Float) :Float
44 | {
45 | var done = true;
46 | var maxSpent = 0.0;
47 | for (ii in 0..._runningActions.length) {
48 | var action = _runningActions[ii];
49 | if (action != null) {
50 | var spent = action.update(dt);
51 | if (spent >= 0) {
52 | _runningActions[ii] = null;
53 | _completedActions.push(action);
54 | if (spent > maxSpent) {
55 | maxSpent = spent;
56 | }
57 | } else {
58 | // We can't possibly finish this frame, but continue ticking the rest of the
59 | // actions anyways
60 | done = false;
61 | }
62 | }
63 | }
64 |
65 | if (done) {
66 | _runningActions = _completedActions;
67 | _completedActions = [];
68 | return maxSpent;
69 | }
70 | return -1;
71 | }
72 |
73 | private var _runningActions :Array;
74 | private var _completedActions :Array;
75 | }
76 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/Repeat.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | /**
8 | * An action that repeats another action until it finishes a certain number of times.
9 | */
10 | class Repeat
11 | implements Action
12 | {
13 | /**
14 | * @param count The number of times to repeat the action, or -1 to repeat forever.
15 | */
16 | public function new (action :Action, count :Int = -1)
17 | {
18 | _action = action;
19 | _count = count;
20 | _remaining = count;
21 | }
22 |
23 | public function update (dt :Float) :Float
24 | {
25 | if (_count == 0) {
26 | // Handle the special case of a 0-count Repeat
27 | return 0;
28 | }
29 |
30 | var spent = _action.update(dt);
31 | if (_count > 0 && spent >= 0 && --_remaining == 0) {
32 | _remaining = _count; // Reset state in case this Action is reused
33 | return spent;
34 | }
35 |
36 | // Keep repeating
37 | return -1;
38 | }
39 |
40 | private var _action :Action;
41 |
42 | private var _count :Int;
43 | private var _remaining :Int;
44 | }
45 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/Script.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | import flambe.util.Disposable;
8 |
9 | /**
10 | * Manages a set of actions that are updated over time. Scripts simplify writing composable
11 | * animations.
12 | */
13 | class Script
14 | {
15 | public function new ()
16 | {
17 | stopAll();
18 | }
19 |
20 | /**
21 | * Add an action to this Script.
22 | * @returns A handle that can be disposed to stop the action.
23 | */
24 | public function run (action :Action) :Disposable
25 | {
26 | var handle = new Handle(action);
27 | _handles.push(handle);
28 | return handle;
29 | }
30 |
31 | /**
32 | * Remove all actions from this Script.
33 | */
34 | public function stopAll ()
35 | {
36 | _handles = [];
37 | }
38 |
39 | public function update (dt :Float)
40 | {
41 | var ii = 0;
42 | while (ii < _handles.length) {
43 | var handle = _handles[ii];
44 | if (handle.removed || handle.action.update(dt) >= 0) {
45 | _handles.splice(ii, 1);
46 | } else {
47 | ++ii;
48 | }
49 | }
50 | }
51 |
52 | private var _handles :Array;
53 | }
54 |
55 | private class Handle
56 | implements Disposable
57 | {
58 | public var removed (default, null) :Bool;
59 | public var action :Action;
60 |
61 | public function new (action :Action)
62 | {
63 | removed = false;
64 | this.action = action;
65 | }
66 |
67 | public function dispose ()
68 | {
69 | removed = true;
70 | action = null;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/script/Sequence.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.script;
6 |
7 | using Lambda;
8 |
9 | /**
10 | * An action that manages a list of other actions, running them one-by-one sequentially until they
11 | * all finish.
12 | */
13 | class Sequence
14 | implements Action
15 | {
16 | public function new (?actions :Array)
17 | {
18 | _idx = 0;
19 | _runningActions = (actions != null) ? cast actions.copy() : [];
20 | }
21 |
22 | public function add (action :Action) :Sequence
23 | {
24 | _runningActions.push(action);
25 | return this;
26 | }
27 |
28 | public function remove (action :Action) :Bool
29 | {
30 | var idx = _runningActions.indexOf(action);
31 | if (idx < 0) {
32 | return false;
33 | }
34 | _runningActions[idx] = null;
35 | return true;
36 | }
37 |
38 | public function removeAll ()
39 | {
40 | _idx = 0;
41 | _runningActions = [];
42 | }
43 |
44 | public function update (dt :Float) :Float
45 | {
46 | // The total time taken by the actions updated this frame
47 | var total = 0.0;
48 |
49 | while (true) {
50 | var action = _runningActions[_idx];
51 | if (action != null) {
52 | var spent = action.update(dt-total);
53 | if (spent >= 0) {
54 | // This action completed, add it to the total time
55 | total += spent;
56 | } else {
57 | // This action didn't complete, so neither will this sequence
58 | return -1;
59 | }
60 | }
61 |
62 | ++_idx;
63 | if (_idx >= _runningActions.length) {
64 | // If this is the last action, reset to the starting position and finish
65 | _idx = 0;
66 | break;
67 |
68 | } else if (total > dt) {
69 | // Otherwise, if there are still actions but not enough time to complete them
70 | return -1;
71 | }
72 | }
73 |
74 | return total;
75 | }
76 |
77 | private var _runningActions :Array;
78 | private var _idx :Int;
79 | }
80 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/util/Disposable.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.util;
6 |
7 | /**
8 | * Any object that can be disposed to free its resources and clean things up properly.
9 | */
10 | interface Disposable
11 | {
12 | function dispose () :Void;
13 | }
14 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/flambe/util/Value.hx:
--------------------------------------------------------------------------------
1 | //
2 | // Flambe - Rapid game development
3 | // https://github.com/aduros/flambe/blob/master/LICENSE.txt
4 |
5 | package flambe.util;
6 |
7 | /**
8 | * Wraps a single value.
9 | */
10 | #if !js
11 | @:generic // Generate typed templates on static targets
12 | #end
13 | class Value
14 | {
15 | /**
16 | * The wrapped value, setting this to a different value will fire the `changed` signal.
17 | */
18 | public var _ (get, set) :A;
19 |
20 | public function new (value :A)
21 | {
22 | _value = value;
23 | }
24 |
25 | inline private function get__ () :A
26 | {
27 | return _value;
28 | }
29 |
30 | private function set__ (newValue :A) :A
31 | {
32 | return _value = newValue;
33 | }
34 |
35 | #if debug @:keep #end public function toString () :String
36 | {
37 | return ""+_value;
38 | }
39 |
40 | private var _value :A;
41 | }
42 |
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/22_heaps_flambe_behaviors/res/haxeLogo.png
--------------------------------------------------------------------------------
/22_heaps_flambe_behaviors/res/particlesJson.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/22_heaps_flambe_behaviors/res/particlesJson.json
--------------------------------------------------------------------------------
/23_heaps_read_write_file/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Используйте IntelliSense, чтобы узнать о возможных атрибутах.
3 | // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
4 | // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "HashLink",
9 | "request": "launch",
10 | "type": "hl",
11 | "hxml": "game.hxml",
12 | "cwd": "${workspaceRoot}",
13 | "preLaunchTask": "Build"
14 | },
15 | {
16 | "name": "HashLink",
17 | "request": "attach",
18 | "port": 6112,
19 | "type": "hl",
20 | "hxml": "game.hxml",
21 | "cwd": "${workspaceRoot}",
22 | "preLaunchTask": "Build"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/23_heaps_read_write_file/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "hxml",
8 | "label": "Build",
9 | "file": "game.hxml",
10 | "problemMatcher": [
11 | "$haxe-absolute",
12 | "$haxe",
13 | "$haxe-error",
14 | "$haxe-trace"
15 | ],
16 | "group": {
17 | "kind": "build",
18 | "isDefault": true
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/23_heaps_read_write_file/Game.hx:
--------------------------------------------------------------------------------
1 | import sys.io.File;
2 | import sys.FileSystem;
3 |
4 | class Game extends hxd.App
5 | {
6 | static function main()
7 | {
8 | hxd.Res.initLocal();
9 |
10 | new Game();
11 | }
12 |
13 | override function init()
14 | {
15 | var t = new h2d.Text(hxd.res.DefaultFont.get(), s2d);
16 |
17 | // this file will be stored / searched for in app directory
18 | var fileName = "data.txt";
19 | var readNum = 0;
20 |
21 | if (!FileSystem.exists(fileName))
22 | {
23 | // if there is no such file, then let's create it
24 | File.saveContent(fileName, 'My data...\n${readNum}');
25 | }
26 | else
27 | {
28 | // if there is such file, then let's read its contents, trace it and modify it a bit
29 | var content = File.getContent(fileName);
30 |
31 | t.text = content;
32 |
33 | var lines = content.split("\n");
34 | readNum = Std.parseInt(lines[1]);
35 | trace("readNum: " + readNum);
36 | readNum++;
37 |
38 | content = lines[0] + "\n" + readNum;
39 | File.saveContent(fileName, content);
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/23_heaps_read_write_file/game.hxml:
--------------------------------------------------------------------------------
1 | # Подключение библиотеки heaps
2 | -lib heaps
3 | # Подключение библиотеки hldx (работает только под Windows)
4 | # Альтернативно можно использовать hlsdl
5 | -lib hldx
6 | # Задаем основной класс приложения с точкой входа
7 | -main Game
8 | # Выходной файл
9 | -hl game.hl
--------------------------------------------------------------------------------
/23_heaps_read_write_file/res/haxeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/23_heaps_read_write_file/res/haxeLogo.png
--------------------------------------------------------------------------------
/23_heaps_read_write_file/res/particlesJson.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Beeblerox/Simplest-Heaps-Examples/27064f6320134865ab0887c559e659a90849c27e/23_heaps_read_write_file/res/particlesJson.json
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Simplest-Heaps-Examples
2 | The most simple examples for heaps. See http://haxe.ru/heapsio (it's in russian)
3 |
4 | Feel free to open new issue, if you want me to add some specific sample demonstrating one of the Heaps features
5 |
--------------------------------------------------------------------------------