Recent

Author Topic: dartboard  (Read 31318 times)

Xienix

  • New Member
  • *
  • Posts: 26
dartboard
« on: December 24, 2014, 04:32:25 pm »
Good evening folks from this lovely forum

I've got a little problem, we have to program/make a working dartboard for school
The teacher says we have the knowledge to do it,even though no one has a clue where to start. I know some of you are laughing right now but that's the truth, no one knows how to make it .-.

I've got an idea on where to start but then I need to know a few things first....

how can I make a shape into a button (with the shape still being round) or how can I click on a shape with it doing something?

Thanks :)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #1 on: December 24, 2014, 04:34:43 pm »
how can I make a shape into a button (with the shape still being round) or how can I click on a shape with it doing something?
You can use an image instead of a button. An image if transparency.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #2 on: December 24, 2014, 04:37:57 pm »
may be the complication is not if a image of transparency, but instead you need to calculate the sector based of the dart's x,y position?

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #3 on: December 24, 2014, 05:03:10 pm »
how can I make a shape into a button (with the shape still being round) or how can I click on a shape with it doing something?
You can use an image instead of a button. An image if transparency.

That's a very good idea

may be the complication is not if a image of transparency, but instead you need to calculate the sector based of the dart's x,y position?

I don't think so, the idea is that you've got to get from 501 to 0 as fast as possible. I've made a vast sketch to illustrate it
http://i.imgur.com/lZBLTmK.png?1 each circle has its own value, if you click on a circle the value will subtract from 501 until you've reached 0
working with pictures is the way to go in my opinion

Thanks for the quick response btw

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #4 on: December 24, 2014, 05:08:25 pm »
I don't think so, the idea is that you've got to get from 501 to 0 as fast as possible. I've made a vast sketch to illustrate it
http://i.imgur.com/lZBLTmK.png?1 each circle has its own value, if you click on a circle the value will subtract from 501 until you've reached 0
working with pictures is the way to go in my opinion

Thanks for the quick response btw
That's the thing. detecting a circle of the x,y position is faster than using buttons or images.

If you'd have a task with one circle (where you know the center position and radius of the circle), would you know how to determine if a point with known x,y position is within the circle or not?

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #5 on: December 24, 2014, 05:16:00 pm »
I don't think so, the idea is that you've got to get from 501 to 0 as fast as possible. I've made a vast sketch to illustrate it
http://i.imgur.com/lZBLTmK.png?1 each circle has its own value, if you click on a circle the value will subtract from 501 until you've reached 0
working with pictures is the way to go in my opinion

Thanks for the quick response btw
That's the thing. detecting a circle of the x,y position is faster than using buttons or images.

If you'd have a task with one circle (where you know the center position and radius of the circle), would you know how to determine if a point with known x,y position is within the circle or not?

that's true and I would have done it if it were only circles but I'm planning to use the multipliers as well

now I need to know how to add a value to a image....   

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #6 on: December 24, 2014, 05:21:51 pm »
that's true and I would have done it if it were only circles but I'm planning to use the multipliers as well
can you make an example of a multiplier? .. something like this http://ibin.co/1lkzaiss3TID?

now I need to know how to add a value to a image....
well, if you're using TImage ... (which I doubt though) it should have "Tag" property. This is a nice place to put the value at.
« Last Edit: December 24, 2014, 05:28:11 pm by skalogryz »

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #7 on: December 24, 2014, 05:37:05 pm »
that's true and I would have done it if it were only circles but I'm planning to use the multipliers as well
can you make an example of a multiplier? .. something like this http://ibin.co/1lkzaiss3TID?

now I need to know how to add a value to a image....
well, if you're using TImage ... (which I doubt though) it should have "Tag" property. This is a nice place to put the value at.

http://darts.is-leuk.nl/afbeeldingen/scores%20dart%20bord.png I meant the double ring and the triple ring, I don't know the English word for it

I am actually using TImage....so it's possible to give the picture a number which you can connect to a variable?


skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #8 on: December 24, 2014, 05:45:58 pm »
http://darts.is-leuk.nl/afbeeldingen/scores%20dart%20bord.png I meant the double ring and the triple ring, I don't know the English word for it
Well, that's even easier than sectors.
So, if you'd go by calculating position of X,Y towards a circle you'd make a nice christmas gift to your teacher :)

And if you know the relation between a point and a circle, then you've your task solved. Even with multipliers.

I am actually using TImage....so it's possible to give the picture a number which you can connect to a variable?
Yes, there's property named "Tag" you should see it in the ObjectInspector.

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #9 on: December 24, 2014, 06:14:52 pm »
http://darts.is-leuk.nl/afbeeldingen/scores%20dart%20bord.png I meant the double ring and the triple ring, I don't know the English word for it
Well, that's even easier than sectors.
So, if you'd go by calculating position of X,Y towards a circle you'd make a nice christmas gift to your teacher :)

And if you know the relation between a point and a circle, then you've your task solved. Even with multipliers.

I am actually using TImage....so it's possible to give the picture a number which you can connect to a variable?
Yes, there's property named "Tag" you should see it in the ObjectInspector.

I bet it would but I'm still very new to programming so I'll have to convince him that I made it myself

