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

  • 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?

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

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

    Dartboard.capx

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

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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

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

    Next to event 6 too.

  • OH THANK YOU so much!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)