diff --git a/program.pde b/game/game.pde similarity index 93% rename from program.pde rename to game/game.pde index 465307f..55af87e 100644 --- a/program.pde +++ b/game/game.pde @@ -105,21 +105,22 @@ void generate_tiles() { // TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection void collisionTest() { // Collision with baseline - if ( pos.y > baseline_y - playerRadius ) { - pos.set(pos.x, baseline_y - playerRadius); + if ( pos.y > baseline_y - playerRadius/2 ) { + pos.set(pos.x, baseline_y - playerRadius/2); } // 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 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; - + // Bottom if ( (xSideEdges) && (ySideEdges)) { pos.set(pos.x, tiles_y[i] + tilesize.y/2); } - 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 - 20); + // 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); } } } diff --git a/map/map.json b/map/map.json new file mode 100644 index 0000000..6b34303 --- /dev/null +++ b/map/map.json @@ -0,0 +1,18 @@ +[ + [ + 50, + 50 + ], + [ + 417, + 414 + ], + [ + 602, + 165 + ], + [ + 308, + 296 + ] +] \ No newline at end of file diff --git a/map/map.pde b/map/map.pde new file mode 100644 index 0000000..9b196b9 --- /dev/null +++ b/map/map.pde @@ -0,0 +1,54 @@ +JSONArray json; + +void setup() { + size(800,800); + // json = loadJSONArray("map.json"); + + // JSONObject values = json.getJSONObject(1); + + // int x = values.getInt("x"); + // print(x); + +} + +void draw() { + background(255); + generate_tiles(); +} + +PVector tilesize = new PVector(50, 50); +int[] tiles_x = {50}; +int[] tiles_y = {50}; +void pickTiles() { + +} + +void generate_tiles() { + for (int i = 0; i < tiles_x.length; i++ ) { + rect(tiles_x[i], tiles_y[i], tilesize.x, tilesize.y); + } +} + +void mouseReleased() { + tiles_x = (int[])append(tiles_x, mouseX); + tiles_y = (int[])append(tiles_y, mouseY); + + println(tiles_x); +} + +void keyPressed() { + if (key == 's') { + println("saved"); + json = new JSONArray(); + + for (int i = 0; i < tiles_x.length; i++) { + + JSONArray mapsave = new JSONArray(); + mapsave.setInt(0, tiles_x[i]); + mapsave.setInt(1, tiles_y[i]); + + json.setJSONArray(i, mapsave); + } + saveJSONArray(json, "map.json"); + } +}