I've been searching everywhere on the internet for the last 30 min on how to use it, but I can't find it
do you mind explaining on how to use Tag?


skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #10 on: December 24, 2014, 06:30:24 pm »
I bet it would but I'm still very new to programming so I'll have to convince him that I made it myself
As long as you understand what's happening in the code you did your self.

So back to my first question.
If you know, x,y of a point and center pos of a circle and its radius, do you know how to determine if it's within the circle or outside of it?
(hint: it's more of math, than programming)

I've been searching everywhere on the internet for the last 30 min on how to use it, but I can't find it
do you mind explaining on how to use Tag?
Sure, whenever you click on TImage. OnClick (or MouseUp/MouseDown) event is fired.
In the event handler there's "Sender"parameter. This Sender is actually the TImage that has been pressed.
So you can cast it and get the value of tag, like this:
Code: [Select]
  v := TImage(Sender).Tag;

So if you assign tag value to your multiplier image as 10. You'll know that you hit the multiplier. ... each piece of the dartboard will come with its own image.

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #11 on: December 24, 2014, 07:21:12 pm »
I bet it would but I'm still very new to programming so I'll have to convince him that I made it myself
As long as you understand what's happening in the code you did your self.

So back to my first question.
If you know, x,y of a point and center pos of a circle and its radius, do you know how to determine if it's within the circle or outside of it?
(hint: it's more of math, than programming)

I've been searching everywhere on the internet for the last 30 min on how to use it, but I can't find it
do you mind explaining on how to use Tag?
Sure, whenever you click on TImage. OnClick (or MouseUp/MouseDown) event is fired.
In the event handler there's "Sender"parameter. This Sender is actually the TImage that has been pressed.
So you can cast it and get the value of tag, like this:
Code: [Select]
  v := TImage(Sender).Tag;

So if you assign tag value to your multiplier image as 10. You'll know that you hit the multiplier. ... each piece of the dartboard will come with its own image.
everything in a certain radius from the center pos. you can calculate it with (x-h)^2 + (y-k)^2 = r^2, take the root of r^2 and you've got a radius, right?
I just figured out that every slice of the board has its own score, so this wont work...

Thanks, but as soon as I add it an error appears : Error: Incompatible types: got "LongInt" expected "AnsiString"


skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #12 on: December 24, 2014, 07:41:37 pm »
everything in a certain radius from the center pos. you can calculate it with (x-h)^2 + (y-k)^2 = r^2, take the root of r^2 and you've got a radius, right?
I just figured out that every slice of the board has its own score, so this wont work...
The formula looks correct. The only difference, is that you don't need to compare for equality but rather know if the point is less or equal than the "hit point" radius.

Now, as you mentioned it many times there're multiple slices on the board.
Thus you need to check from the smallest part to the biggest part.

Once you find the radius that's greater than your "hit point" radius - it's your score!

Assume that the center has radius of 2, then the next large piece, has radius of 14, then the the multiplier has radius 15.

Thus the code... might... look like this.
Code: [Select]
const
  CENTER_RAD = 2;  CENTER_SCORE := 50;
  LARGE_RAD =  14; ;  LARGE_SCORE := 5;
  MULT_RAD = 15; ;  MULT_SCORE := 100;

 hitRadius = getRadius(x,y);
 if hitRadius <= CENTER_RAD then
   score := CENTER_SCORE
 else if hitRadius <= LARGE_RAD then
   score := LARGE_RAD
 else if hitRadius <= MULT_RAD then
   score := MULT_RAD
 ...
...and.. so on...

Thanks, but as soon as I add it an error appears : Error: Incompatible types: got "LongInt" expected "AnsiString"
not sure what was added. please post the code.
« Last Edit: December 24, 2014, 07:47:38 pm by skalogryz »

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #13 on: December 24, 2014, 10:04:26 pm »
looks great :D but if you take large rad for example, now the whole large circle is worth 5 points
but in darts you'll be given a certain amount of points for a slice of that circle http://i.imgur.com/QD278OM.png (made it red)...so is it possible to split 1 full circle into 20 parts? 

here's the code (I'm just testing if it works)
http://notes.io/ZBw

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #14 on: December 24, 2014, 10:17:27 pm »
looks great :D but if you take large rad for example, now the whole large circle is worth 5 points
but in darts you'll be given a certain amount of points for a slice of that circle http://i.imgur.com/QD278OM.png (made it red)...so is it possible to split 1 full circle into 20 parts? 
Determine which circle is your first step. Once you know which circle you hit, you can determine the actual sector. (If needed. If you hit center - there're no sectors there)
Sector can be identified via angle of the hit point. Similar to radius - start with minimum and go until you find it... yes... loops on array.

The angle can be determined by using arctan2 function. Because it almost removes all the headache from you...

Spoiler: (the whole task is just two loops)
here's the code (I'm just testing if it works)
http://notes.io/ZBw
Code: [Select]
procedure TForm1.Image1Click(Sender: TObject);
begin
v := IntToStr(TImage(Sender).Tag);
Form1.test.Text:= v ;
end;
« Last Edit: December 24, 2014, 10:25:06 pm by skalogryz »

 

TinyPortal © 2005-2018