A
alexanderarts
Guest
I'm just starting out with Game Maker so I am using tutorials to learn how to do everything.
I've managed to make a simple Yes/No pop-up menu that comes up in my game. It's designed for planets on a solar system map. When the player runs into a planet the planet creates an instance of this menu and gets info from it's creator instance so that it knows the planet's name and what map it's associated with. When the player hits Yes it should take them to the orbit room. If the player hits No the spaceship should be lightly pushed away from the planet. I've gotten both options to work, but not correctly.
I want the Yes and No options to both be selectable with the accept_key but also have a cancel_key that switches to No when on the Yes case and selects No when on the No case. Currently the accept key just does the Yes option no matter where it is and the cancel_key always does the No option.
I feel like the other stuff I've managed to do is so much more complicated, but I really can't figure out where I messed this one up. If anyone can see where I went wrong, please point it out to me! Thanks!!!
Here's the code:
CREATE:
///initialize the menu
creator = noone;
ALARM 0:
///menu alarm
STEP:
///control the menu
if (alarm[0] <= 0) {
if (obj_get_input.down_key) {
if (menu_index < array_length_1d(option)-1) {
menu_index +=1;
} else {
menu_index = 0;
}
alarm[0] = room_speed/3;
}
if (obj_get_input.up_key) {
if (menu_index > 0) {
menu_index -=1;
} else {
menu_index = array_length_1d(option)-1;
}
alarm[0] = room_speed/3;
}
if (obj_get_input.accept_key) {
switch (menu_index) {
case 0:
room_goto(creator.planet_scan_room);
break;
case 1:
obj_player_explorer.explorer_control = true;
obj_player_explorer.direction +=180;
obj_player_explorer.speed = 0.05;
obj_planet_parent.alarm[0] = 100;
instance_destroy();
break;
default:
break;
}
}
if (obj_get_input.cancel_key) {
switch (menu_index) {
case 0:
menu_index +=1;
alarm[0] = room_speed/3;
break;
case 1:
obj_player_explorer.explorer_control = true;
obj_player_explorer.direction +=180;
obj_player_explorer.speed = 0.05;
obj_planet_parent.alarm[0] = 100;
instance_destroy();
break;
default:
break;
}
}
}
USER DEFINED 0:
///event user 0
//make sure "creator" is set
creator = creator
//create menu
title = "Enter orbit around " +string(creator.planet_name) + "?";
option[0] = "Yes";
option[1] = "No";
//menu index
menu_index = 0;
DRAW GUI:
///draw the orbit menu text
draw_self();
var xx = display_get_gui_width()/2;
var yy = display_get_gui_height()/2;
draw_set_halign(fa_center);
draw_text(xx, yy-64, title);
//loop through array
for (var i=0; i<=array_length_1d(option)-1; i++) {
draw_set_color(c_gray);
if (i == menu_index) {
draw_set_colour(c_white);
}
//draw text relative to each other
draw_text(xx, yy+ (i*32), option);
}
//set color and h align back
draw_set_color(c_white);
draw_set_halign(fa_left);
I've managed to make a simple Yes/No pop-up menu that comes up in my game. It's designed for planets on a solar system map. When the player runs into a planet the planet creates an instance of this menu and gets info from it's creator instance so that it knows the planet's name and what map it's associated with. When the player hits Yes it should take them to the orbit room. If the player hits No the spaceship should be lightly pushed away from the planet. I've gotten both options to work, but not correctly.
I want the Yes and No options to both be selectable with the accept_key but also have a cancel_key that switches to No when on the Yes case and selects No when on the No case. Currently the accept key just does the Yes option no matter where it is and the cancel_key always does the No option.
I feel like the other stuff I've managed to do is so much more complicated, but I really can't figure out where I messed this one up. If anyone can see where I went wrong, please point it out to me! Thanks!!!
Here's the code:
CREATE:
///initialize the menu
creator = noone;
ALARM 0:
///menu alarm
STEP:
///control the menu
if (alarm[0] <= 0) {
if (obj_get_input.down_key) {
if (menu_index < array_length_1d(option)-1) {
menu_index +=1;
} else {
menu_index = 0;
}
alarm[0] = room_speed/3;
}
if (obj_get_input.up_key) {
if (menu_index > 0) {
menu_index -=1;
} else {
menu_index = array_length_1d(option)-1;
}
alarm[0] = room_speed/3;
}
if (obj_get_input.accept_key) {
switch (menu_index) {
case 0:
room_goto(creator.planet_scan_room);
break;
case 1:
obj_player_explorer.explorer_control = true;
obj_player_explorer.direction +=180;
obj_player_explorer.speed = 0.05;
obj_planet_parent.alarm[0] = 100;
instance_destroy();
break;
default:
break;
}
}
if (obj_get_input.cancel_key) {
switch (menu_index) {
case 0:
menu_index +=1;
alarm[0] = room_speed/3;
break;
case 1:
obj_player_explorer.explorer_control = true;
obj_player_explorer.direction +=180;
obj_player_explorer.speed = 0.05;
obj_planet_parent.alarm[0] = 100;
instance_destroy();
break;
default:
break;
}
}
}
USER DEFINED 0:
///event user 0
//make sure "creator" is set
creator = creator
//create menu
title = "Enter orbit around " +string(creator.planet_name) + "?";
option[0] = "Yes";
option[1] = "No";
//menu index
menu_index = 0;
DRAW GUI:
///draw the orbit menu text
draw_self();
var xx = display_get_gui_width()/2;
var yy = display_get_gui_height()/2;
draw_set_halign(fa_center);
draw_text(xx, yy-64, title);
//loop through array
for (var i=0; i<=array_length_1d(option)-1; i++) {
draw_set_color(c_gray);
if (i == menu_index) {
draw_set_colour(c_white);
}
//draw text relative to each other
draw_text(xx, yy+ (i*32), option);
}
//set color and h align back
draw_set_color(c_white);
draw_set_halign(fa_left);
Attachments
-
66.5 KB Views: 8