79 lines
2.0 KiB
Plaintext
79 lines
2.0 KiB
Plaintext
int screenx = 0;
|
|
|
|
// level generation
|
|
void generate_tiles() {
|
|
for (int i = 0; i < level.length; i++ ) {
|
|
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
|
}
|
|
}
|
|
|
|
void generate_editor_tiles() {
|
|
for (int i = 0; i < 100; i++ ) {
|
|
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
|
if (drawRectWithMouseColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) {
|
|
if (mousePressed && iseditor) {
|
|
if (mouseButton == RIGHT) {
|
|
level[i][0] = 0;
|
|
level[i][1] = 0;
|
|
level[i][2] = 0;
|
|
level[i][3] = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void baseRect() {
|
|
line(0, 0.875*height, width, 0.875*height);
|
|
fill(100);
|
|
quad(0, 0.875*height, width, 0.875*height, width, height, 0, height);
|
|
fill(255);
|
|
}
|
|
|
|
//// This Handles loading and saving the level
|
|
// TODO Check if json is empty. If it is generate level
|
|
// int[][] level = new int[100][4];
|
|
JSONArray json;
|
|
|
|
int savetofile(String filename) {
|
|
json = new JSONArray();
|
|
|
|
for (int i = 0; i < level.length; i++) {
|
|
|
|
JSONArray mapsave = new JSONArray();
|
|
mapsave.setInt(0, level[i][0]);
|
|
mapsave.setInt(1, level[i][1]);
|
|
mapsave.setInt(2, level[i][2]);
|
|
mapsave.setInt(3, level[i][3]);
|
|
|
|
json.setJSONArray(i, mapsave);
|
|
}
|
|
saveJSONArray(json,"./saves/" + filename + ".json");
|
|
return 1;
|
|
}
|
|
|
|
|
|
int[][] loadJson(String jsonfile) {
|
|
JSONArray values = loadJSONArray(jsonfile);
|
|
// println(values.size());
|
|
|
|
int[][] arrayfromjson = new int[values.size()][values.size()];
|
|
|
|
for (int i = 0; i < values.size(); i++) {
|
|
|
|
JSONArray jsontoarray = values.getJSONArray(i);
|
|
|
|
int x = jsontoarray.getInt(0);
|
|
int y = jsontoarray.getInt(1);
|
|
int rectwidth = jsontoarray.getInt(2);
|
|
int rectheight = jsontoarray.getInt(3);
|
|
|
|
// arrayfromjson_x[i] = x;
|
|
arrayfromjson[i][0] = x;
|
|
arrayfromjson[i][1] = y;
|
|
arrayfromjson[i][2] = rectwidth;
|
|
arrayfromjson[i][3] = rectheight;
|
|
}
|
|
return arrayfromjson;
|
|
}
|