diff --git a/_data/examplesindex.json b/_data/examplesindex.json index d5b9214a0..e0b0f45d3 100644 --- a/_data/examplesindex.json +++ b/_data/examplesindex.json @@ -1,99 +1,123 @@ [ { - "category": "RESOURCE", - "collection": "resource/modify_atlas", - "name": "Modify atlas", - "path": "resource/modify_atlas" + "category": "DEBUG", + "collection": "debug/physics", + "name": "Physics", + "path": "debug/physics" }, { - "category": "SOUND", - "collection": "sound/panning", - "name": "Panning", - "path": "sound/panning" + "category": "DEBUG", + "collection": "debug/profile", + "name": "Profile", + "path": "debug/profile" }, { - "category": "SOUND", - "collection": "sound/music", - "name": "Music", - "path": "sound/music" + "category": "BASICS", + "collection": "basics/parent_child", + "name": "Parent child", + "path": "basics/parent_child" }, { - "category": "SOUND", - "collection": "sound/fade_in_out", - "name": "Fade in out", - "path": "sound/fade_in_out" + "category": "BASICS", + "collection": "basics/z_order", + "name": "Z order", + "path": "basics/z_order" }, { - "category": "COLLECTION", - "collection": "collection/proxy", - "name": "Proxy", - "path": "collection/proxy" + "category": "BASICS", + "collection": "basics/message_passing", + "name": "Message passing", + "path": "basics/message_passing" }, { - "category": "COLLECTION", - "collection": "collection/timestep", - "name": "Timestep", - "path": "collection/timestep" + "category": "TILEMAP", + "collection": "tilemap/collisions", + "name": "Collisions", + "path": "tilemap/collisions" }, { - "category": "COLLECTION", - "collection": "collection/splash", - "name": "Splash", - "path": "collection/splash" + "category": "TILEMAP", + "collection": "tilemap/get_set_tile", + "name": "Get set tile", + "path": "tilemap/get_set_tile" }, { - "category": "INPUT", - "collection": "input/move", - "name": "Move", - "path": "input/move" + "category": "MOVEMENT", + "collection": "movement/movement_speed", + "name": "Movement speed", + "path": "movement/movement_speed" }, { - "category": "INPUT", - "collection": "input/text", - "name": "Text", - "path": "input/text" + "category": "MOVEMENT", + "collection": "movement/follow", + "name": "Follow", + "path": "movement/follow" }, { - "category": "INPUT", - "collection": "input/mouse_and_touch", - "name": "Mouse and touch", - "path": "input/mouse_and_touch" + "category": "MOVEMENT", + "collection": "movement/move_to", + "name": "Move to", + "path": "movement/move_to" }, { - "category": "INPUT", - "collection": "input/down_duration", - "name": "Down duration", - "path": "input/down_duration" + "category": "MOVEMENT", + "collection": "movement/look_at", + "name": "Look at", + "path": "movement/look_at" }, { - "category": "BASICS", - "collection": "basics/parent_child", - "name": "Parent child", - "path": "basics/parent_child" + "category": "MOVEMENT", + "collection": "movement/move_forward", + "name": "Move forward", + "path": "movement/move_forward" }, { - "category": "BASICS", - "collection": "basics/z_order", - "name": "Z order", - "path": "basics/z_order" + "category": "MOVEMENT", + "collection": "movement/simple_move", + "name": "Simple move", + "path": "movement/simple_move" }, { - "category": "BASICS", - "collection": "basics/message_passing", - "name": "Message passing", - "path": "basics/message_passing" + "category": "SPRITE", + "collection": "sprite/tint", + "name": "Tint", + "path": "sprite/tint" }, { - "category": "GUI", - "collection": "gui/load_texture", - "name": "Load texture", - "path": "gui/load_texture" + "category": "SPRITE", + "collection": "sprite/size", + "name": "Size", + "path": "sprite/size" }, { - "category": "GUI", - "collection": "gui/layouts", - "name": "Layouts", - "path": "gui/layouts" + "category": "SPRITE", + "collection": "sprite/flip", + "name": "Flip", + "path": "sprite/flip" + }, + { + "category": "SPRITE", + "collection": "sprite/bunnymark", + "name": "Bunnymark", + "path": "sprite/bunnymark" + }, + { + "category": "COLLECTION", + "collection": "collection/splash", + "name": "Splash", + "path": "collection/splash" + }, + { + "category": "COLLECTION", + "collection": "collection/proxy", + "name": "Proxy", + "path": "collection/proxy" + }, + { + "category": "COLLECTION", + "collection": "collection/timestep", + "name": "Timestep", + "path": "collection/timestep" }, { "category": "GUI", @@ -103,9 +127,15 @@ }, { "category": "GUI", - "collection": "gui/button", - "name": "Button", - "path": "gui/button" + "collection": "gui/pointer_over", + "name": "Pointer over", + "path": "gui/pointer_over" + }, + { + "category": "GUI", + "collection": "gui/color", + "name": "Color", + "path": "gui/color" }, { "category": "GUI", @@ -115,9 +145,9 @@ }, { "category": "GUI", - "collection": "gui/pointer_over", - "name": "Pointer over", - "path": "gui/pointer_over" + "collection": "gui/healthbar", + "name": "Healthbar", + "path": "gui/healthbar" }, { "category": "GUI", @@ -125,6 +155,12 @@ "name": "Drag", "path": "gui/drag" }, + { + "category": "GUI", + "collection": "gui/load_texture", + "name": "Load texture", + "path": "gui/load_texture" + }, { "category": "GUI", "collection": "gui/get_set_material", @@ -133,21 +169,21 @@ }, { "category": "GUI", - "collection": "gui/get_set_font", - "name": "Get set font", - "path": "gui/get_set_font" + "collection": "gui/layouts", + "name": "Layouts", + "path": "gui/layouts" }, { "category": "GUI", - "collection": "gui/get_set_texture", - "name": "Get set texture", - "path": "gui/get_set_texture" + "collection": "gui/button", + "name": "Button", + "path": "gui/button" }, { "category": "GUI", - "collection": "gui/color", - "name": "Color", - "path": "gui/color" + "collection": "gui/get_set_font", + "name": "Get set font", + "path": "gui/get_set_font" }, { "category": "GUI", @@ -156,52 +192,34 @@ "path": "gui/progress" }, { - "category": "TIMER", - "collection": "timer/repeating_timer", - "name": "Repeating timer", - "path": "timer/repeating_timer" - }, - { - "category": "TIMER", - "collection": "timer/cancel_timer", - "name": "Cancel timer", - "path": "timer/cancel_timer" - }, - { - "category": "TIMER", - "collection": "timer/trigger_timer", - "name": "Trigger timer", - "path": "timer/trigger_timer" - }, - { - "category": "FILE", - "collection": "file/sys_save_load", - "name": "Sys save load", - "path": "file/sys_save_load" + "category": "GUI", + "collection": "gui/get_set_texture", + "name": "Get set texture", + "path": "gui/get_set_texture" }, { "category": "ANIMATION", - "collection": "animation/easing", - "name": "Easing", - "path": "animation/easing" + "collection": "animation/basic_tween", + "name": "Basic tween", + "path": "animation/basic_tween" }, { "category": "ANIMATION", - "collection": "animation/cursor", - "name": "Cursor", - "path": "animation/cursor" + "collection": "animation/euler_rotation", + "name": "Euler rotation", + "path": "animation/euler_rotation" }, { "category": "ANIMATION", - "collection": "animation/spine", - "name": "Spine", - "path": "animation/spine" + "collection": "animation/flipbook", + "name": "Flipbook", + "path": "animation/flipbook" }, { "category": "ANIMATION", - "collection": "animation/euler_rotation", - "name": "Euler rotation", - "path": "animation/euler_rotation" + "collection": "animation/easing", + "name": "Easing", + "path": "animation/easing" }, { "category": "ANIMATION", @@ -211,9 +229,9 @@ }, { "category": "ANIMATION", - "collection": "animation/flipbook", - "name": "Flipbook", - "path": "animation/flipbook" + "collection": "animation/spine", + "name": "Spine", + "path": "animation/spine" }, { "category": "ANIMATION", @@ -223,27 +241,33 @@ }, { "category": "ANIMATION", - "collection": "animation/basic_tween", - "name": "Basic tween", - "path": "animation/basic_tween" + "collection": "animation/cursor", + "name": "Cursor", + "path": "animation/cursor" }, { - "category": "PHYSICS", - "collection": "physics/pendulum", - "name": "Pendulum", - "path": "physics/pendulum" + "category": "SOUND", + "collection": "sound/panning", + "name": "Panning", + "path": "sound/panning" }, { - "category": "PHYSICS", - "collection": "physics/raycast", - "name": "Raycast", - "path": "physics/raycast" + "category": "SOUND", + "collection": "sound/fade_in_out", + "name": "Fade in out", + "path": "sound/fade_in_out" }, { - "category": "PHYSICS", - "collection": "physics/kinematic", - "name": "Kinematic", - "path": "physics/kinematic" + "category": "SOUND", + "collection": "sound/music", + "name": "Music", + "path": "sound/music" + }, + { + "category": "RESOURCE", + "collection": "resource/modify_atlas", + "name": "Modify atlas", + "path": "resource/modify_atlas" }, { "category": "PHYSICS", @@ -251,12 +275,6 @@ "name": "Knockback", "path": "physics/knockback" }, - { - "category": "PHYSICS", - "collection": "physics/trigger", - "name": "Trigger", - "path": "physics/trigger" - }, { "category": "PHYSICS", "collection": "physics/dynamic", @@ -270,100 +288,76 @@ "path": "physics/hinge_joint" }, { - "category": "MOVEMENT", - "collection": "movement/move_to", - "name": "Move to", - "path": "movement/move_to" - }, - { - "category": "MOVEMENT", - "collection": "movement/move_forward", - "name": "Move forward", - "path": "movement/move_forward" - }, - { - "category": "MOVEMENT", - "collection": "movement/movement_speed", - "name": "Movement speed", - "path": "movement/movement_speed" - }, - { - "category": "MOVEMENT", - "collection": "movement/simple_move", - "name": "Simple move", - "path": "movement/simple_move" - }, - { - "category": "MOVEMENT", - "collection": "movement/look_at", - "name": "Look at", - "path": "movement/look_at" + "category": "PHYSICS", + "collection": "physics/pendulum", + "name": "Pendulum", + "path": "physics/pendulum" }, { - "category": "MOVEMENT", - "collection": "movement/follow", - "name": "Follow", - "path": "movement/follow" + "category": "PHYSICS", + "collection": "physics/raycast", + "name": "Raycast", + "path": "physics/raycast" }, { - "category": "RENDER", - "collection": "render/screen_to_world", - "name": "Screen to world", - "path": "render/screen_to_world" + "category": "PHYSICS", + "collection": "physics/kinematic", + "name": "Kinematic", + "path": "physics/kinematic" }, { - "category": "RENDER", - "collection": "render/camera", - "name": "Camera", - "path": "render/camera" + "category": "PHYSICS", + "collection": "physics/trigger", + "name": "Trigger", + "path": "physics/trigger" }, { - "category": "TILEMAP", - "collection": "tilemap/get_set_tile", - "name": "Get set tile", - "path": "tilemap/get_set_tile" + "category": "FILE", + "collection": "file/sys_save_load", + "name": "Sys save load", + "path": "file/sys_save_load" }, { - "category": "TILEMAP", - "collection": "tilemap/collisions", - "name": "Collisions", - "path": "tilemap/collisions" + "category": "MATERIAL", + "collection": "material/noise", + "name": "Noise", + "path": "material/noise" }, { - "category": "DEBUG", - "collection": "debug/profile", - "name": "Profile", - "path": "debug/profile" + "category": "MATERIAL", + "collection": "material/unlit", + "name": "Unlit", + "path": "material/unlit" }, { - "category": "DEBUG", - "collection": "debug/physics", - "name": "Physics", - "path": "debug/physics" + "category": "MATERIAL", + "collection": "material/uvgradient", + "name": "Uvgradient", + "path": "material/uvgradient" }, { - "category": "SPRITE", - "collection": "sprite/flip", - "name": "Flip", - "path": "sprite/flip" + "category": "MATERIAL", + "collection": "material/vertexcolor", + "name": "Vertexcolor", + "path": "material/vertexcolor" }, { - "category": "SPRITE", - "collection": "sprite/bunnymark", - "name": "Bunnymark", - "path": "sprite/bunnymark" + "category": "TIMER", + "collection": "timer/trigger_timer", + "name": "Trigger timer", + "path": "timer/trigger_timer" }, { - "category": "SPRITE", - "collection": "sprite/tint", - "name": "Tint", - "path": "sprite/tint" + "category": "TIMER", + "collection": "timer/cancel_timer", + "name": "Cancel timer", + "path": "timer/cancel_timer" }, { - "category": "SPRITE", - "collection": "sprite/size", - "name": "Size", - "path": "sprite/size" + "category": "TIMER", + "collection": "timer/repeating_timer", + "name": "Repeating timer", + "path": "timer/repeating_timer" }, { "category": "PARTICLES", @@ -390,45 +384,57 @@ "path": "particles/particlefx" }, { - "category": "FACTORY", - "collection": "factory/dynamic", - "name": "Dynamic", - "path": "factory/dynamic" + "category": "RENDER", + "collection": "render/screen_to_world", + "name": "Screen to world", + "path": "render/screen_to_world" }, { - "category": "FACTORY", - "collection": "factory/bullets", - "name": "Bullets", - "path": "factory/bullets" + "category": "RENDER", + "collection": "render/camera", + "name": "Camera", + "path": "render/camera" }, { - "category": "FACTORY", - "collection": "factory/basic", - "name": "Basic", - "path": "factory/basic" + "category": "INPUT", + "collection": "input/move", + "name": "Move", + "path": "input/move" }, { - "category": "MATERIAL", - "collection": "material/uvgradient", - "name": "Uvgradient", - "path": "material/uvgradient" + "category": "INPUT", + "collection": "input/down_duration", + "name": "Down duration", + "path": "input/down_duration" }, { - "category": "MATERIAL", - "collection": "material/noise", - "name": "Noise", - "path": "material/noise" + "category": "INPUT", + "collection": "input/text", + "name": "Text", + "path": "input/text" }, { - "category": "MATERIAL", - "collection": "material/vertexcolor", - "name": "Vertexcolor", - "path": "material/vertexcolor" + "category": "INPUT", + "collection": "input/mouse_and_touch", + "name": "Mouse and touch", + "path": "input/mouse_and_touch" }, { - "category": "MATERIAL", - "collection": "material/unlit", - "name": "Unlit", - "path": "material/unlit" + "category": "FACTORY", + "collection": "factory/basic", + "name": "Basic", + "path": "factory/basic" + }, + { + "category": "FACTORY", + "collection": "factory/bullets", + "name": "Bullets", + "path": "factory/bullets" + }, + { + "category": "FACTORY", + "collection": "factory/dynamic", + "name": "Dynamic", + "path": "factory/dynamic" } ] \ No newline at end of file diff --git a/_includes/examples/gui/healthbar/healthbar_gui_script.md b/_includes/examples/gui/healthbar/healthbar_gui_script.md new file mode 100644 index 000000000..cc3ad79fd --- /dev/null +++ b/_includes/examples/gui/healthbar/healthbar_gui_script.md @@ -0,0 +1,36 @@ +-- < 1 > +local min_size = 48 +local max_size = 235 - min_size + +-- < 2 > +local function set_healthbar(healthbar_node_name, health_percentage) + local healthbar_node = gui.get_node(healthbar_node_name) -- < 3 > + local healthbar_size = gui.get_size(healthbar_node) -- < 4 > + healthbar_size.x = health_percentage * max_size + min_size -- < 5 > + gui.set_size(healthbar_node, healthbar_size) -- < 6 > +end + +function init(self) + -- < 7 > + set_healthbar("left_health", 1.0) + set_healthbar("right_health", 1.0) + set_healthbar("center_health", 1.0) +end + +function on_message(self, message_id, message, sender) + -- < 8 > + if message_id == hash("update_health") then + set_healthbar(message.health_name, message.health_percentage) + end +end + +--[[ +1. Define minimum and maximum size of GUI healthbar (only width is changed). +2. Define a local helper function to update healthbar. +3. Get node of given name passed as "healthbar_node_name" and store it in local variable "healthbar_node". +4. Get size of this node and store it in local variable "healthbar_size". +5. Change size along X axis (width) of the node to given "health_percentage" scaled times "max_size" and added to "min_size", so that it can be no smaller than it. +6. Set the newly updated size of the node. +7. In init function, for each of three defined nodes set initial health_percentage to 1.0 (100%). +8. In on_message function, if the GUI component receives message "update_health" call helper function to update given health bar. +]] \ No newline at end of file diff --git a/_includes/examples/gui/healthbar/healthbar_script.md b/_includes/examples/gui/healthbar/healthbar_script.md new file mode 100644 index 000000000..cc9c540b8 --- /dev/null +++ b/_includes/examples/gui/healthbar/healthbar_script.md @@ -0,0 +1,25 @@ +function init(self) + -- < 1 > + self.player_one_health = 1.0 + self.player_two_health = 1.0 + self.game_boss_health = 1.0 + + -- < 2 > + timer.delay(1, true, function() + -- < 3 > + self.player_one_health = math.max(self.player_one_health - 0.1, 0) + self.player_two_health = math.max(self.player_two_health - 0.1, 0) + self.game_boss_health = math.max(self.game_boss_health - 0.1, 0) + -- < 4 > + msg.post("hud", "update_health", { health_name = "left_health", health_percentage = self.player_one_health }) + msg.post("hud", "update_health", { health_name = "right_health", health_percentage = self.player_two_health }) + msg.post("hud", "update_health", { health_name = "center_health", health_percentage = self.game_boss_health }) + end) +end + +--[[ +1. Set initial health percentage (1.0 = 100%, 0.0 = 0%). +2. Start a timer that will call every 1 second (first argument) repeateadly (second argument being true) a callback function (3rd argument) +3. Reduce each health percentage by 0.1 (10%), but no less than 0 (using math.max to select `0`, if `self.player_one_health - 0.1` is less than `0`). +4. Send messages to hud (gui component) to "updated_health" with health name and percentage to be set in GUI script. +]] \ No newline at end of file diff --git a/examples/archive/archive_files.json b/examples/archive/archive_files.json index c204a750e..d14a73e14 100644 --- a/examples/archive/archive_files.json +++ b/examples/archive/archive_files.json @@ -1 +1 @@ -{"content":[{"name":"game.projectc","size":3945,"pieces":[{"name":"game0.projectc","offset":0}]},{"name":"game.arci","size":47808,"pieces":[{"name":"game0.arci","offset":0}]},{"name":"game.arcd","size":4143914,"pieces":[{"name":"game0.arcd","offset":0},{"name":"game1.arcd","offset":2097152}]},{"name":"game.dmanifest","size":52152,"pieces":[{"name":"game0.dmanifest","offset":0}]},{"name":"game.public.der","size":162,"pieces":[{"name":"game0.public.der","offset":0}]}],"total_size":4247981} \ No newline at end of file +{"content":[{"name":"game.projectc","size":3945,"pieces":[{"name":"game0.projectc","offset":0}]},{"name":"game.arci","size":48368,"pieces":[{"name":"game0.arci","offset":0}]},{"name":"game.arcd","size":4149590,"pieces":[{"name":"game0.arcd","offset":0},{"name":"game1.arcd","offset":2097152}]},{"name":"game.dmanifest","size":52751,"pieces":[{"name":"game0.dmanifest","offset":0}]},{"name":"game.public.der","size":162,"pieces":[{"name":"game0.public.der","offset":0}]}],"total_size":4254816} \ No newline at end of file diff --git a/examples/archive/game0.arcd b/examples/archive/game0.arcd index 9b60592d4..f6fb8d9aa 100644 Binary files a/examples/archive/game0.arcd and b/examples/archive/game0.arcd differ diff --git a/examples/archive/game0.arci b/examples/archive/game0.arci index 12a548d5c..a48f071ef 100644 Binary files a/examples/archive/game0.arci and b/examples/archive/game0.arci differ diff --git a/examples/archive/game0.dmanifest b/examples/archive/game0.dmanifest index 8404406f7..a5f475229 100644 Binary files a/examples/archive/game0.dmanifest and b/examples/archive/game0.dmanifest differ diff --git a/examples/archive/game0.public.der b/examples/archive/game0.public.der index 94c994472..c2abfba08 100644 Binary files a/examples/archive/game0.public.der and b/examples/archive/game0.public.der differ diff --git a/examples/archive/game1.arcd b/examples/archive/game1.arcd index 24c6a2871..8cb5061fb 100644 Binary files a/examples/archive/game1.arcd and b/examples/archive/game1.arcd differ diff --git a/examples/gui/healthbar/healthbar.md b/examples/gui/healthbar/healthbar.md new file mode 100644 index 000000000..d083f8515 --- /dev/null +++ b/examples/gui/healthbar/healthbar.md @@ -0,0 +1,28 @@ +--- +layout: example +permalink: examples/gui/healthbar/ +collection: gui/healthbar +title: Health Bar +brief: This example demonstrates how to add different health bars. +scripts: healthbar.script, healthbar.gui_script +--- + +Overview : Example shows 3 pairs of nodes each forming a "health bar" with different pivots. + +Create a pair of Box nodes, so that child node is smaller than the parent: +![healthbar](healthbar.png) +![healthbar_inner](healthbar_inner.png) + +Example contains 3 such pairs - each with different `Pivot` and `X Anchor` settings for inner health bars: + +- `West` + `Left` +- `East` + `Right` +- `Center` + `None` + +Health is indicated as the size on X Axis of the inner node, so define what can be maximum and minimum width here. + +Create a collection with such GUI component and add it and your game object with script to collection: + +![healthbar_collection](healthbar_collection.png) + +Example shows communication between `controller#main` script component (`healthbar.script`) and `hud#main` gui component with gui_script (`healthbar.gui_script`). \ No newline at end of file diff --git a/examples/gui/healthbar/healthbar.png b/examples/gui/healthbar/healthbar.png new file mode 100644 index 000000000..a9ed40f8c Binary files /dev/null and b/examples/gui/healthbar/healthbar.png differ diff --git a/examples/gui/healthbar/healthbar_collection.png b/examples/gui/healthbar/healthbar_collection.png new file mode 100644 index 000000000..33ad720c6 Binary files /dev/null and b/examples/gui/healthbar/healthbar_collection.png differ diff --git a/examples/gui/healthbar/healthbar_inner.png b/examples/gui/healthbar/healthbar_inner.png new file mode 100644 index 000000000..1bcc8b2be Binary files /dev/null and b/examples/gui/healthbar/healthbar_inner.png differ