Game design

This is not specifically about C++, but I thought it would be OK to post it here.

I was planning to make a game, a 2D RPG hopefully, but I ran into some design problems. Say, I'm making a map with two houses in it, how would I handle events in each house? Every house would have different items in it, therefore different events. I'm implementing a state machine, and I thought making a state for every house or place would be a really stupid idea. How would you handle events when you have numerous maps and numerous buildings in it, without making the code cluttered with nested ifs and loops?
Last edited on
Off-topic - this might be interesting for you: http://mu.ranter.net/design-theory
On-topic - Probably using states. You can read this: http://gameprogrammingpatterns.com/
There are many programming patterns there described, with simple examples(unfortunately, I think that some of these examples might be not sufficient, as it's hard for beginner to use such pattern in real code, but you can still try it). Probably there's an answer waiting for you out there, and even if not, some of these patterns are nice to know.

Cheers!:)
The way I did it was only possible because I had a tile-based system. I just have a 2D vector of tiles, which each contained pointers to a polymorphic class of events. Calling the events 'doAction()' function returns a std::queue of function pointers. The main world handler then calls these functions, allowing for the events to be performed. Then, when making the map (e.g. from a file), you simply add derived classes from the base class to the tiles, which (for example) print text on the screen as if talking to the player.
closed account (N36fSL3A)
If you want I have code for a 2D RPG I wrote last year. Really badly coded (and I think I was in the middle of adding layer support, so it may or may not be directly compile-able), but still a good resource to have.
Topic archived. No new replies allowed.