map editor deletion
This commit is contained in:
parent
53b9f7b136
commit
d991e79538
@ -24,50 +24,6 @@ PVector tilesize = new PVector(50, 50);
|
||||
|
||||
int[][] level;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void menu() {
|
||||
rectWithText(width/2, height/2, 100, 50, "test", 40);
|
||||
}
|
||||
|
||||
|
||||
void rectWithText(float rectX, float rectY, float rectWidth, float rectHeight, String rectText, float ts) {
|
||||
// rect
|
||||
rectMode(CENTER);
|
||||
rect(rectX, rectY, rectWidth, rectHeight);
|
||||
|
||||
// text
|
||||
textSize(ts);
|
||||
textAlign(CENTER,CENTER);
|
||||
fill(0);
|
||||
text(rectText, rectX, rectY);
|
||||
|
||||
// stop painting
|
||||
noFill();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// The actual game
|
||||
@ -93,11 +49,6 @@ void play() {
|
||||
// moveTiles();
|
||||
}
|
||||
|
||||
// This is basically the Level file:
|
||||
// It consists out of an array, that spawns tiles
|
||||
// It is also checked in collisionTest()
|
||||
int[] tiles_x = { 300, 50, 600, 50};
|
||||
int[] tiles_y = { 500, 50, 600, 200 };
|
||||
|
||||
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
||||
void collisionTest() {
|
||||
|
||||
@ -32,3 +32,18 @@ void keyPressed () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int runnerRect = 0;
|
||||
void mouseReleased() {
|
||||
if(iseditor) {
|
||||
if (mouseButton == LEFT) {
|
||||
level[runnerRect][0] = mouseX+screenx;
|
||||
level[runnerRect][1] = mouseY;
|
||||
level[runnerRect][2] = 50;
|
||||
level[runnerRect][3] = 50;
|
||||
println("generated");
|
||||
runnerRect = runnerRect + 1;
|
||||
println(runnerRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +60,8 @@ void mainMenu() {
|
||||
|
||||
void mapEditor() {
|
||||
background(255);
|
||||
generate_tiles();
|
||||
generate_editor_tiles();
|
||||
// generate_tiles();
|
||||
}
|
||||
|
||||
boolean drawRectWithColission(int x, int y, int rectwidth, int rectheight) {
|
||||
@ -69,7 +70,7 @@ boolean drawRectWithColission(int x, int y, int rectwidth, int rectheight) {
|
||||
rect(x, y, rectwidth, rectheight);
|
||||
|
||||
// Check it for collission
|
||||
if((mouseX > x - 2/rectwidth && mouseX < x + rectwidth/2) && (mouseY > y - rectheight/2 && mouseY < y + rectheight/2)) {
|
||||
if((mouseX > x - rectwidth/2 && mouseX < x + rectwidth/2) && (mouseY > y - rectheight/2 && mouseY < y + rectheight/2)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
67
game/map.pde
67
game/map.pde
@ -1,3 +1,4 @@
|
||||
int screenx = 0;
|
||||
|
||||
void generate_tiles() {
|
||||
for (int i = 0; i < level.length; i++ ) {
|
||||
@ -5,20 +6,23 @@ void generate_tiles() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int runnerRect = 0;
|
||||
void mouseReleased() {
|
||||
if(iseditor) {
|
||||
level[runnerRect][0] = mouseX+screenx;
|
||||
level[runnerRect][1] = mouseY;
|
||||
level[runnerRect][2] = 50;
|
||||
level[runnerRect][3] = 50;
|
||||
println("generated");
|
||||
runnerRect = runnerRect + 1;
|
||||
println(runnerRect);
|
||||
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 (drawRectWithColission(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO Check if json is empty. If it is generate level
|
||||
// int[][] level = new int[100][4];
|
||||
JSONArray json;
|
||||
@ -40,20 +44,27 @@ int savetofile(String filename) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int screenx = 0;
|
||||
// void keyPressed() {
|
||||
// if (key == 's') {
|
||||
// println("saved");
|
||||
// savetofile("save");
|
||||
// } else if (key == CODED) {
|
||||
// if (keyCode == RIGHT) {
|
||||
// screenx = screenx + 50;
|
||||
// println("moved right!");
|
||||
// println(screenx);
|
||||
// } else if (keyCode == LEFT) {
|
||||
// screenx = screenx - 50;
|
||||
// println("moved right!");
|
||||
// println(screenx);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user