G
Grimbel
Guest
Hello everyone,
I am very new in Game Maker: Studio and my programming skills are still very limited, but I am working very hard in my project and I hope to see it finished some day. It is first time I ask for help, and I hope this community can help me. My problem is the one below:
I have followed a YouTube tutorial in order to make a Zelda style hearts system. The video is designed in a way that every heart is divided in 2 halves, but I want to divide it in 4 quarters instead. I thought it would be easy to adapt, but not at all! Here it is the exact minute (14:40) where the author of the tutorial explains the code:
I think the problem could be easily solved if the code in two small sections below was the right one, but I don't know what to write or how to do it, so I ask for your help.
Here is the complete page:
Thank you very much in advance for helping, and I hope I can learn something from this.
I am very new in Game Maker: Studio and my programming skills are still very limited, but I am working very hard in my project and I hope to see it finished some day. It is first time I ask for help, and I hope this community can help me. My problem is the one below:
I have followed a YouTube tutorial in order to make a Zelda style hearts system. The video is designed in a way that every heart is divided in 2 halves, but I want to divide it in 4 quarters instead. I thought it would be easy to adapt, but not at all! Here it is the exact minute (14:40) where the author of the tutorial explains the code:
I think the problem could be easily solved if the code in two small sections below was the right one, but I don't know what to write or how to do it, so I ask for your help.
Code:
// draw two quarters heart
repeat(floor(obj_player_stats.hp/4) + frac(obj_player_stats.hp/1) * 1) {
if(x_two_quarters == 26 * 10) {
y_two_quarters = 26;
x_two_quarters = 0;
}
draw_sprite(spr_heart_life_2, 0, xx + x_two_quarters, yy + y_two_quarters);
x_two_quarters += 26;
}
// draw three quarters heart
repeat(floor(obj_player_stats.hp/4) + frac(obj_player_stats.hp/1) * 1) {
if(x_three_quarters == 26 * 10) {
y_three_quarters = 26;
x_three_quarters = 0;
}
Code:
/// Draw the stats
var width = display_get_gui_width();
var xx = width - 26 * 6;
var yy = 32;
var x_zero_quarters = 0;
var y_zero_quarters = 0;
var x_one_quarters = 0;
var y_one_quarters = 0;
var x_two_quarters = 0;
var y_two_quarters = 0;
var x_three_quarters = 0;
var y_three_quarters = 0;
var x_four_quarters = 0;
var y_four_quarters = 0;
obj_player_stats.maxhp = clamp(obj_player_stats.maxhp, 12, 24);
obj_player_stats.hp = clamp(obj_player_stats.hp, 0, obj_player_stats.maxhp);
//draw text
draw_set_colour(c_white);
draw_text(width - 26 * 10 / 2, 0, "-Life-");
draw_set_halign(fa_center);
// draw empty heart
repeat(obj_player_stats.maxhp/4) {
if(x_zero_quarters == 26 * 10) {
y_zero_quarters = 26;
x_zero_quarters = 0;
}
draw_sprite(spr_heart_life_0, 0, xx + x_zero_quarters, yy + y_zero_quarters);
x_zero_quarters += 26;
}
// draw one quarter heart
repeat(floor(obj_player_stats.hp/4) + frac(obj_player_stats.hp/4) * 4) {
if(x_one_quarters == 26 * 10) {
y_one_quarters = 26;
x_one_quarters = 0;
}
draw_sprite(spr_heart_life_1, 0, xx + x_one_quarters, yy + y_one_quarters);
x_one_quarters += 26;
}
// draw two quarters heart
repeat(floor(obj_player_stats.hp/4) + frac(obj_player_stats.hp/1) * 1) {
if(x_two_quarters == 26 * 10) {
y_two_quarters = 26;
x_two_quarters = 0;
}
draw_sprite(spr_heart_life_2, 0, xx + x_two_quarters, yy + y_two_quarters);
x_two_quarters += 26;
}
// draw three quarters heart
repeat(floor(obj_player_stats.hp/4) + frac(obj_player_stats.hp/1) * 1) {
if(x_three_quarters == 26 * 10) {
y_three_quarters = 26;
x_three_quarters = 0;
}
draw_sprite(spr_heart_life_3, 0, xx + x_three_quarters, yy + y_three_quarters);
x_three_quarters += 26;
}
// draw four quarters heart
repeat(floor(obj_player_stats.hp/4)) {
if(x_four_quarters >= 26 * 10) {
y_four_quarters = 26;
x_four_quarters = 0;
}
draw_sprite(spr_heart_life_4, 0, xx + x_four_quarters, yy + y_four_quarters);
x_four_quarters += 26;
}
Last edited by a moderator: