8 posts
• Page **1** of **1**

In the case of a dart target, I would use concentric circles.

So a circle image and collision polygon, and you size them accordingly to each section (1 point, 2 points, 4 points and so on).

In the code, to know what "section" your dart is currently touching, you end up with something like :

Dart is overlapping Section_n - 1

Dart is overlapping Section_n

Dart is not overlapping Section_n + 1

As the conditions to determine what "Section_n" is.

I would use instances for each section of the target, the animation frame allowing me to determine Section_n.

I hope it makes sense.

So a circle image and collision polygon, and you size them accordingly to each section (1 point, 2 points, 4 points and so on).

In the code, to know what "section" your dart is currently touching, you end up with something like :

Dart is overlapping Section_n - 1

Dart is overlapping Section_n

Dart is not overlapping Section_n + 1

As the conditions to determine what "Section_n" is.

I would use instances for each section of the target, the animation frame allowing me to determine Section_n.

I hope it makes sense.

**Posts:**7,357**Reputation:**73,458

Moderator

B

304
S

123
G

99
**Posts:**1,519**Reputation:**11,084

B

67
S

24
G

7
Message: sherlykim can only post plain text URLS until they have 500 rep. **1** URLS modified. Why?

korbaach wrote:..or just calculate the distance and angle...

https://app.box.com/s/08mnlrvyopvod441erx5f9uv44en0adv Dartboard.capx

I just saw the capx and I have no idea how u did that x.x

**Posts:**7**Reputation:**314

B

4
S

1
Ok to break it down:

He loaded the score values in order, counterclockwise, into an array. (6,13,4,18,ect...)

Then normalize the angle() expression (normally returns -180 to 180) with angle()+360%360, resulting in a value 0-360 (this is dAngle)

Then map that angle to the array with (20-(round(dAngle/18)))%20. (this is dIndex)

Based on the distance from the center, you can determine if the final score (dNumber) should be a inner bullseye at 50, outerbullseye at 25, or a multiple of the base value stored in the array.

He uses some nice math to to be efficient. If you have trouble wrapping your head around that (and or the array), here's general pseudocode:

If distance (from middle) is less than (bullseye size), then score = 50

else if distance is less than (2*bullseye size), then score = 25

else if distance is greater than (dartboard score zone), then score = 0

ELSE

If -10<angle<10, score = 6

If 10<angle<30, score = 13

If 30<angle<50, score = 4

and so on...

and after that if the dart is within a certain distance from the middle, multiply the score by 2 or 3 (bonus rings)

-------- OR -----------

The arguably simplest way is to make invisible placeholder sprites for each target zone with a score variable for each instance. This could be a lot of work though, and not nearly as accurate as the mathematical way with distance and angle (you might have overlaps or gaps).

He loaded the score values in order, counterclockwise, into an array. (6,13,4,18,ect...)

Then normalize the angle() expression (normally returns -180 to 180) with angle()+360%360, resulting in a value 0-360 (this is dAngle)

Then map that angle to the array with (20-(round(dAngle/18)))%20. (this is dIndex)

Based on the distance from the center, you can determine if the final score (dNumber) should be a inner bullseye at 50, outerbullseye at 25, or a multiple of the base value stored in the array.

He uses some nice math to to be efficient. If you have trouble wrapping your head around that (and or the array), here's general pseudocode:

If distance (from middle) is less than (bullseye size), then score = 50

else if distance is less than (2*bullseye size), then score = 25

else if distance is greater than (dartboard score zone), then score = 0

ELSE

If -10<angle<10, score = 6

If 10<angle<30, score = 13

If 30<angle<50, score = 4

and so on...

and after that if the dart is within a certain distance from the middle, multiply the score by 2 or 3 (bonus rings)

-------- OR -----------

The arguably simplest way is to make invisible placeholder sprites for each target zone with a score variable for each instance. This could be a lot of work though, and not nearly as accurate as the mathematical way with distance and angle (you might have overlaps or gaps).

Mistakes were made.

**Posts:**1,712**Reputation:**65,172

B

57
S

28
G

115
8 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: Asmodean, Google [Bot] and 4 guests |