A
Anti-Icarus
Guest
I'm trying to implement a game over screen in a prototype I was working on. I intend to have my game to have a level structure that would have two interconnected rooms per level which I refer to here as rm_House_of_Worship and rm_field. I want it so that a game over screen is displayed when a character dies and then presents the player a choice to either try again or quit and go back to the main menu (rm_front_end, in this case). Using one of the YouTube tutorial videos done by Making Games 101 as reference material, I created an object appropriately called obj_gameover. So far, it's not working in the way I intended. Here's what I've done so far:
I included a step event in the main controller object (obj_controller) that contains the following code:
Next, I made sure that all of my game objects had a Draw event that at least contains the line of code called draw_self(). Then, I structured obj_gameover with the following blocks of code in the Create event:
The Step event:
The Draw event:
And the Draw GUI event:
During my few tests, I've been encountering a problem in which when the instance of the player object (obj_Savior) gets destroyed in rm_field, I merely go back to rm_House_of_Worship, the room that I would start in. While a few variables get reset to zero, the game became basically broken with text displayed by obj_controller and by another object upon being touched by the player pushed to the left side of the screen.
The game I've been trying to create is something along the lines of Gauntlet, a classic arcade game from the 1980s, in which you run around a field (hence rm_field) to collect relic pieces and bring back to a house of worship (hence rm_House_of_Worship) as fast as possible while also fighting and avoiding hordes of demons. I want to give the player the option to try again by resetting the the two rooms to what they were before the game started; I want the instances of the relic pieces to be reset to the state they were in before the player collected them in the first place (and keep the placement of the in-game text intact, of course). I'm not sure how expand upon my obj_gameover as it is in order to make that possible. It is also true that I may have done something wrong with the code itself and I'm just not sure where the error lies in as of yet. Any advice would be greatly appreciated.
I included a step event in the main controller object (obj_controller) that contains the following code:
Code:
///Creates game over object upon player death
if !instance_exists(obj_Savior) {
instance_create(x, y, obj_gameover);
}
Code:
///Creates the game over screen
pauseSurf = surface_create(view_xview[0], view_hview[0]);
surface_set_target(pauseSurf);
draw_clear_alpha(c_black, 0);
with (all) {
if (visible == true) {
x = x-view_xview[0];
y = y-view_yview[0];
event_perform(ev_draw, 0);
x = x+view_xview[0];
y = y+view_yview[0];
}
}
surface_reset_target();
instance_deactivate_all(true);
visible = true;
Code:
///Displays options that would destroy the game over instance
//Sets choice to restart or end the game
if keyboard_check_pressed('y') {
score = 0;
global.relicCollection = 0;
room_goto(rm_House_of_Worship);
instance_create(512, 384, obj_Savior);
}
else if keyboard_check_pressed('n')
room_goto(rm_front_end);
//Destroys the game over screen
if (keyboard_check_pressed('y') || keyboard_check_pressed('n')) {
surface_free(pauseSurf);
instance_activate_all();
instance_destroy();
}
Code:
///Draws the game over screen
if (surface_exists(pauseSurf)) {
draw_surface(pauseSurf, view_xview[0], view_yview[0]);
}
draw_set_color(c_black);
draw_set_alpha(0.5);
draw_rectangle(view_xview[0], view_yview[0], view_xview[0]+view_wview[0], view_yview[0]+view_hview[0], 0);
draw_set_alpha(1);
Code:
///Writes game over screen text
draw_set_color(c_red);
draw_set_halign(fa_center);
draw_set_valign(fa_center);
draw_text(view_wview[0]/2, view_hview[0]/2, "You have failed. Try again?");
draw_text(view_wview[0]/2, view_hview[0]/2 + 30, "Y/N");
The game I've been trying to create is something along the lines of Gauntlet, a classic arcade game from the 1980s, in which you run around a field (hence rm_field) to collect relic pieces and bring back to a house of worship (hence rm_House_of_Worship) as fast as possible while also fighting and avoiding hordes of demons. I want to give the player the option to try again by resetting the the two rooms to what they were before the game started; I want the instances of the relic pieces to be reset to the state they were in before the player collected them in the first place (and keep the placement of the in-game text intact, of course). I'm not sure how expand upon my obj_gameover as it is in order to make that possible. It is also true that I may have done something wrong with the code itself and I'm just not sure where the error lies in as of yet. Any advice would be greatly appreciated.