map editor ground work
This commit is contained in:
parent
cd98f3bc12
commit
22a429cba8
@ -22,11 +22,34 @@ float actualPos;
|
||||
|
||||
PVector tilesize = new PVector(50, 50);
|
||||
|
||||
int[][] level;
|
||||
|
||||
void setup() {
|
||||
size(800,800);
|
||||
frameRate(60);
|
||||
smooth(4);
|
||||
|
||||
level = loadJson("../map/map.json");
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// arrayfromjson_x[i] = x;
|
||||
arrayfromjson[i][0] = x;
|
||||
arrayfromjson[i][1] = y;
|
||||
}
|
||||
return arrayfromjson;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
@ -42,6 +65,7 @@ void draw() {
|
||||
// menu();
|
||||
play();
|
||||
helper();
|
||||
// moveTiles();
|
||||
}
|
||||
|
||||
boolean ismenu;
|
||||
@ -98,8 +122,8 @@ int[] tiles_x = { 300, 50, 600, 50};
|
||||
int[] tiles_y = { 500, 50, 600, 200 };
|
||||
|
||||
void generate_tiles() {
|
||||
for (int i = 0; i < tiles_x.length; i++ ) {
|
||||
rect(tiles_x[i], tiles_y[i], tilesize.x, tilesize.y);
|
||||
for (int i = 0; i < level.length; i++ ) {
|
||||
rect(level[i][0], level[i][1], tilesize.x, tilesize.y);
|
||||
}
|
||||
}
|
||||
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
||||
@ -110,24 +134,24 @@ void collisionTest() {
|
||||
}
|
||||
|
||||
// Collision with all the tiles bottom site
|
||||
for (int i = 0; i < tiles_x.length; i++) {
|
||||
boolean xSideEdges = pos.x > tiles_x[i] - tilesize.x/2 && pos.x < tiles_x[i] + tilesize.x/2;
|
||||
boolean ySideEdges = pos.y < tiles_y[i] + tilesize.y/2 && pos.y > tiles_y[i] - tilesize.y/2;
|
||||
for (int i = 0; i < level.length; i++) {
|
||||
boolean xSideEdges = pos.x > level[i][0] - tilesize.x/2 && pos.x < level[i][0] + tilesize.x/2;
|
||||
boolean ySideEdges = pos.y < level[i][1] + tilesize.y/2 && pos.y > level[i][1] - tilesize.y/2;
|
||||
|
||||
// Bottom
|
||||
if ( (xSideEdges) && (ySideEdges)) {
|
||||
pos.set(pos.x, tiles_y[i] + tilesize.y/2);
|
||||
pos.set(pos.x, level[i][1] + tilesize.y/2);
|
||||
}
|
||||
// Top
|
||||
if ( (xSideEdges) && (pos.y < tiles_y[i] + tilesize.y/2 && pos.y > tiles_y[i] - tilesize.y/2 - playerRadius)) {
|
||||
pos.set(pos.x, tiles_y[i] - tilesize.y/2 - 15);
|
||||
if ( (xSideEdges) && (pos.y < level[i][1] + tilesize.y/2 && pos.y > level[i][1] - tilesize.y/2 - playerRadius)) {
|
||||
pos.set(pos.x, level[i][1] - tilesize.y/2 - 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void moveTiles() {
|
||||
for (int i = 0; i < tiles_x.length; i++) {
|
||||
tiles_x[i] = tiles_x[i] - 1;
|
||||
for (int i = 0; i < level.length; i++) {
|
||||
level[i][0] = level[i][0] - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,6 +199,9 @@ void keyPressed() {
|
||||
// pos.y = pos.y + direction.y * speed;
|
||||
// //}
|
||||
// }
|
||||
} else if (key == 'l') {
|
||||
println(loadJSONArray("../map/map.json"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user