• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Creating a Game Over Screen

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:

Code:
///Creates game over object upon player death

if !instance_exists(obj_Savior) {
    instance_create(x, y, obj_gameover);   
}
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:

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;
The Step event:

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();
}
The Draw event:

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);
And the Draw GUI event:

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");
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.
 

Xer0botXer0

Senpai
Is your game over object set to persistent because you are changing rooms before it finishes its code.

I also don't see you defining a height and width for your surface.
 
A

Anti-Icarus

Guest
Is your game over object set to persistent because you are changing rooms before it finishes its code.

I also don't see you defining a height and width for your surface.
I tried setting obj_gameover to persistent, but it didn't make much difference other than having my enemy spawn objects retain their positions.

I'm pretty certain that I have the height and width of the game over surface defined in my game over object's Draw and Draw GUI events. Should that have been done in its Create event? (Speaking of which, I found a slight typo at the beginning of the create event: pauseSurf = surface_create(view_xview[0], view_hview[0]). I corrected it so that it would look like this: pauseSurf = surface_create(view_xview[0], view_hview[0]))

I've made a bit of progress by altering a bit of code in my player object (obj_Savior) that checks its health. I managed to create the game over screen if only for a nanosecond before immediately going into the rm_House_of_Worship.
 

samspade

Member
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:

Code:
///Creates game over object upon player death

if !instance_exists(obj_Savior) {
    instance_create(x, y, obj_gameover); 
}
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:

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;
The Step event:

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();
}
The Draw event:

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);
And the Draw GUI event:

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");
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 could be wrong, but this seems like a lot more work than necessary for what you want to accomplish. Though I might have misunderstood what you're going for. I would simply create a new room called rm_game_over. Draw everything in that room and put everything in that room. For example, create an object (obj_level) which you either make persistent or include in all relevant rooms with the following code:

Code:
///obj_level create event
global.game_over = false;

///obj_level step event
if (whatever you want here happens) global.game_over = true;

if (global.game_over == true) {
    room_goto(rm_game_over);
    global.game_over = false;
}
Then in rm_game_over put the following object

Code:
///game_over draw gui event

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");

///game_over step event

if (keyboard_check_pressed(ord('Y')) {
    score = 0;
    global.relicCollection = 0;
    room_goto(rm_House_of_Worship);
    instance_create(512, 384, obj_Savior);    
} else if (keyboard_check_pressed(ord('N')) {
    room_goto(rm_front_end);
}
 
A

arirish

Guest
Gauntlet, eh? The way you describe it reminded me a lot of ActRaiser, from the same era. Which is cool, because I'd forgotten about it, and now I'm going to track it down and go play it.
 
A

Anti-Icarus

Guest
I could be wrong, but this seems like a lot more work than necessary for what you want to accomplish. Though I might have misunderstood what you're going for. I would simply create a new room called rm_game_over. Draw everything in that room and put everything in that room. For example, create an object (obj_level) which you either make persistent or include in all relevant rooms with the following code:

Code:
///obj_level create event
global.game_over = false;

///obj_level step event
if (whatever you want here happens) global.game_over = true;

if (global.game_over == true) {
    room_goto(rm_game_over);
    global.game_over = false;
}
Then in rm_game_over put the following object

Code:
///game_over draw gui event

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");

///game_over step event

if (keyboard_check_pressed(ord('Y')) {
    score = 0;
    global.relicCollection = 0;
    room_goto(rm_House_of_Worship);
    instance_create(512, 384, obj_Savior);   
} else if (keyboard_check_pressed(ord('N')) {
    room_goto(rm_front_end);
}
Before going further, I think it's time to demonstrate the direction I've been taking this game in a video I have just recorded and uploaded to YouTube:


Now when I attempted to implement the methods suggested to me above, I ended up with a bizarre glitch that causes the game to just freeze rather than going over to rm_gameover and (upon pressing 'y') going to rm_House_of_Worship, creating multiple instances of obj_Savior and more when moving in the room. I'll let the next video speak for itself.


By drawing and putting everything in rm_gameover, did you mean ALL of the instances in the room and putting them in rm_gameover upon the player's demise?
 
Top