111 lines
2.6 KiB
Plaintext
111 lines
2.6 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.850*height, width, 0.850*height);
|
|
fill(255);
|
|
}
|
|
|
|
// Background
|
|
void drawBackground() {
|
|
color sky = color(94, 218, 252);
|
|
color sand = color(235, 218, 174);
|
|
color darksand = color(232, 177, 120);
|
|
color sea = color(51, 169, 255);
|
|
color seaend = color(146, 254, 255);
|
|
|
|
// sky
|
|
background(sky);
|
|
// sea
|
|
// for(int y = 400; y < 650; y++){
|
|
// float inter = map(y, 400, 650, 0, 1);
|
|
// color c = lerpColor(sea, seaend, inter);
|
|
// stroke(c);
|
|
// line(0, y, width, y);
|
|
// noStroke();
|
|
// }
|
|
fill(sea);
|
|
quad(0, 400, width, 400, width, 650, 0, 650);
|
|
// Beach
|
|
fill(sand);
|
|
quad(0, 650, width, 650, width, height, 0, height);
|
|
// Player stands on this
|
|
fill(darksand);
|
|
quad(0, 0.850*height, width, 0.850*height, width, height, 0, height);
|
|
fill(0);
|
|
}
|
|
|
|
void drawCloud() {
|
|
ellipse(224, 184, 220, 220);
|
|
}
|
|
|
|
|
|
//// 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;
|
|
}
|