Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How do I restart the game once the end game screen appears?

Author
Message
Ashley Leppington
11
Years of Service
User Offline
Joined: 1st Mar 2014
Location:
Posted: 1st Apr 2014 12:52
Hello everybody.

I have a piece of code which ends the game when all the objects in the game are collected. The end screen appears and when the user presses backspace the game ends. I just need to know how to restart the game when this end screen appears.



I put


I put the code above before the "if keystate(14) = 1 then end". The game worked but when I pressed R the game did not restart. Do I need to put the code to restart the game outside of the function which displays the end screen and ends the game?

I appreciate all answers and help
Many Thanks

Ashley Leppington
wattywatts
15
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 1st Apr 2014 16:40
I'd personally make a gosub near the beginning of my program and hop to that, but maybe someone has a better way.
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 1st Apr 2014 22:54 Edited at: 1st Apr 2014 22:58
This is a case of structuring your code to deal with looping back to the start of the game. This was something I initially struggled with when I first started making games, as I was just trying to sort the game play out, but is now something I code at the very beginning, putting in all the various sub-routines and functions to deal with menus, loading and deleting media as appropriate, playing the game and the game over state (win or lose).



The code above just shows the basic over view of the program structure from one of my games, a simple racer. The variable "game_state" controls when to move on to the next stage of the program. So in the main menu loop, there'll be a condition looking for game_state = game_play in order to exit the menu.

One thing you have to remember is to reset any flags or values that changed over the course of the game. It might that there's something in you program that needs to be reset in order for the game to run properly.

Decision you have to make are whether you want to the player to go through the main menu to replay the game or if you want to just reset the level. Whether you want to delete and reload menu media separately from the game media (as in the above example) or if you want to just load everything on and leave it alone.

You might want to add in something that deletes any "residual" media when the player quits the game.

Whether you use subroutines or functions makes no different to the basic order of things. I just prefer subroutines.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Apr 2014 00:45
Quote: "I pressed R the game did not restart"


That's because you told it to end.



If you don't want your program to end then tell it to do something else.



Powered by Free Banners
tiffer
19
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Scotland
Posted: 2nd Apr 2014 10:55
There's no single command for restarting a game so it would depend on how your game works? Presuming your game runs around a main loop (as it should) then you would write a function that put everything back to the way it was when the game started. Think about a board game you might have played. If you wanted to start a new game you could simply wipe the score board clean and put all the peices back to the start. It's effectively the same idea. set any variables you're using to 0 and then reposition everything where it was.

Login to post a reply

Server time is: 2025-05-15 20:15:13
Your offset time is: 2025-05-15 20:15:13