Array Collision
in
Programming Questions
•
5 months ago
Hi everyone,
I'm making a maze game that contains a substantial amount of objects (trees, rocks, etc.). The map is quite big (4000 to 64000 pixels depending on the difficulty. Here's how I generate my map:
EDIT: On the topic of collision, How do I check collision for every non-transparent pixel of an image? My trees are basically circles to the collision algorithm but they're shown with a PImage and trees are of course lopsided so some clear areas are blocked and some covered areas are walkable.
I'm making a maze game that contains a substantial amount of objects (trees, rocks, etc.). The map is quite big (4000 to 64000 pixels depending on the difficulty. Here's how I generate my map:
- int[] mapx = new int[int(sq(mapSize/4000)*512 )]; //x coordinate of a tree
int[] mapy = new int[mapx.length]; //y coordinate of a tree
boolean[] mapi = new boolean[mapx.length]; // type of tree - void randomize() {
- for ( int i=0; i < mapx.length; i++ ) {
boolean out = true;
while (out) {
out = false;
mapx[i] = int(random(mapSize));
mapy[i] = int(random(mapSize));
mapi[i] = boolean(int(random(2)));
if (mapx[i] < pos.x+100 && mapx[i] > pos.x-100 && mapy[i] < pos.y+100 && mapy[i] > pos.y-100) {
out = true;
}
if (mapx[i] < cp.x+500 && mapx[i] > cp.x-500 && mapy[i] < cp.y+500 && mapy[i] > cp.y-500) {
out = true;
}
for (int j = 0; j < i; j++) {
float td = sqrt(sq(abs(mapx[i] - mapx[j])) + sq(abs(mapy[i] - mapy[j])));
if (td < 80) {
out = true;
break;
}
}
}
} - }
EDIT: On the topic of collision, How do I check collision for every non-transparent pixel of an image? My trees are basically circles to the collision algorithm but they're shown with a PImage and trees are of course lopsided so some clear areas are blocked and some covered areas are walkable.
1