I haven’t been here in a long time. So I thought I would share this code I made with you and explain how it works (so people who don’t use Gamemaker can reverse-engineer it). Unfortunately I’m not taking part this time round, but I felt like helping those who are!

**Gamemaker Script Code**

Simply copy and paste these into two seperate scripts:

To execute the scripts simply use:

scr_health_ring(x,y,radius,thickness,maxsegments,segments,rotation,angle,direction,colour)

or

scr_health_circle(x,y,radius,maxsegments,segments,rotation,angle,direction,colour)

**Meet The Variables:**

*x,y* = the coordinates of the center of the ring

*radius* = the distance from the center to the start of the ring

*thickness* = the thickness of the ring

*rotation* = at what angle is the zero mark of the ring?

*angle* = over how many degrees does the ring span?

*max segments* = how many segments the ring is split in to

*segments* = how many of those segments are visible

*direction* = which way is the ring drawn? 1 for anti-clockwise and -1 for clockwise

*For the circle health bar the variables are the same except that thickness is not included.*

A demo (gif):

The demo is using two rings; one red and one green to simulate health.

**What is this sorcery?**

When a computer draws a circle, it is actually just a bunch of triangles arranged in the same way as slices of pie.

To find the coordinates of each triangle to be able to draw them we need a big steaming pile of math.

Specifically we need some trigonometry. Let’s start with which way is up:

Or in this case, which way is right: zero degrees.

A new temporary variable, i, will count our current angle as we sweep around the circle.

After each cycle in the loop it will change by the angle variable divided by the maxsegments.

Add to the mix our variables for radius and thickness and we can draw a triangle to work out our x and y coordinates for our triangles to draw!

From this we can get the coordinates for the two points a and b. To get point b we simply add the thickness to the radius:

Then we add the angle change to i, and get the variables c and d. Then we can connect the dots and draw one section!

Repeating this process for how many sections we want to draw will result in a ring!

This process is the same for the circle, except we only need points a, c, and the center for each triangle.

Good luck for LD 32! Hopefully this tutorial will come in handy.

I kinda rushed this. Hopefully you can understand it if you have a basic grip on maths.