PDA

Click to See Complete Forum and Search --> : Darts game


Fishcake
Mar 3rd, 2001, 10:26 AM
Hi,

I'm trying to develop a darts game, mainly to learn some new stuff, but have run into a brick wall trying to work out which segment of the board the dart has hit.

I don't know wether this should be done using co-ords of the screen, shapes or sectors drawn on the form etc.
And then doubles and trebles have to be taken into account.

Any help will be greatly appreciated.

kedaman
Mar 3rd, 2001, 12:25 PM
Assuming you know the center of the circle, the point hit and for each sector, it's angle spec and radius spec you could do this with arctangent, the vb function is called atn and is not a good option when you hit vertical to the center. Look up Guv's Arktangent in the math forum.

The center offsets are given:
dx=hit.x-center.x
dy=hit.y-center.y
The radius is given by:
r=sqr(dx*dx+dy*dy)
The angle is given by:
a=ArkTangent(dy,dx)
I'm not too familiar with the dart so i don't know where you have the scores, but they are 20 right? in that case you can get's the index counterclockwise from right.

each sector spec is 2*pi/20 radians which is 0.31415 starting from an offset is 2*pi/40 radians which is 0.157075
so the index is given by:
i=(a-0.157075)\0.31415
have a select case for radius (r) going trough the double and tripple sectors specs, ascending or descending.

HarryW
Mar 3rd, 2001, 02:23 PM
If that looks like too much maths to you, an alternative would be to make a second identical outline image of the dartboard, and then fill each seperate scoring region with a different colour. When a certain point is hit on the proper dartboard image, you can check the equivalent image to see what the colour is at that point (you could use GetPixel). You could use a Select Case statement or something similar to check what region each colour was equivalent to.

Kedaman's suggestion is more efficient, this is just a less mathematical alternative.

kedaman
Mar 3rd, 2001, 04:32 PM
No actually Harry ;) your would be more efficient, regarding cpu usage, but on the other hand would require a whole bitmap of memory and a device context. If you use a RGB color code indicating the score directly you don't need any select case.

HarryW
Mar 3rd, 2001, 06:30 PM
Well yes I was thinking that, but I wanted to make it as simple as possible :)

Fishcake
Mar 4th, 2001, 07:57 AM
Cheers Harry and Kedaman thats given me plenty to work with, think i was going about it the wrong way to start with.

Thanks again.