beautify and prepare for losing

This commit is contained in:
Makussu 2023-10-22 01:39:39 +02:00
parent 0db9e72d8d
commit 175c0d238e
4 changed files with 276 additions and 81 deletions

View File

@ -1,6 +1,9 @@
// } else if (key == 'l') { // } else if (key == 'l') {
// println(loadJSONArray("../map/map.json")); // println(loadJSONArray("../map/map.json"));
boolean iseditorModeRect = true;
boolean iseditorModeSpike = false;
void keyPressed () { void keyPressed () {
if (ismenu) { if (ismenu) {
} else if (isgame) { } else if (isgame) {
@ -19,6 +22,15 @@ void keyPressed () {
if (key == 's') { if (key == 's') {
savetofile("save"); savetofile("save");
println("saved"); println("saved");
} else if (key == ' ') {
if(iseditorModeRect) {
iseditorModeRect = false;
iseditorModeSpike = true;
} else if (iseditorModeSpike) {
iseditorModeRect = true;
iseditorModeSpike = false;
}
println("mode changed");
} else if (key == CODED) { } else if (key == CODED) {
if (keyCode == RIGHT) { if (keyCode == RIGHT) {
screenx = screenx + 50; screenx = screenx + 50;
@ -36,11 +48,23 @@ void keyPressed () {
int runnerRect = 0; int runnerRect = 0;
void mouseReleased() { void mouseReleased() {
if(iseditor) { if(iseditor) {
if(iseditorModeRect) {
if (mouseButton == LEFT) { if (mouseButton == LEFT) {
level[runnerRect][0] = mouseX+screenx; level[runnerRect][0] = mouseX+screenx;
level[runnerRect][1] = mouseY; level[runnerRect][1] = mouseY;
level[runnerRect][2] = 100; level[runnerRect][2] = 100;
level[runnerRect][3] = 50; level[runnerRect][3] = 50;
level[runnerRect][4] = 0;
println("generated");
runnerRect = runnerRect + 1;
println(runnerRect);
}
} else if (iseditorModeSpike) {
level[runnerRect][0] = mouseX+screenx;
level[runnerRect][1] = mouseY;
level[runnerRect][2] = 50;
level[runnerRect][3] = 50;
level[runnerRect][4] = 1;
println("generated"); println("generated");
runnerRect = runnerRect + 1; runnerRect = runnerRect + 1;
println(runnerRect); println(runnerRect);

View File

@ -94,6 +94,19 @@ boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight)
} }
} }
boolean drawTriangleWithMouseColission(int x, int y, int rectwidth, int rectheight) {
// Draw A Rect
rectMode(CENTER);
triangle();
// Check it for collission
if(dist(mouseX, mouseY, x+rectwidth/2, y-rectheight/2) > rectheight/2) {
return true;
} else {
return false;
}
}
void debug() { void debug() {
// println(screenoffset); // println(screenoffset);
// println(level[0][0]); // println(level[0][0]);

View File

@ -1,16 +1,27 @@
// BUG level editor x position bleibt ingame
int screenx = 0; int screenx = 0;
// level generation // level generation
void generate_tiles() { void generate_tiles() {
stroke(0); stroke(0);
for (int i = 0; i < level.length; i++ ) { 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]); rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
} else {
triangle(level[i][0]-level[i][2]/2 -screenx, level[i][1], level[i][0]+level[i][2]/2, level[i][1], level[i][0], level[i][1]-level[i][3]);
} }
} }
}
void generate_spikes() {
}
void generate_editor_tiles() { void generate_editor_tiles() {
for (int i = 0; i < 100; i++ ) { for (int i = 0; i < 100; i++ ) {
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]); 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 (drawRectWithMouseColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) {
if (mousePressed && iseditor) { if (mousePressed && iseditor) {
if (mouseButton == RIGHT) { if (mouseButton == RIGHT) {
@ -18,6 +29,20 @@ void generate_editor_tiles() {
level[i][1] = 0; level[i][1] = 0;
level[i][2] = 0; level[i][2] = 0;
level[i][3] = 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;
}
} }
} }
} }
@ -60,6 +85,12 @@ void drawBackground() {
fill(0); fill(0);
randomSeed(0);
drawPalm(100, 700);
drawPalm(200, 700);
drawPalm(300, 700);
drawPalm(400, 700);
} }
void drawCloud() { void drawCloud() {
@ -67,6 +98,22 @@ void drawCloud() {
} }
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 //// This Handles loading and saving the level
// TODO Check if json is empty. If it is generate level // TODO Check if json is empty. If it is generate level
// int[][] level = new int[100][4]; // int[][] level = new int[100][4];
@ -82,6 +129,7 @@ int savetofile(String filename) {
mapsave.setInt(1, level[i][1]); mapsave.setInt(1, level[i][1]);
mapsave.setInt(2, level[i][2]); mapsave.setInt(2, level[i][2]);
mapsave.setInt(3, level[i][3]); mapsave.setInt(3, level[i][3]);
mapsave.setInt(4, level[i][4]);
json.setJSONArray(i, mapsave); json.setJSONArray(i, mapsave);
} }
@ -89,8 +137,12 @@ int savetofile(String filename) {
return 1; return 1;
} }
boolean checkSaveFile(String filepath) {
return new File(dataPath(filepath)).exists();
}
int[][] loadJson(String jsonfile) { int[][] loadJson(String jsonfile) {
if (checkSaveFile("./saves/save.json")) {
JSONArray values = loadJSONArray(jsonfile); JSONArray values = loadJSONArray(jsonfile);
// println(values.size()); // println(values.size());
@ -104,12 +156,18 @@ int[][] loadJson(String jsonfile) {
int y = jsontoarray.getInt(1); int y = jsontoarray.getInt(1);
int rectwidth = jsontoarray.getInt(2); int rectwidth = jsontoarray.getInt(2);
int rectheight = jsontoarray.getInt(3); int rectheight = jsontoarray.getInt(3);
int isspike = jsontoarray.getInt(4);
// arrayfromjson_x[i] = x; // arrayfromjson_x[i] = x;
arrayfromjson[i][0] = x; arrayfromjson[i][0] = x;
arrayfromjson[i][1] = y; arrayfromjson[i][1] = y;
arrayfromjson[i][2] = rectwidth; arrayfromjson[i][2] = rectwidth;
arrayfromjson[i][3] = rectheight; arrayfromjson[i][3] = rectheight;
arrayfromjson[i][4] = isspike;
} }
return arrayfromjson; return arrayfromjson;
} else {
int[][] arrayfromjson = new int[100][5];
return arrayfromjson;
}
} }

View File

@ -1,599 +1,699 @@
[ [
[ [
405, 417,
595, 598,
100,
50, 50,
50 0
], ],
[ [
823, 312,
337, 660,
100,
50, 50,
50 1
], ],
[ [
1002, 679,
560, 646,
100,
50, 50,
50 1
], ],
[ [
885, 167,
678, 633,
100,
50, 50,
50 1
], ],
[ [
1027, 465,
338, 665,
100,
50, 50,
50 0
], ],
[ [
929, 578,
686, 649,
100,
50, 50,
50 0
], ],
[ [
925, -3,
322, 0,
50, 0,
50 0,
0
], ],
[ [
1024, -3,
717, 0,
50, 0,
50 0,
0
], ],
[ [
927, -3,
344, 0,
50, 0,
50 0,
0
], ],
[ [
1013, -3,
564, 0,
50, 0,
50 0,
0
], ],
[ [
825, -3,
463, 0,
50, 0,
50 0,
0
], ],
[ [
1012, -3,
454, 0,
50, 0,
50 0,
0
], ],
[ [
1622, -3,
495, 0,
50, 0,
50 0,
0
], ],
[ [
1687, -3,
130, 0,
50, 0,
50 0,
0
], ],
[ [
-3,
0, 0,
0, 0,
0, 0,
0 0
], ],
[ [
-3,
0, 0,
0, 0,
0, 0,
0 0
], ],
[ [
-3,
0, 0,
0, 0,
0, 0,
0 0
], ],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