Thanks for this, because none of the game tutorials I've read (including a book) have touched on this.
Could you give an example of how this happens? How would I plug the code of the rules into the game logic temporarily?
Also, are we talking make an abstract class for Rules, and then make a specific class for each rule, and then having a line in the text file that tells the game to create an object for that specific class? I feel like since rules can get pretty specific, wouldn't this just lead to a bunch of rule objects, and if so is that okay?
I just can't wrap my head around how you could have could have conditions in a text file that are executed by the program. Should I just use something like Rhino or Beanshell? Though I'm not exactly sure how, it seems like maybe an external scripting language could solve this problem.
Also, what do you mean here?
Okay I get it now. Most game tutorials I've seen just put conditions and game logic for the game directly in the code, so encapsulating that into a Rule is kind of foreign to me, but I get it now.
I'm guessing that I basically do the same thing for Triggers/Game Events , right? Abstract class and then specific Trigger classes that do stuff? Or maybe by Rule you essentially mean Trigger/Game Event (not sure)..
For learning purposes, hard coding your rules isn't the worst thing initially if that's what it takes you to get things functional. Once you have things functional you can start thinking of ways to improve, otherwise you might get stuck trying to extrapolate too far out and never write code (happens to me).
In terms of real world stuff, the biggest thing to think about is "what is your data?".
Imagine you're making something like Super Mario, your data is:
1. Platform locations
2. Platform types
3. Enemy Spawn locations
4. Enemy types
5. Enemy point values
6. Power up locations
7. Check point locations
8. End point location
(among other things)
You can now start grouping these properties into objects, (ie an enemy has a position, a point value, a path type, a sprite etc). Then you can think of a way to encapsulate all these objects (maybe its an xml file, maybe is some kind of script) and your game knows how to load this "level" up, load up the objects inside of it when needed and keep track of their behaviors for their life time.
Sorry this might be a bit abstract or rambly. The basic point is that admittedly a lot of game programming tutorials are very bad at teaching you how to structure an engine but I think that's somewhat by design. They're about teaching you to solve some of the problems in creating an aspect of the game, and usually do so in the most direct (if ugly) way possible. As you gain more experience you'll better understand how to build cleaner, more reusable code.
How do you guys feel about comments? Can there be too much?
If there's a particularly messy line I can see myself adding like 3 lines of comments for it (say 15 words per line). Sure I try to write clear code but sometimes I hit a wall. I'm also not that smart so maybe just having a full explanation in English is better. But I don't know if this is okay to do.
I absolutely believe there can be too much. If your comment is either too long its emblematic of a lot of possible issues. I largely reserve comments for things that had to be done a specific way to solve some specific issue.
i.e.:
// This random special case is to prevent the game from crashing when the player picks the following heroes on () on level 35.
Also:
// You have to initialize X before Y otherwise it creates a race case. Maybe we should refactor this later?
Or:
// Yes this is ugly but Apple's stupid compiler doesn't follow normal logic
And sometimes:
// TODO: FUCK! FIX THIS AT SOME POINT WHEN ITS NOT FUCKING 4 AM AND I HAVE HAD ACTUAL SLEEP. THE PROBLEM IS PROBABLY RELATED TO blah blah blah BUT IVE HAD 2 HOURS OF SLEEP AND I CANT THINK STRAIGHT.
I try to make my code and comments useful to whatever poor soul will likely have to build on top of the project at some later date because I hate when I take over for someone else and spend my time trying to make heads or tales of their nonsensical code.
I also generally believe that most functions should fit lengthwise on a monitor because if I have to keep scrolling to the top or bottom I'll probably forget something.