6 Replies - 1802 Views - Last Post: 17 November 2012 - 09:07 AM

#1 !cpm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-October 12

Game states and level selection

Posted 03 November 2012 - 04:30 AM

Hey all!

This is more a question of theory than actual programming help. I have been following the tutorial on game states on this website http://xnagpa.net/xnatutorials.phpI understand the author of this website also is a member here on the forums, so if you are reading, I would like to thank you! I had been struggling with understanding game states for a while, and this tutorial cleared a lot of things up for me., and was wondering how - using this system - would I go about implementing some sort of level selection system?

The main question I have is this: As the game is operating using alternating game states, would each of the levels implemented into the game be stored in it's own game state. For example: Each of the levels in my current project have a camera class, a player, and a map. The way I currently have it set up is by having levels selected using an enum, and in the Update and Draw methods ect... I have a switch statement to see which level the user selected to play. This however, seems very inefficient to me, now that I have a slightly better understanding of how game states work.

So to sum it up - Would each of the levels have their own game state?

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Game states and level selection

#2 LiberLogic969  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 34
  • View blog
  • Posts: 85
  • Joined: 03-September 12

Re: Game states and level selection

Posted 03 November 2012 - 06:48 AM

Usually there would be a generic "GamePlayState" which handles the current Level/Map object and all the systems needed for game play. I think it would be overkill the make a new state per Level, unless each of your levels has a dramaticly different style of game play or some serious "special cases".
Was This Post Helpful? 0
  • +
  • -

#3 !cpm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-October 12

Re: Game states and level selection

Posted 03 November 2012 - 07:26 AM

Could you offer a suggestion as to what would be the best way to implement this?
Was This Post Helpful? 0
  • +
  • -

#4 LiberLogic969  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 34
  • View blog
  • Posts: 85
  • Joined: 03-September 12

Re: Game states and level selection

Posted 03 November 2012 - 09:23 AM

I think there are many acceptable ways to go about it, it really depends on how you've set things up so far. The way I would do it is create a state that handles selecting a level to play. When the player selects a level it will push on a LoadingState which loads all the assets and creates all entities/objects for the selected level and passes the data along to the GamePlayState. The GamePlayState will handle the logic for the actual game play, most likely by calling Update and Draw on seperate manager classes; You should also check out the GameScreen Manager sample on the XNA website. That sample has helped me alot.

Hope that helps. If you need any more tips just ask!
Was This Post Helpful? 0
  • +
  • -

#5 !cpm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-October 12

Re: Game states and level selection

Posted 04 November 2012 - 01:34 AM

Well, sadly I don't have the luxury of time to do a whole ton of research on that. I only have a few days to implement this system. And any problems I encounter down the line with your method could prove costly :(

I was thinking however, of just completely bypassing a loading screen and instead just having maybe a property in the level select screen that will pass a value to a variable in the GamePlayState screen? As all screens in the game are handled in the Game1.cs file, this should be relatively easy enough to implement to serve as a short-time fix to the problem.

I can of course consider implementing a more efficient system further down the line..

Do you think this would be good enough as a temporary solution to the problem?
Was This Post Helpful? 0
  • +
  • -

#6 LiberLogic969  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 34
  • View blog
  • Posts: 85
  • Joined: 03-September 12

Re: Game states and level selection

Posted 04 November 2012 - 05:31 AM

As long as its working it should be fine for a temporary solution!
Was This Post Helpful? 0
  • +
  • -

#7 snaynay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Game states and level selection

Posted 17 November 2012 - 09:07 AM

I would suggest looking into Screen managers down the line for future builds.

You could make a parent class (screen) that fetches all the relevant game data, and then create child classes that retrieve the level data and override any necessary mechanics.

That way all levels, menus and basically every "screen" could be a separate file, managed by a stack/queue in the game.cs...

I like to think of them as more modular finite state machines. ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1