Login | Register

Minimap

July 24, 2006, 13:06 by Calle
[loading]
-->
<div style="clear: both;">
mm_yu = 5 //This is the upper y position
mm_xl = 5 // This is leftmost position
mm_yd = 105 //The second y position
mm_xr = 105 //right x position

//Which objects to draw
nr_obj = 3; //How many objects
obj_d[0] = object0;
obj_d[1] = object1;
obj_d[2] = object2;
obj_d[3] = object3;

//In which color - use the index number of the array above
obj_c[0] = c_blue;
obj_c[1] = c_red;
obj_c[2] = c_gray;
obj_c[3] = c_lime

</div>

The script above should be called suggestively in the create event as an initialization of all the variables. As you can see there are two arrays (rather than one two-dimensional) that keeps information about which objects to draw and in what colour. It would also be possible to create a third array which could keep information about other stuff, such that if you want to draw a specific sprite or so for specific objects.

i = 0;
d = 0;
draw_background_stretched(background_index,mm_xl,mm_yu,
mm_xr-mm_xl,mm_yd-mm_yu);
while(i<instance_number(obj_d[d])) {
//Selecting information
x_id = (instance_find(obj_d[d],i).x/room_width)*92;
y_id = (instance_find(obj_d[d],i).y/room_height)*92;


draw_point_color(mm_xl+x_id,mm_yu+y_id,obj_c[d]);

i +=1;
if (i==instance_number(obj_d[d])) {
d += 1;
i = 0;
}

}


Draw background strectched, background index, that gives a cool kind of feeling. Especially if you got a cool background, imagine a battlefield for an example; it gives a kind of map feeling. Although if you rather would like a one-colour background you might just delete that piece of code, maybe replace it with a rectangle.

The condition of that first while statement might be confusing since it only seems to run through one array of obj_d, but as you can see later in the code it changes to d+1 and i is reset. That’s like placing the while loop inside another while loop which would say while(d<nr_obj), it’s the same thing.

And finally, as you can see, I am using draw_point for drawing, this is highly selectable. You might change it anyway you like!

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games