Recent

Author Topic: dartboard  (Read 31890 times)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #15 on: December 24, 2014, 10:27:40 pm »
ah, yes. Since there're 20 parts each sector is only 18 deg.

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #16 on: December 24, 2014, 10:57:44 pm »
Quote
ah, yes. Since there're 20 parts each sector is only 18 deg.
I was just about to make a comment on that

Quote
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)
That's genius, I only don't have any idea on how to use it....

Quote
Code: [Select]
procedure TForm1.Image1Click(Sender: TObject);
begin
v := IntToStr(TImage(Sender).Tag);
Form1.test.Text:= v ;
end;
works now, thanks :)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #17 on: December 24, 2014, 10:58:56 pm »
ugh... too tired today! Spoiler: (Since the size of a sector is known and static, there's no need for "sector" search loop at all. "div" operation can be used to determine the exact sector and the score for it is kept in an array)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #18 on: December 24, 2014, 11:01:38 pm »
I only don't have any idea on how to use it....

I'd suggest you to give a try!  It's much easier than you might think!

If you still give up... well, we can trade. If you donate 5 euro to the Lazarus project (the link is at the left part of the page. I'll ask for the screenshot of the confirmation number), I'll give you the code... But it's much better if you try to implement it yourself first. You've all the formulas and the algorithm.
« Last Edit: December 24, 2014, 11:06:10 pm by skalogryz »

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: dartboard
« Reply #19 on: December 25, 2014, 09:24:43 am »
That would be much more funny if a player would 'throw darts' not by clicking, but by spinning mouse wheel at another TImage.onmousewheel (e.g. strength = total 'wheel' value for the last second) and grabbing mouse x position with onmouseover :)
Or another idea - to let a square Image2 randomly spawn around the image1. First click at image 2 would define x1y1 and another x2y2. And then based on x1y1x2y2 vector determine the throw strength (=vector length) & throw angle (considering Image2 current position).
Hehe... and make the dartboard move around the image1 & spin.

I know, you won't do that now... but honestly... game programming is the most exciting way of learning the language :)  However, definitely not the best one :)
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #20 on: December 25, 2014, 09:13:13 pm »
I only don't have any idea on how to use it....

I'd suggest you to give a try!  It's much easier than you might think!

If you still give up... well, we can trade. If you donate 5 euro to the Lazarus project (the link is at the left part of the page. I'll ask for the screenshot of the confirmation number), I'll give you the code... But it's much better if you try to implement it yourself first. You've all the formulas and the algorithm.

I'll do that if I don't see another way out, I'd like to try it myself first

also this happened http://i.imgur.com/j5ygcm2.png?1
the pictures are overlapping each other, is there a way to prevent that from happening?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #21 on: December 26, 2014, 01:30:02 am »
also this happened http://i.imgur.com/j5ygcm2.png?1
the pictures are overlapping each other, is there a way to prevent that from happening?
nope. TImage are always rectangular. Maybe instead of breaking an image into separate TImage, you could just two images - one for the board itself, another for pixel map.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: dartboard
« Reply #22 on: December 26, 2014, 12:55:38 pm »
Hmmmmmmmmmmmmm.... came up with a good idea!
You can use TBitmap;
and then TBitmap.color[x,y] to get the clicked color. And the only thing left is to make the each dartboard segment color different depending on the score and known (beware of intermediate lines) :)
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #23 on: December 26, 2014, 01:49:47 pm »
Hmmmmmmmmmmmmm.... came up with a good idea!
You can use TBitmap;
and then TBitmap.color[x,y] to get the clicked color. And the only thing left is to make the each dartboard segment color different depending on the score and known (beware of intermediate lines) :)
I was actually thinking a similar thing, I only can't find a Tbitmap button...

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #24 on: December 26, 2014, 02:20:41 pm »
well, you don't need one.

TImage is going to used to show the dartboard on the screen.

Pixel map, that I referred in my previous post, is your TBitmap. It doesn't have to be visible at all, since you're using it for hit-testing only. You can create TBitmap and load the bitmap behind the scene


Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #25 on: December 26, 2014, 02:45:12 pm »
well, you don't need one.

TImage is going to used to show the dartboard on the screen.

Pixel map, that I referred in my previous post, is your TBitmap. It doesn't have to be visible at all, since you're using it for hit-testing only. You can create TBitmap and load the bitmap behind the scene

do I have to convert a normal picture to pixel map or is it something you can do in Lazarus?
and how can I add a value to a color? like I said before, I'm really new to Lazarus pascal

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #26 on: December 26, 2014, 03:04:13 pm »
do I have to convert a normal picture to pixel map or is it something you can do in Lazarus?
and how can I add a value to a color? like I said before, I'm really new to Lazarus pascal
You cannot convert "a normal picture" to pixel map. Pixel map is a "normal picture", that has a special image on it.
So creating one, won't require you any knowledge of Lazarus, but rather some graphical editor that could save you some time in generating one.

The idea is that every part of the board has it's own "logical" color. The program would take the "logical color" and map it to a score.
(That brings you to an array of colors and scores).

Once a user clicks on TImage (that represents a nice looking dartboard) - you get X,Y value. Then you would read a color value from the pixel map bitmap. That gives you the "logical" color. Then you lookup the score value in your color-to-score table.

Obvious restrictions and limitations.  PixelMap must match in size to the normal image of the dartboard.
« Last Edit: December 26, 2014, 03:08:11 pm by skalogryz »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #27 on: December 26, 2014, 03:16:46 pm »
colored pizza!  ... and mspaint is not the best utility to do that, but still possible.

Xienix

  • New Member
  • *
  • Posts: 26
Re: dartboard
« Reply #28 on: December 26, 2014, 03:23:28 pm »
Quote
You cannot convert "a normal picture" to pixel map. Pixel map is a "normal picture", that has a special image on it.
So creating one, won't require you any knowledge of Lazarus, but rather some graphical editor that could save you some time in generating one.

The idea is that every part of the board has it's own "logical" color. The program would take the "logical color" and map it to a score.
(That brings you to an array of colors and scores).

Once a user clicks on TImage (that represents a nice looking dartboard) - you get X,Y value. Then you would read a color value from the pixel map bitmap. That gives you the "logical" color. Then you lookup the score value in your color-to-score table.

so 2 pictures on top of each other, the lowest one having all different colors and to top one a picture of the dartboard?

lets say I've done that, how do I use it? writing the codes for it and connect each color to a variable?

Quote
colored pizza!  ... and mspaint is not the best utility to do that, but still possible.
I'm going to use photoshop for it, I'll take a picture of a dartboard, use it as a background and redraw it and fill it with different colors at the end

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: dartboard
« Reply #29 on: December 26, 2014, 03:26:22 pm »
so 2 pictures on top of each other, the lowest one having all different colors and to top one a picture of the dartboard?
No need to physically put two TImages on the form. Just one - nice looking dartboard.
The map should be invisible and it's better to load in the code. Thus you can use TBitmap class.

lets say I've done that, how do I use it? writing the codes for it and connect each color to a variable?
Yes, you need to write the code to connect a color to a score value or a variable.
By using a lot of IF statements, or CASE statements, or arrays with loops... or anything else that seems reasonable.

 

TinyPortal © 2005-2018