Maximilian Ruhm eafd6f3d92 finish
2023-10-23 19:11:26 +02:00

183 lines
5.1 KiB
Plaintext

// BUG level editor x position bleibt ingame
// TODO Completly rework colission
// TODO Die when touching triangle
// moveTilesBack() and High Score Tracking
// No Unlimited Jumping
int screenx = 0;
// level generation for playable
void generate_tiles() {
stroke(0);
for (int i = 0; i < level.length; i++ ) {
if (level[i][4] == 0) {
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
} else {
if (drawTriangleWithPlayerColission(level[i][0] -screenx, level[i][1], level[i][2], level[i][3])) {
moveTilesBack(tilespeed);
deathsound.play();
}
}
}
}
// Generate the tiles for Editor View (tiles that are deletable with mouse)
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(level[i][4] == 0) {
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;
level[i][4] = 0;
}
}
}
} else {
if (drawTriangleWithMouseColission(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;
level[i][4] = 0;
}
}
}
}
}
}
void baseRect() {
line(0, 0.850*height, width, 0.850*height);
fill(255);
}
// Draws all the Background elements like sea and Beach
void drawBackground() {
color sky = color(94, 218, 252);
color sand = color(235, 218, 174);
color darksand = color(232, 177, 120);
color darkersand = color(166, 110, 51);
color sea = color(51, 169, 255);
color seaend = color(146, 254, 255);
color sun = color(247, 178, 2);
// 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();
}
// 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);
//sun
fill(sun);
ellipse(130, 100, 70, 70);
randomSeed(0);
drawPalm(100, 700);
drawPalm(200, 700);
drawPalm(300, 700);
drawPalm(400, 700);
fill(0, 200);
stroke(darkersand);
for (int i = 0; i < 500; i++) {
point(random(0, width), random(700, 800));
}
stroke(0);
fill(0);
}
// No Clouds yet
void drawCloud() {
ellipse(224, 184, 220, 220);
}
// Draws a slightly randomised Palm
void drawPalm(int startingpoint_x, int startingpoint_y) {
fill(108, 88, 51);
float randomnumber = int(random(10, 16));
float schwanken = int(random(-2, 2));
int offset = 8;
PVector endpoint = new PVector(startingpoint_x, startingpoint_y - randomnumber * offset);
for (int i = 0; i <= randomnumber; i++) {
triangle(endpoint.x+i*schwanken, endpoint.y+i*offset, endpoint.x+10+i*schwanken, endpoint.y+10+i*offset, endpoint.x+20+i*schwanken, endpoint.y+i*offset);
}
fill(93, 133, 47);
quad(endpoint.x+10, endpoint.y, endpoint.x - 12, endpoint.y - 8, endpoint.x - 50, endpoint.y + 20, endpoint.x - 5, endpoint.y + 12);
quad(endpoint.x+10, endpoint.y, endpoint.x + 22, endpoint.y - 8, endpoint.x + 60, endpoint.y + 20, endpoint.x + 15, endpoint.y + 12);
}
//// This Handles loading and saving the level
JSONArray json;
// This saves the Current save to file
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]);
mapsave.setInt(4, level[i][4]);
json.setJSONArray(i, mapsave);
}
saveJSONArray(json,"./saves/" + filename + ".json");
return 1;
}
boolean checkSaveFile(String filepath) {
return new File(dataPath(filepath)).exists();
}
// Check if there already is a safefile and load it if it is possible. If not load empty array
int[][] loadJson(String jsonfile) {
if (!checkSaveFile("./saves/save.json")) {
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);
int isspike = jsontoarray.getInt(4);
arrayfromjson[i][0] = x;
arrayfromjson[i][1] = y;
arrayfromjson[i][2] = rectwidth;
arrayfromjson[i][3] = rectheight;
arrayfromjson[i][4] = isspike;
}
return arrayfromjson;
} else {
int[][] arrayfromjson = new int[100][5];
return arrayfromjson;
}
}