[C# XNA] Stroy Lines and Programming

Started by
1 comment, last by Dr_Asik 14 years, 7 months ago
Hi there. So, I've been playing my old Pokemon Games recently and I have had a revelation about my games. So far with XNA I can draw a tile map, add a player Sprite, control his movement create a vast 2D world with collision detection etc. I can also use IO to create a sort of NPC script system (all thinks to) [Link] However, I realise So far all my logic goes into this one Update() method and it simpaly checks using loads of If Statements to tell it what to do. The Problem: Storylines ...... so, when a rival NPC appears and attacks you, when your enemies have a plan to foil, etc. My Question: How do you control this feature? I could hardcore it. but that would leave me with 10000 of lines of code. or is this the only way? any help is appreciated ... Andy^ :)
Advertisement
This is what I THINK you mean, and what my solution is to that:

If you're referring to interactive conversations with enemies... I think it's better to have a spirit of soft-coding every aspect of the conversation, and designing everything using text files, or a tool of some sort.

I tend to hard-code when I don't have a lot of content to include in game. But when the content represents an possibly large dataset, I think it's good idea to think about implementing a lighter way to add content to the game.
You need to split your code into many small subroutines that all do a specific task, instead of having one giant subroutine that does everything with if statements. The XNA Framework gives you some examples of that: when you create a game, there is a method for Initializing, Loading assets, Drawing, Updating logic, etc. They didn't throw everything in one method; each method has one specific purpose.

That's the most basic skill to acquire when you want to write a program that requires many lines of code. Divide and conquer by splitting the logic into small subroutines that do one specific task, in a few lines of code.

At some point it can get confusing to have a large number of methods that can all access the same data members. This is where object-oriented programming comes in, allowing you to divide methods and their related data into objects with well-defined responsibilities.

As for the story aspects of your game, you have to separate data from code. All the dialogs, item descriptions and statistics, quests, maps, etc., have to be in separate files such as .txt or .xml, so that you can easily extend your game by adding new data instead of hard-coding everything.

This topic is closed to new replies.

Advertisement