|
Author
|
||||
|
More in Development
|
||||
Have you ever wondered how anyone was able to create that magical cursor in the World of Goo? Wonder no more, noble Dev.Mag reader, for this article will explain how you can put that gooey cursor into your game, in just 15 minutes. We will be using Game Maker Pro as our development tool, so to get started, open up a new project.
Add an object and call it ‘GooCursor'. A cursor is always drawn last out of all the objects in the room. This is because you want the cursor to always appear above the other sprites. To achieve this, give the ‘GooCursor' object a very low depth; -10 000 for example. Enable the ‘persistent' option, so that this object does not get destroyed when rooms are switched.
Now that the object has been created, add it to a newly created, or existing room – preferably the first room of a project. You can change the background colour of your room to what ever suits you; in this example I am using orange. Next, change the room caption to ‘WoGcursor'. I've decided to go with a high room speed of 60, to maintain a smooth motion for the goo cursor.
Create Event
Next, add the code for the ‘Create' and ‘Draw' events for the ‘GooCursor' object. Let's start with the ‘Create' event. First, we need to hide the default cursor using the following code:
window_set_cursor(cr_none);
We need variables to represent the characteristics of the goo cursor.
trail = 30; // length of goo trail radius = 18; // radius of main goo circle outline = 3; // outline in pixels surrounding the goo flow = 2; // increasing this value produces a smoother goo trail scale = 0.75; // scale difference between the front and back end of the trail
The goo cursor is made by joining many circles together in a sequence. The ‘trail' variable represents the number of circles; it is also an indication on how long our arrays should be. The arrays that we will need are those for the ‘curPosX' and ‘curPosY'. These arrays are used for holding the mouse position. An array ‘size' will be used for holding the size of the circles, from largest to smallest.
A ‘for' statement is used to loop through the array indexes; starting from 0 until ‘i' is no longer smaller than ‘trail'. So the array index goes from 0 – 29, which gives us 30 places to hold information in each array. This ‘for' statement is mainly used to assign a starting value to the indexes in the array:
for (i = 0; i < trail; i += 1)
{
curPosX[i] = mouse_x;
curPosY[i] = mouse_y;
size[i] = radius - i / trail * radius * scale;
// create an array that decreases its value as it goes through its indexes
}
Now we need to assign the ‘index' variable that will hold the current position of largest circle in the goo cursor; this is also the main circle that all the other circles will trail behind.
index = 0;