rebuild and map editor
This commit is contained in:
parent
c3f0390160
commit
cd98f3bc12
@ -105,21 +105,22 @@ void generate_tiles() {
|
|||||||
// 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() {
|
||||||
// Collision with baseline
|
// Collision with baseline
|
||||||
if ( pos.y > baseline_y - playerRadius ) {
|
if ( pos.y > baseline_y - playerRadius/2 ) {
|
||||||
pos.set(pos.x, baseline_y - playerRadius);
|
pos.set(pos.x, baseline_y - playerRadius/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collision with all the tiles bottom site
|
// Collision with all the tiles bottom site
|
||||||
for (int i = 0; i < tiles_x.length; i++) {
|
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;
|
boolean ySideEdges = pos.y < tiles_y[i] + tilesize.y/2 && pos.y > tiles_y[i] - tilesize.y/2;
|
||||||
|
|
||||||
|
// Bottom
|
||||||
if ( (xSideEdges) && (ySideEdges)) {
|
if ( (xSideEdges) && (ySideEdges)) {
|
||||||
pos.set(pos.x, tiles_y[i] + tilesize.y/2);
|
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)) {
|
// Top
|
||||||
pos.set(pos.x, tiles_y[i] - tilesize.y/2 - 20);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
18
map/map.json
Normal file
18
map/map.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[
|
||||||
|
[
|
||||||
|
50,
|
||||||
|
50
|
||||||
|
],
|
||||||
|
[
|
||||||
|
417,
|
||||||
|
414
|
||||||
|
],
|
||||||
|
[
|
||||||
|
602,
|
||||||
|
165
|
||||||
|
],
|
||||||
|
[
|
||||||
|
308,
|
||||||
|
296
|
||||||
|
]
|
||||||
|
]
|
||||||
54
map/map.pde
Normal file
54
map/map.pde
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user