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[][] 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
|
// The actual game
|
||||||
@ -93,11 +49,6 @@ void play() {
|
|||||||
// moveTiles();
|
// 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
|
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
||||||
void collisionTest() {
|
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() {
|
void mapEditor() {
|
||||||
background(255);
|
background(255);
|
||||||
generate_tiles();
|
generate_editor_tiles();
|
||||||
|
// generate_tiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean drawRectWithColission(int x, int y, int rectwidth, int rectheight) {
|
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);
|
rect(x, y, rectwidth, rectheight);
|
||||||
|
|
||||||
// Check it for collission
|
// 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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
67
game/map.pde
67
game/map.pde
@ -1,3 +1,4 @@
|
|||||||
|
int screenx = 0;
|
||||||
|
|
||||||
void generate_tiles() {
|
void generate_tiles() {
|
||||||
for (int i = 0; i < level.length; i++ ) {
|
for (int i = 0; i < level.length; i++ ) {
|
||||||
@ -5,20 +6,23 @@ void generate_tiles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void generate_editor_tiles() {
|
||||||
int runnerRect = 0;
|
for (int i = 0; i < 100; i++ ) {
|
||||||
void mouseReleased() {
|
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
||||||
if(iseditor) {
|
if (drawRectWithColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) {
|
||||||
level[runnerRect][0] = mouseX+screenx;
|
if (mousePressed && iseditor) {
|
||||||
level[runnerRect][1] = mouseY;
|
if (mouseButton == RIGHT) {
|
||||||
level[runnerRect][2] = 50;
|
level[i][0] = 0;
|
||||||
level[runnerRect][3] = 50;
|
level[i][1] = 0;
|
||||||
println("generated");
|
level[i][2] = 0;
|
||||||
runnerRect = runnerRect + 1;
|
level[i][3] = 0;
|
||||||
println(runnerRect);
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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];
|
||||||
JSONArray json;
|
JSONArray json;
|
||||||
@ -40,20 +44,27 @@ int savetofile(String filename) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int screenx = 0;
|
|
||||||
// void keyPressed() {
|
int[][] loadJson(String jsonfile) {
|
||||||
// if (key == 's') {
|
JSONArray values = loadJSONArray(jsonfile);
|
||||||
// println("saved");
|
// println(values.size());
|
||||||
// savetofile("save");
|
|
||||||
// } else if (key == CODED) {
|
int[][] arrayfromjson = new int[values.size()][values.size()];
|
||||||
// if (keyCode == RIGHT) {
|
|
||||||
// screenx = screenx + 50;
|
for (int i = 0; i < values.size(); i++) {
|
||||||
// println("moved right!");
|
|
||||||
// println(screenx);
|
JSONArray jsontoarray = values.getJSONArray(i);
|
||||||
// } else if (keyCode == LEFT) {
|
|
||||||
// screenx = screenx - 50;
|
int x = jsontoarray.getInt(0);
|
||||||
// println("moved right!");
|
int y = jsontoarray.getInt(1);
|
||||||
// println(screenx);
|
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