Help making Scenes with a series of actions.

Started by
2 comments, last by Ghost Clock 11 years, 10 months ago
I hope this is in the right section and I apologize if it's not.

I am not a programmer by any professional definition but I have gotten myself fairly comfortable with the basics of C# and XNA over the last couple years and have actually managed to make a few amateur games on my own that I'm actually fairly proud of, each with a few moments of coding that "hey, that might just be how a professional would do this!"

Unforutanetly, with my latest project I've hit a bit of a stump and I'm having trouble not only figuring out the best way to do what I want but putting it into words that I can look up.

So here's what I want to do in lousy English. I have a class, let's call it "Scene" and it has an Update method that gets called every frame through the Game class Update (XNA terminologies, if not other). In my previous games, this would just be handing over control of my PlayerCharacter instance to the player and act out any AI for any Enemies or Helpers. This game though I have stories and acting or "cutscenes", I suppose, and I sometimes I need the game to play out these scenes before giving control back to the player. So as an example in English, at each Update call the following steps would be played out by performing a series of functions, checking if requirements are satisfied to end the step on this call and then move to the next step for the next Update call when finished.

Step 1: Move player and another character to designated spots.

Step 2: Active a talk scene or anything else.

Step 3: Give default control to Player and AI.

I have found finding any simple examples or tutorials of how to do this to be a harder task than I would have thought. I have to admit now that while I am getting better, I have a hard time following the logic of larger projects that I didn't write myself. This doesn't seem like it should be such a complicated thing on the other hand, so I'm hoping I'm just not seeing the obvious.

The two things I have tried thus far are not very eloquent. First, I thought switch statements with an Act int variable. As an example

Case 1: { p1Character.Move(destination); if (p1Character.Position == destination) {Act = 2} break;};

Of course, this would get really messy if I put in all the logic into one class. So my idea was to have an abstract Scene class and derive from that classes that would each override the Update method with their own switch statements. This didn't seem like a very good solution either and would still become hard to manage with so many classes, each for just one scene. Doesn't seem like how it would be done on a professional level at all, I assume not.

The next idea was to load instructions from a file. This way I would have just one scene class that could load a variety of custom content files. This would be nice as well because it would allow me or others to easily add content to the game even after its released. This seems like to way to go but the problem is I really don't know how to do this well either. My first attempt was creating a StageDirection class that could call a variety of different methods like .MoveCharacter() based on what a string says to do.

When an instruction file would load, it would add a StageDirection to a list with each string in the file. Then my Scene.Update() would call each active StageDirection in the List. I fiddled around with this and it does work but once again I can see this becoming a real mess. Making the StageDirection class accepting so many different stated instructions feels like I'm making a whole new language just to talk to my computer language, which I have not even mastered. Maybe this is what will be necessary but after working on this for just a couple days, I realized I missed just writting switch statements.

So here's what I need to know. Is there a better way to do what I'm wanting to do that has flown over my head? How do real games execute these kind of "cutscenes" inside an update loop? Are they typically coded into the executable like my inherited class idea or more like my instruction file idea? Neither? Is there a coding concept I'm just not familiar with at this level? Help me out if you can. Examples are good if there's a more simple answer, I typically work this kind of thing out with a console application and an infinite while loop to simulate an XNA update. If there isn't a simple answer, I could be pointed to some reading material. Thanks in advance.
Advertisement

The next idea was to load instructions from a file. This way I would have just one scene class that could load a variety of custom content files. This would be nice as well because it would allow me or others to easily add content to the game even after its released. This seems like to way to go but the problem is I really don't know how to do this well either. My first attempt was creating a StageDirection class that could call a variety of different methods like .MoveCharacter() based on what a string says to do.

Congratulations, you have just discovered the essence of scripting.
To be more clear, you're talking about writing your own scripting language. And yes, as far as I can tell professionals handle cutscenes via scripting. Your giant switch statement is probably the simplest way to think of it conceptually.
I'll start reading into scripting and see what's been done before me, I'm sure there are much better examples of how to do this better than my own flying blind attempts to do this from scratch.

This topic is closed to new replies.

Advertisement