Open AurelienFT opened 5 years ago
After thinking about data structures for the city I think a graph could be a good idea. Here is an explanation of graph in python here : https://www.python-course.eu/graphs_python.php I think we can start with a city like :
graph = { ["a", [0, 0], [0, 2]] : [["c", [0, 2], [2, 2]]],
["b", [1, 2], [3, 2]] : [["c", [0, 2], [2, 2]], ["d", [3, 2], [3, 6]]],
["c", [0, 2], [2, 2]] : [["a", [0, 0], [0, 2]], ["b", [1, 2], [3, 2]], ["d", [3, 2], [3, 6]]],
["d", [3, 2], [3, 6]] : [["c", [0, 2], [2, 2]]],
}
The data format is :
{
[node_name, [x_start, y_start], [x_end, y_end]]: [[node_name, [x_start, y_start], [x_end, y_end]], [node_name, [x_start, y_start], [x_end, y_end]]],
...
}
What do you think about it @Idruk ?
node = [
name: "NodeName", type: "node_type",
XY_start: [x_start, y_start],
XY_end: [x_end, y_end],
walkable: bool, driveable: bool, bikeable: bool,
ImportantPlaces: [
place1, ..., placeX
]
]
I tough about a node like this, maybe there some more informations, you'd like to add in it ? @AurelienFT
EDIT :
node = [
name: "NodeName", type: "node_type",
XY_start: [x_start, y_start],
XY_end: [x_end, y_end],
walkable: bool, driveable: bool, bikeable: bool,
]
Looks better
@Idruk I want to write informations about the nodes only one time so the file will look like that :
var ways = {
"nodes": [
{
"name": "a",
"type": "road",
"start": {
x: 0,
y: 0
},
"end": {
x: 0,
y: 10
},
"walkable": true,
"driveable": true,
"bikeable": true
},
{
"name": "b",
"type": "road",
"start": {
x: 0,
y: 5
},
"end": {
x: 5,
y: 5
},
"walkable": true,
"driveable": true,
"bikeable": true
},
{
"name": "c",
"type": "road",
"start": {
x: 0,
y: 8
},
"end": {
x: 5,
y: 8
},
"walkable": true,
"driveable": true,
"bikeable": true
},
{
"name": "d",
"type": "road",
"start": {
x: 5,
y: 0
},
"end": {
x: 5,
y: 8
},
"walkable": true,
"driveable": true,
"bikeable": true
}
],
"roads": [
{
"road": "a",
"neighbors": [
{"name": "b", "x": 0, "y": 5},
{"name": "c", "x": 0, "y": 8}
]
},
{
"road": "b",
"neighbors": [
{"name": "a", "x": 0, "y": 5},
{"name": "d", "x": 5, "y": 5}
]
},
{
"road": "c",
"neighbors": [
{"name": "a", "x": 0, "y": 8},
{"name": "d", "x": 5, "y": 8}
]
},
{
"road": "d",
"neighbors": [
{"name": "b", "x": 5, "y": 5},
{"name": "c", "x": 5, "y": 8}
]
}
]
}
Some ressources to learn how to generate a city : https://gamedev.stackexchange.com/questions/162344/town-generation-algorithms https://cgl.ethz.ch/Downloads/Publications/Papers/2001/p_Par01.pdf https://jsfiddle.net/7srfrx55/