rebuild and map editor

This commit is contained in:
Maximilian Ruhm
2023-10-18 12:20:18 +02:00
parent c3f0390160
commit cd98f3bc12
3 changed files with 79 additions and 6 deletions

18
map/map.json Normal file
View File

@@ -0,0 +1,18 @@
[
[
50,
50
],
[
417,
414
],
[
602,
165
],
[
308,
296
]
]

54
map/map.pde Normal file
View File

@@ -0,0 +1,54 @@
JSONArray json;
void setup() {
size(800,800);
// json = loadJSONArray("map.json");
// JSONObject values = json.getJSONObject(1);
// int x = values.getInt("x");
// print(x);
}
void draw() {
background(255);
generate_tiles();
}
PVector tilesize = new PVector(50, 50);
int[] tiles_x = {50};
int[] tiles_y = {50};
void pickTiles() {
}
void generate_tiles() {
for (int i = 0; i < tiles_x.length; i++ ) {
rect(tiles_x[i], tiles_y[i], tilesize.x, tilesize.y);
}
}
void mouseReleased() {
tiles_x = (int[])append(tiles_x, mouseX);
tiles_y = (int[])append(tiles_y, mouseY);
println(tiles_x);
}
void keyPressed() {
if (key == 's') {
println("saved");
json = new JSONArray();
for (int i = 0; i < tiles_x.length; i++) {
JSONArray mapsave = new JSONArray();
mapsave.setInt(0, tiles_x[i]);
mapsave.setInt(1, tiles_y[i]);
json.setJSONArray(i, mapsave);
}
saveJSONArray(json, "map.json");
}
}