Results 1 to 6 of 6

Thread: Darts game

  1. #1

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    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.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Last edited by HarryW; Mar 3rd, 2001 at 03:31 PM.
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Well yes I was thinking that, but I wanted to make it as simple as possible
    Harry.

    "From one thing, know ten thousand things."

  6. #6

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Smile Thanks

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width