dynadungeons icon indicating copy to clipboard operation
dynadungeons copied to clipboard

Gameover screen

Open akien-mga opened this issue 8 years ago • 9 comments

Should show and congratulate the winner, or a draw screen if it's there's no winner. Clicking it should send back to the main menu (at least until we implement multi-round games).

akien-mga avatar Jul 30 '15 11:07 akien-mga

or a draw screen if it's there's no winner

Would this mean that a round timer needs to be implemented? Or is it solely for both players dying at the same time / via the same bomb?

ghost avatar Sep 02 '15 02:09 ghost

I think both solutions could be implemented. Also, maybe should we use two layers for the screen : one with the background and one with the text (if there is a background)

ObaniGemini avatar Sep 02 '15 04:09 ObaniGemini

Need some input here. Clicking is mentioned as the dismiss action in the OP, but I see that there's a ui_accept input that already exists and seems to fit the bill just as well.

Should I: a) Go with ui_accept as is (Keyboard only) b) Create a new input action, assign left click to it, and use that as the dismiss action (Mouse only) c) Assign left_click to ui_accept and then go with that (Keyboard and Mouse)

ghost avatar Nov 29 '15 22:11 ghost

Just about finished this one by adding in a new process_deaths function, but can't for the life of me get around a small bug.

func process_deaths():
    var players = level.player_manager.get_children()
    var size = players.size()
    var alive = 0
    for player in players:
        if player.dead != true:
            alive = alive + 1
    if (alive == 0):
        gameover.get_node("Label").set_text("It's a draw!")
        gameover.show() # Does not accept input but other one does
    elif ((size - alive) == 1):
        var winner
        for player in players:
            if player.dead != true:
                gameover.get_node("Label").set_text("Player " + str(player.id) + " wins!")
        gameover.show()

For some reason the if (alive == 0): portion won't allow me to dismiss the gameover prompt (even when removing the elif below, in case it was interfering somehow), but the elif portion works fine.

Probably missing something obvious but just can't spot it. Any ideas?

ghost avatar Jan 03 '16 00:01 ghost

Are you running this from _fixed_process in the player script? It will get run at each frame for each player, so the gameover prompt will be shown over and over and over as long as alive is null.

Since this code chunk does not need anything from the current player, it should be moved in another script, maybe level.gd, or wherever it fits best.

akien-mga avatar Jan 03 '16 12:01 akien-mga

Yes, that's right, running it from _fixed_process. Then the code I added in previously chimes in so that the gameover prompt can be dismissed:

func process_gameover():
    if gameover.is_visible() and Input.is_action_pressed("ui_accept"):
        get_tree().change_scene_to(global.menu_scene)

I can dismiss the prompt fine when the elif portion runs (code from my previous comment) but not when the if portion above it runs.

Thanks for your response, though I'm still a bit confused. Do you know why the elif portion isn't affected? I would have expected it to react in the same way (gameover prompt being shown over and over) because as the difference between size and alive is 1 for multiple frames.

And yes, can move the code into level.gd. Had only left it in player.gd because the original snippet dealing with the winner was there. Will shift it over once I get it working properly.

ghost avatar Jan 04 '16 09:01 ghost

I'm not exactly sure why the elif runs only once when the if runs ad libitum, but at any rate it shows that using _fixed_process to show UI elements is not a good idea. _fixed_process should be reserved to gameplay elements that actually need to be refreshed at each frame, else it's a useless loss of resource - I haven't seen your full changes yet but it looks like it will process the gameover stuff at each frame for the whole game when it only needs to be processed when a player dies, at it is done in the current implementation IIRC.

Basically, you just need to catch the "Hey I'm dead!" event from a player, and send it over to whichever node will have the code to handle it - level.gd sounds like a good match. For example:

  • when the player dies, call something like level.handle_death(self)
  • in level.gd, add a handle_death(player) function that will check if this new death triggers a gameover condition
  • when yes, trigger the proper UI changes to accomodate after a winning player or a draw. To handle input, don't use _fixed_process but _input (set_process_input(true)).

A style comment: better use if !player.dead than if player.dead != true :)

akien-mga avatar Jan 04 '16 10:01 akien-mga

Thanks heaps, will give it a shot :)

ghost avatar Jan 04 '16 18:01 ghost