How do I: is there a way to define sections with in sprite?

Get help using Construct 2

Post » Thu Jun 09, 2016 9:12 am

so, i'm making a dart game, and I want to define each sections of the dart board to be different numbers. Do i have to make dart board from the scratch to define each little sections? or is there other ways to define little sections of the sprite? :D :D
B
4
S
1
Posts: 7
Reputation: 314

Post » Thu Jun 09, 2016 9:28 am

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.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,328
Reputation: 71,298

Post » Thu Jun 09, 2016 10:48 am

..or just calculate the distance and angle...

Image



Dartboard.capx
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Wed Jun 15, 2016 4:26 am

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...

Image



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


I just saw the capx and I have no idea how u did that x.x
B
4
S
1
Posts: 7
Reputation: 314

Post » Wed Jun 15, 2016 6:30 am

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).
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Wed Jun 15, 2016 7:20 am

Thank you oosyrag i totally get what u are saying as of pseudocode, but i just dont see WHERE that was implemented in the capx file.
B
4
S
1
Posts: 7
Reputation: 314

Post » Wed Jun 15, 2016 7:31 am

OH. See the little + in a box next to event 2? Click that haha

Next to event 6 too.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Wed Jun 15, 2016 7:33 am

OH THANK YOU so much!
B
4
S
1
Posts: 7
Reputation: 314


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests