I am developing a 2D top-down post-apocalyptic shooter and would like there to be a storyline. I have no experience with this and have no clue how to do it...

I would like there to be a primary storyline and then some secondary missions, but how do I keep track of where the player is in the story. What functions do I have to add to my code...? Should I have a different class for the storyline and have a bunch of IFs to see if the player meets the required standards to start the mission? and an int for the mission he is currently in?

Sounds like you need to think of some sort of quest system, and mark some of them as [Story] Quests. this will allow you to have requirments too, so you cant do quest B untill Quest A has been completed, or Quest C requires Quest B to have been completed using The Good Choice. etc.

Should I have a different class for the storyline and have a bunch of IFs to see if the player meets the required standards to start the mission? and an int for the mission he is currently in?

I don't know, did you actually try that idea? Sounds like a possible route...

More importantly:

Stop asking "Should". You will only learn if you TRY your ideas out. Come up with horrible, crappy ideas, implement them, see how crappy they are, and try something else. Eventually they start becoming good ideas.

Bam. Experience and wisdom.

It's how we all got to where we are right now. I've scrapped my entire codebase on projects multiple times because the architecture idea I had was utterly brittle and useless in practice. Each time I had the experience and understanding of why the last idea didn't work to build off of, and the code just keeps getting better as I refactor and rebuild.

You only appreciate "best practice" design once you've tried to put it together yourself in a worse fashion.

A story is a sequence of events happening in the view (to be understood in a wider sense) of the player. To ensure that the player notices the events, they are usually not running detached but being enabled by requirements on the world state, and perhaps being triggered by the player. During happening and at its end, an event often alters the world state, so being able to enable or disable other (not yet happened) events. This way a sequence or even branches can be defined.

The world state is the entirety of variables describing, err, the state in which the game world is. E.g. a boolean flag for the life/death of an opponent belonging to the story, a counter for how often the player has hit a target, a flag whether or not a specific NPC has told the player about the hidden secret, ... whatever.

Events are enabled when their requirements on the world state are satisfied. E.g. if the flag meaning "opponent A is shot to death" is cleared and the counter for "rings of the bell" has reached 12 and the flag for "colliding with the proximity volume close to opponent A" is set, then let opponent A throw an offense against the player.

Triggers can be any action a player is able to perform. Colliding with a collision volume can be used as a location based trigger, or the death by shot of an NPC can be a trigger. On the other hand, the expiration of a timer can be a trigger, too, e.g. allowing for deferred events. Triggers can be implemented as a mechanism which alters the world state.

The player usually needs be hinted at how to trigger enabled events, or else s/he may not realize what to do next. How to do this depends on the type and style of the game. Briefings, books, journals, gossip, talks, ... by NPCs, a companion, the HUD, ... and so on. This can also be implemented as events in the way described above.

There isn't necessarily the need to explicitly track the current chapter in the story. The world state already reflects this.

@andy474: I think you are forgetting that this forum is the "for begginers forum". Yes it is hard to interpret such a poorly elaborated answer.

@Bcullis: I know, I'ts just that I'm making the framework of my game still as my graphic designer hasn't caught up to me. I can't carry on the basics and I don't have a map yet. I'll try some methods, but I was just asking if there was a good accepted method to do this. Thanks for the advice though

@haegarr: Very good explanation, it kind of gives me an idea of what I need to implement into my game. I ill start having a class "World" with all these flags and simply have another class for the storyline that takes in a reference to the world and has a series of if statements an an int to keep track of the mission the player's in. Kind of like:

There's a difference between implementing someone else's design, and designing something yourself. The former still relies on programming ability, but the latter is where you will really GROW as a programmer. This is why a lot of "where do I begin" guides give people a suggested progression of certain game types, with the caveat that you should try and make it work yourself before looking at other people's solutions. Project Euler does this brilliantly: you can't see the solutions thread until you post a correct answer. And man can those be enlightening.

There are few problems in programming that can be solved with one standard answer. Programming is all about solving problems, and the solutions vary from problem to problem. Implementing story into your game is really probably one of the easier things to do. There is little advanced math or logic, the main issue is not really the implementation of your ideas, but coming up with what you want your story to be about. How in depth you want to go into story telling is up to you, and there are many different ways to go about it, which is why it is hard to pin point a logical standard solution.

Here are some examples that I can come up with for story implementations, just to get your mental juices flowing about how you may want to go about this:

Your story is about a zombie survivor out in the woods alone, moving from abandoned cabin to cabin, scrounging for food and ammunition. The zombies could strike at any minute, so you must work fast to be ready for an attack.

How do you do this in programming? Perhaps you have a list of the cabins(probably stored in an array, list, or in some sort of "level file"). The game interprets this data and virtually assembles the level around you. When you walk in the houses and you collect the items, it would remove from the inventory of the house in you "level file". Everything stored has an X and Y position and in your class that handles rendering it would recognize data from the file and interpret that to draw the objects in the house.

Perhaps if you want a story with less player determination, you could play a short animation at the beginning of the game that shows them their fate of eternal zombie battle unless they find the mad scientist that is controlling the minds of the poor undead. You could pick up clues scattered around the game that when touched, would pause your main loop and display an image file associated with that clue. Throughout the game, the player may have to make decisions that will either lead them to the scientist, or keep them battling the zombies. At the end of each "level" of battle, the decision would have to made (either physically in game or maybe in a GUI or something...) and the decision would either put them off track on some random level or bring them closer to the mad scientists lair. Think about how the levels are connected as a tree or a web, not the normal sequential approach.

I'm not expecting you to use either one of these stories, but I hope that gives some idea of how you might plan about things.

For both of these implementations, or anything you come up with, your going to want to use Object Oriented Programming(OOP).

This answer is probably more of the story writing side of things than the technical examples than you wanted, but in reality, it's important to think about what you want something to be, before you're already half way done with it and just sloppily piecing other people's code snips together. What you really need is not a technical answer from us, but a good cup of you favourite warm beverage, a lot of paper and pens, and some time to think about each system in your game, what it does, and how it interacts with the other systems to form a nice, well organized piece of computer art.

@haegarr: Very good explanation, it kind of gives me an idea of what I need to implement into my game. I ill start having a class "World" with all these flags and simply have another class for the storyline that takes in a reference to the world and has a series of if statements an an int to keep track of the mission the player's in. Kind of like:

That is a question of experience and of personal preference. Although it is a valid way (until reaching some complexity), I would not implement it that way. I prefer a data driven way with concentrated responsibility (a.k.a. sub-systems, or "services" as they are generally called in my engine).

A way in-between would be where the individual events of the story are stored each one into an own object. The (base) class of that objects would support handling the requirements (probably data driven), and the effects of the event onto the world state (probably data driven, too). They could be separated, combined, or shared in different structures where meaningful (e.g. list of past events, list of running events, list of deferred/pending events, lists of listeners, a spatial structure when depending on locations, ...).