Skip to content

JSON examples

DiogoVF edited this page Sep 8, 2020 · 3 revisions

When the user create a new level with level editor application, a JSON is saved on maps dir. The file is loaded on the game application. Each elements have id and type. the type is the class of the object and the id is not required, because it's defined by the user for specific objectives.

objectives: - have_item : user has to have items - on_item : user has to go on specific item - location : user has to go a specific position

// level Structure
{
    "level": {
        "name": "stage learning",
        "objectives": [
            {
                "id": "logs",
                "type": "have_item",
                "name": "take 5 logs",
                "required": true,
                "data":{
                    "item_type" : "log",
                    "item_count" : 5
                }
            },
            {
                "id": "moving",
                "type": "location",
                "name": "go front of the house",
                "required": true,
                "data":{
                    "location": {
                        "x": 200,
                        "y": 300
                    }
                }
            },
            {
                "id": "lumberjack",
                "type": "interact",
                "name": "chop 3 trees",
                "required": false,
                "data":{
                    "with_item_type": "axe",
                    "on_object_type": "tree",
                    "item_count": 3                  
                }
            },
            {
                "id": "idiot",
                "type": "interact",
                "name": "chop the first tree with an illogical item",
                "required": false,
                "data":{
                    "with_item_type": "apple",
                    "on_object_type": "tree",                  
                }
            }
        ],
        "maps": [{
            "name": "Example_plain",
            "player_spawn": {
                "position": {
                    "x": 200,
                    "y": 200
                },
                "inventory": [
                    {
                        "object": {
                            "id": "apple01",
                            "type": "apple",
                            "name": "apple",
                            "data": {
                                "texture": "apple_core"
                            }
                        },
                        "holding": true
                    }
                ]
            },
            "elements": [
                {
                    "id": "tree01",
                    "type": "tree",
                    "name": "Sapin",
                    "position": {
                        "x": 85,
                        "y": 60
                    },
                    "data": {
                        "texture": "basic_tree",
                        "num_logs": 5
                    }
                }
            ]
        }]
    }
}

Clone this wiki locally