Bathroom Matters

Show us your works in progress and request feedback

Post » Thu Mar 10, 2016 5:44 pm

I have this game I am working on for a client.
https://www.scirra.com/arcade/other-gam ... -game-6075

The problem is, the taps overlap sometimes. I need help with randomly positioning the holes in the wall, such that, the taps do not overlap.

Thanks you.
B
13
S
3
Posts: 22
Reputation: 1,195

Post » Sat Mar 19, 2016 4:24 pm

Hi,

there's two and more possible solutions to do this:

1) Base the tap spawning on a grid. For example if your tap sprite is 32x32 pixels, than this is the minimum distance between to taps.

2) Upon spawning a tap, check the distance of it to each other tap. With a for each loop, you can check distance (x1,y1,x2,y2) > 32. If true, proceed with the spawn. Else, reiterate.

Solution 1) is more elegant with the downside of having a fixed grid. Solution 2) lets you keep completely random positions at the cost of some calculation time.

Cheers!
Image
B
17
S
5
G
1
Posts: 122
Reputation: 1,930


Return to Works in Progress/Feedback Requests

Who is online

Users browsing this forum: anty21ro, Mayfly and 1 guest