beautify and prepare for losing
This commit is contained in:
parent
0db9e72d8d
commit
175c0d238e
@ -1,6 +1,9 @@
|
||||
// } else if (key == 'l') {
|
||||
// println(loadJSONArray("../map/map.json"));
|
||||
|
||||
boolean iseditorModeRect = true;
|
||||
boolean iseditorModeSpike = false;
|
||||
|
||||
void keyPressed () {
|
||||
if (ismenu) {
|
||||
} else if (isgame) {
|
||||
@ -19,6 +22,15 @@ void keyPressed () {
|
||||
if (key == 's') {
|
||||
savetofile("save");
|
||||
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) {
|
||||
if (keyCode == RIGHT) {
|
||||
screenx = screenx + 50;
|
||||
@ -36,14 +48,26 @@ void keyPressed () {
|
||||
int runnerRect = 0;
|
||||
void mouseReleased() {
|
||||
if(iseditor) {
|
||||
if (mouseButton == LEFT) {
|
||||
level[runnerRect][0] = mouseX+screenx;
|
||||
level[runnerRect][1] = mouseY;
|
||||
level[runnerRect][2] = 100;
|
||||
level[runnerRect][3] = 50;
|
||||
println("generated");
|
||||
runnerRect = runnerRect + 1;
|
||||
println(runnerRect);
|
||||
if(iseditorModeRect) {
|
||||
if (mouseButton == LEFT) {
|
||||
level[runnerRect][0] = mouseX+screenx;
|
||||
level[runnerRect][1] = mouseY;
|
||||
level[runnerRect][2] = 100;
|
||||
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");
|
||||
runnerRect = runnerRect + 1;
|
||||
println(runnerRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
// println(screenoffset);
|
||||
// println(level[0][0]);
|
||||
|
||||
104
game/map.pde
104
game/map.pde
@ -1,23 +1,48 @@
|
||||
// BUG level editor x position bleibt ingame
|
||||
|
||||
int screenx = 0;
|
||||
|
||||
// level generation
|
||||
void generate_tiles() {
|
||||
stroke(0);
|
||||
for (int i = 0; i < level.length; i++ ) {
|
||||
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
||||
if (level[i][4] == 0) {
|
||||
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() {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -60,6 +85,12 @@ void drawBackground() {
|
||||
|
||||
|
||||
fill(0);
|
||||
|
||||
randomSeed(0);
|
||||
drawPalm(100, 700);
|
||||
drawPalm(200, 700);
|
||||
drawPalm(300, 700);
|
||||
drawPalm(400, 700);
|
||||
}
|
||||
|
||||
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
|
||||
// TODO Check if json is empty. If it is generate level
|
||||
// int[][] level = new int[100][4];
|
||||
@ -82,6 +129,7 @@ int savetofile(String filename) {
|
||||
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);
|
||||
}
|
||||
@ -89,27 +137,37 @@ int savetofile(String filename) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean checkSaveFile(String filepath) {
|
||||
return new File(dataPath(filepath)).exists();
|
||||
}
|
||||
|
||||
int[][] loadJson(String jsonfile) {
|
||||
JSONArray values = loadJSONArray(jsonfile);
|
||||
// println(values.size());
|
||||
if (checkSaveFile("./saves/save.json")) {
|
||||
JSONArray values = loadJSONArray(jsonfile);
|
||||
// println(values.size());
|
||||
|
||||
int[][] arrayfromjson = new int[values.size()][values.size()];
|
||||
int[][] arrayfromjson = new int[values.size()][values.size()];
|
||||
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
|
||||
JSONArray jsontoarray = values.getJSONArray(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 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_x[i] = x;
|
||||
arrayfromjson[i][0] = x;
|
||||
arrayfromjson[i][1] = y;
|
||||
arrayfromjson[i][2] = rectwidth;
|
||||
arrayfromjson[i][3] = rectheight;
|
||||
// arrayfromjson_x[i] = x;
|
||||
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;
|
||||
}
|
||||
return arrayfromjson;
|
||||
}
|
||||
|
||||
@ -1,599 +1,699 @@
|
||||
[
|
||||
[
|
||||
405,
|
||||
595,
|
||||
417,
|
||||
598,
|
||||
100,
|
||||
50,
|
||||
50
|
||||
0
|
||||
],
|
||||
[
|
||||
823,
|
||||
337,
|
||||
312,
|
||||
660,
|
||||
100,
|
||||
50,
|
||||
50
|
||||
1
|
||||
],
|
||||
[
|
||||
1002,
|
||||
560,
|
||||
679,
|
||||
646,
|
||||
100,
|
||||
50,
|
||||
50
|
||||
1
|
||||
],
|
||||
[
|
||||
885,
|
||||
678,
|
||||
167,
|
||||
633,
|
||||
100,
|
||||
50,
|
||||
50
|
||||
1
|
||||
],
|
||||
[
|
||||
1027,
|
||||
338,
|
||||
465,
|
||||
665,
|
||||
100,
|
||||
50,
|
||||
50
|
||||
0
|
||||
],
|
||||
[
|
||||
929,
|
||||
686,
|
||||
578,
|
||||
649,
|
||||
100,
|
||||
50,
|
||||
50
|
||||
0
|
||||
],
|
||||
[
|
||||
925,
|
||||
322,
|
||||
50,
|
||||
50
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
1024,
|
||||
717,
|
||||
50,
|
||||
50
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
927,
|
||||
344,
|
||||
50,
|
||||
50
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
1013,
|
||||
564,
|
||||
50,
|
||||
50
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
825,
|
||||
463,
|
||||
50,
|
||||
50
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
1012,
|
||||
454,
|
||||
50,
|
||||
50
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
1622,
|
||||
495,
|
||||
50,
|
||||
50
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
1687,
|
||||
130,
|
||||
50,
|
||||
50
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user