01-14-2002, 04:38 AM
Ive just started to design a simple darts game, that consists of a dartboard as a background picture, and a cross hair.
The code so far consists of the crosshair moving in a circlearound the outside of the board. When the user presses enter it begins to move in and out (towards and away from the bull). When the player presses enter again, the dart is thrown (an image moves to the crosshairs current position).
The problem that im having is that i have no idea how to score the darts position (does that read right?).
Any help appreciated.

01-14-2002, 05:30 AM
Scoring the darts will mean checking its position on the form at some point. You could check the pixel color at that particular point, but most likely you'll have to check the x and y positions of the dart, and use a lot of conditional statements to pin down its position relative to the board.

01-14-2002, 05:35 AM
is there no other way?:(
I had considered the posibility but that seems like alot of code?

01-14-2002, 05:41 AM
I cant think of anything else off the top of my head, but I think it depends on how you've coded the board at the moment. And yes, it would be a lot of code, but I think it would be however you did it.

You will need to build some sort of lookup table which contains the various areas (coordinates) and the scores associated with them. Each area would be a polygon with several coords defining it, then you'd check to see if your dart point was within the polygon.
Perhaps using the InterSectRect API will be of use...

01-14-2002, 05:42 AM
I also think you have to define all areas on the board. It would be easy if every part had his own color but there is only green/red/white and black, so you have to check them manually.

to late

01-14-2002, 05:46 AM
Ive gotta kindve idea.
I increase the angle of the cross hair by 5 degrees at a time.
And ive already calculated the distance from the cross hair to the bull.
If i use an extremely large case select on the angle, i can use if statements to set sectors along that line.
Question is WILL IT WORK?
Any feedback appreciated.

01-14-2002, 05:47 AM
Okay, here is an idea. Your program plots an imaginary line between the dart position and the centre of the board. Then, it calculates the angle this makes with the vertical axis. So then you can calculate which sector it is in (1 to 20).

From there you have two options:

Use another algorithm to calculate the distance from the centre and then from that work out whether it is a Single, Double, Triple or Bull.
Use GetPixel to find the pixel colour to work out if it is Single, Double, Triple, or Bull (you can use colours which vary too little to the naked eye but can be detected by the game code).

Just an idea....... :)

01-14-2002, 08:01 AM
Ok just my 2 cents, lira, rupee, centavo, etc....... Each ring on the board is a discreet color right? Way back up towards the beginning of this thread someone suggested checking the pixel at the point where the dart hits, seems to me this would be the best and easiest way to go at this thing. If the alternating rings are the same color (say red then black then red then black) then change the alternating reds and blacks by one like this; 255,0,0 would be 254,0,0 in the next red ring. Enough so that the computer could detect the difference but not so much that the user would be able to see the color change. Ah well enough on my thoughts on picks. :)

01-14-2002, 09:23 AM
um..... you didnt mention pence. I am most offended :p

01-14-2002, 01:51 PM
ummm, sorry Squirm. To add the the 2 cent list......,pence.

wild wolf
01-15-2002, 02:20 AM
well looks like an interesting game, well i have this option, it might work, as i havent tried it myself, first step : is ur dart image 1 single image or is it made up of different images, if it is 1 image, try to break it down into different images and assemble these images in the vb form, now second step : put a check, when the cross hair is on a certain image of the dart circle, a specific amount is added to ur score, i hope u understand what i mean

01-15-2002, 04:57 AM
I must be having a bit of a short day today, because everything you said went straight over my head.
The crosshair is just one image, (if i remember right ts just a standad icon that comes with vb.)

As for the rest of your reply, you lost me completely.

01-15-2002, 05:19 AM
Yes, but wat kind of cheese is MADE backwards?

01-15-2002, 05:52 AM

01-15-2002, 05:54 AM
Surely a cheese thats made backwards would be MILK?

Anyway, apart from that slight interruption, ive had an idea that might work.
However it uses the pythagorean therom, simple enough, but how would i get the computer to square root a number?
I think theres some expression, or fraction, but i cant remember.
Any help appreciated

01-15-2002, 06:02 AM
I think dcl3500's idea sounds the simplest and the best, there are over 16 million colours available on the computer, so you have enough room to make them all look the same to the human eye but give different results when you use the GetPixel API. no need for complex equations

01-15-2002, 06:53 AM
It might be dragging the whole program away from VB a bit but if you were to use the internet control and then create the dart board in HTML, you can then use the image map functionality of HTML. This could well be a real easy way of doing it and get your VB function to do the scoring.


01-15-2002, 07:29 AM
I think the most elegant way is using some simple math.

You know the center of the board, you know where the dart has landed, so you can calculate both distance and angle, needed to get the part on the dartboard.

01-15-2002, 07:42 AM
Got a scoring method to work work by some calculations and som if statements.
Got some more sections to finish, and the basics will be complete.
Once its near finished, i'll post it if anyones interested for some critiscim from you people.
Thanxs for all the help

01-15-2002, 07:43 AM
To obtain the square root of a number or variable, use the following equation:


So, to use the pythagorean theorem (which in my opinion would be the best choice here), do the following:

c = sqr((a*a)+(b*b))

01-15-2002, 07:50 AM
Wait. I thought the square root function was just Sqr(X) without the T.

01-15-2002, 08:32 AM
DOH! You're right, Iceplug. It's sqr(x), not sqrt(x). I've gone back and edited my post.

01-15-2002, 08:37 AM
From VBHelp:

Sqr Function
Returns a Double specifying the square root of a number.



The required number argument is a Double or any valid numeric expression greater than or equal to zero.

As far as the game is concerned, I agree with ArnoutV that the most efficient, reliable, and accurate method would be to use the angle and distance to work out the score. First, find the sector of the board (1 to 20) based on trigonometry, then use the distance (linear, not cartesian) from the bull to work out the multiplier.

01-19-2002, 07:29 PM
Make each scoring postion a different object? And see if the dart hit the object

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum