Icarus Demo

Back

The Goal

This describes how to create chunks in the "Icarus" part of the world. This is for version 1.02.00.

Prerequisites

You should read the chapter of the creation manual about "Icarus mode".

Download

Here is the demo we are talking about. Install it in the Data/Packages folder of Fractal Block World and create a new game that uses this package.

Enabling Icarus Mode

When a new game is created, Icarus mode is turned off. You must turn it on manually by calling ga_set_icarus_enabled(true). The saved game will remember that Icarus mode is turned on. Once turned on, it is not recommended to turn it off.

The way this package handles turning Icarus mode on is that there is a basic entity in the root chunk that turns it on/off. Once Icarus mode is on, the engine can create the parent of the root chunk, which opens the door to the Icarus world.

Block Script for the True Root Chunk

Here is the Lua code for the block script for the root chunk (also called the true root, or max root).
--File: block_root.lua

function p.__get_is_solid() return true end
function p.__get_tex() return "block_default" end

function p.__main()
    set_default_block("s")
    create_rect("e", 1,1,1, 14,14,14)

    --Doors out.
    set_pos(7,7,5, "s")
    set_pos(7,7,0, "e")
    set_pos(7,7,15, "e")
    set_pos(7,0,7, "e")
    set_pos(7,15,7, "e")
    set_pos(0,7,7, "e")
    set_pos(15,7,7, "e")

    local level = get_level()
    local txt = "Check: level = " .. tostring(level)
    add_bent_s(2,2,7, "bent_base_txt", txt)

    add_bent(13,13,7, "bent_icarus")

    --Icarus stuff.
    set_gen_root_parent("block_neg_1")
end
The interesting thing here is that the __main function specifies the block type of the parent of the true root, via the function set_gen_root_parent.

Block Script for the Parent of the True Root Chunk

Here is where things get more interesting. Here is the Lua code for the block script for the parent of the true root. We call this chunk the gen root (generalized root) on level -1.
--File: block_neg_1.lua

function p.__get_is_solid() return true end
function p.__get_tex() return "block_default" end

function p.__main()
    set_default_block("e")
    std.create_edges("block_s")

    local level = get_level()
    local txt = "Check: level = " .. tostring(level)
    add_bent_s(2,2,7, "bent_base_txt", txt)

    --Icarus stuff.
    set_gen_root_parent("block_neg_2")
    set_gen_root_child(7,7,7, "block_root")
end
Here the block script specifies the block type of the parent gen root as well as the child gen root (the true root). It also specifies the position of the child gen root.

It is important for the way the engine works that every gen root specifies its parent and child gen root (except the true root which only needs to specify its parent gen root).

Block Script for Gen Root on Level -2

Continuing the pattern, here is the Lua code for the block script for the gen root on level -2 (the parent of the gen root on level -1):
--File: block_neg_2.lua

function p.__get_is_solid() return true end
function p.__get_tex() return "block_default" end

function p.__main()
    set_default_block("e")
    std.create_edges("block_s")

    local level = get_level()
    local txt = "Check: level = " .. tostring(level)
    add_bent_s(2,2,7, "bent_base_txt", txt)

    --Icarus stuff.
    set_gen_root_parent("block_neg_recursive")
    set_gen_root_child(7,7,7, "block_neg_1")
end

Block Script for all the Other Gen Roots

We could continue like this, but there is a special rule: once Icarus mode is enabled, every gen root must have a parent. To handle this rule, what we can do is have a block script that handles the gen roots for all levels less than or equal to -3:
--File: block_neg_recursive.lua

function p.__get_is_solid() return true end
function p.__get_tex() return "block_default" end

function p.__main()
    set_default_block("e")
    std.create_edges("block_s")

    local level = get_level()
    local txt = "Check: level = " .. tostring(level)
    add_bent_s(2,2,7, "bent_base_txt", txt)

    --Icarus stuff.
    set_gen_root_parent("block_neg_recursive") --Recursive.
    --
    local child_bt = ""
    local level = get_level()
    if( level == -3 ) then
        child_bt = "block_neg_2"
    else
        child_bt = "block_neg_recursive"
    end
    set_gen_root_child(7,7,7, child_bt)
end