{"author_name":"Six","cat":"LD - Misc","comments":[{"author_name":"","time":"September 8, 2009 8:30 am","epoch":1252416600,"text":"This is all true, but if it comes down to the wire and I have the option of either polishing up my gameplay and adding sounds (as I did) or adding pre-game and post-game mensu, I&#8217;m going to go for polish every time. Most people are scrambling just to finish their gameplay in the last few minutes, and haven&#8217;t had time to even think about menus yet.","spam":"N"}],"epoch":1252388460,"likes":1,"metadata":{"p_key":"72448","p_author":"Six","p_authorkey":"1190","p_urlkey":"108270","p_title":"Adding an overall game flow loop","p_cat":"LD - Misc","p_event":"LD15","p_time":"1252388460","p_likes":"1","p_comments":"1","p_status":"UPD5","us_key":"1190","us_name":"Six","us_username":"six","event_start":"1251417600","event_key":"1","event_name":"LD15"},"text":"<p>In playing through people&#8217;s entries I found a lot of them just jump straight into the game and stop when you win or lose.\u00a0 This is a post intended to inform anyone who doesn&#8217;t know how, about a quick and dirty way to create a simple &#8216;start screen&#8217; -&gt; &#8216;game&#8217; -&gt; &#8216;end&#8217; -&gt; &#8216;reset&#8217; loop in thier game.\u00a0 I&#8217;ve no idea if there is a more &#8216;proper&#8217; way to do this, but this is quick, dirty, and works.\u00a0 There may be some differences depending on how your game is structured, but you can fit the idea to most.<\/p>\n <p><span id=\"more-10596\"><\/span><\/p>\n <p>First you will need to add one integer variable to tell the program what state the game is currently in (i.e. the start screen, the actual game etc.) called something like <em>&#8216;gameState&#8217;<\/em>.\u00a0 Initialize this to 1, corrisponding to the menu screen, so that when the game starts up it shows the menu. You&#8217;ll also want to pull out any specific initialization that needs to be done before the game starts into a separate method, not the image loading or any of that, just things like generating maps, reseting scores to 0 and the like.<\/p>\n <p>Now for the magic, wrap any parts that are involved with updating your game in great big &#8216;if elseif&#8217; statements checking the value of <em>&#8216;gameState<\/em>&#8216;.\u00a0 Leave the normal playing of the game stuff in <em>&#8216;gameState<em> == 2&#8242;<\/em><\/em>.\u00a0 Now, when at the menu (<em>gameState == 1<\/em>) draw whatever is needed for a main menu (instructions, keys, intro, etc.) and check for whatever causes the game to start (clicking a button or pressing a key) and when that happens call the game inialization stuff you pulled out earlier and set <em>&#8216;gameState = 2&#8217;<\/em>.\u00a0 In the actual game (<em>gameState == 2<\/em>), when checking for Win\/Lose conditions, when they occur (or after a button is pressed after they occur etc.) clean up anything that should be from the game and set <em>gameState<\/em> to 3 or 4 to go to win\/lose screens (or alternativly just back to 1 to jump back to the menu).\u00a0 If using a win lose screen make sure to have a point in them that will set <em>gameState back to 1, to put you back on the menu.<br \/>\n <\/em><\/p>\n <p>Using this simple idea it&#8217;s quick and easy to create game flow for your game.\u00a0 You can also have the nice aspect of being able to restart easily by calling the reinitialize method, or to even quit back to the menu from the game easily too.\u00a0 So please to the peoples out there, add game flow to your game.\u00a0 It ends up making the whole thing feel like a much more complete and rounded game experience, with only a few minutes work.<\/p>","time":"September 8th, 2009 12:41 am","title":"Adding an overall game flow loop"}