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
14
S
3
Posts: 22
Reputation: 1,220

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
19
S
6
G
1
Posts: 125
Reputation: 2,086


Return to Works in Progress/Feedback Requests

Who is online

Users browsing this forum: No registered users and 0 guests