Are there any rules (of thumb), guidelines, formulas, tests or general considerations regarding HOW I organise my objects and information? As in, when do I fill Objects with countless attributes and methods, and when would I better keep those within separate sub-objects and attach them to whatever Object has need of them? When is it smarter to store information in individual objects, and when is it smarter to store it in a single super-object? Is it generally best to minimise the number of layers of objects and sub-objects, or does it not usually matter how deep that rabbit hole goes?
I'm going to have a slightly different approach than X here, but largely speaking the two of us think alike. I've gotten tons of helpful code and theory from him and Keith.
Anyway.
1) Avoid God Objects. A "god object" is a single class or instance that Know Everything.
2) Avoid public properties where possible, only expose what needs to be exposed.
3) Likewise don't cross reference if you can avoid it. The main game class will know about the Player and the Dungeon, both of which will know about the main class, but the Dungeon shouldn't know about the Player and vice versa. (Possibly bad example, but its the best I can come up with on short notice). Inevitably you'll find exceptions even when you were certain that A shouldn't need to know anything about B.*
4) Class inheritance! Extends! Implements! Glorious features. public class Player extends GameObject implements IMovable {}
(GameObject here being a generic class, not Unity's GameObject class, which is static and can't be extended)
As a generic suggestion, go get
Minecraft Forge source (and
Eclipse to run it), poke around with Minecraft's internal structure a bit. Get a feel for how the code is organized. Its by no means perfect, but having spent several months modding I picked up a few habits that I rather like, just due to the organizational benefit. I also fell in love with Eclipse, though I haven't had the time to set it up as a generic IDE for Unity or Flash (the version of MonoDevelop for Windows that ships with Unity is garbage). It's Refactoring tools are lovably amazing. Want to rename a class? Right click, refactor -> rename, bam. Anywhere it's been used in your entire project now use the new name. I would love to have that power for the Flash game I'm working on. I'd like to rename RewardItem to ItemReward, just so that when I try to type a var as RewardItem I don't have to scroll down through Reward00 through Reward50 to get to it (or typing out "RewardI").
*My dungeon floor objects should never need to know anything about the player, after all, this is just the walkable map and some other objects!
* Draco18s implements shadows
public function onEnter() { //run when the player first enters the floor.
if(main.currentMapID <= 10) { //no shadows below floor 10
shadows.visible = false;
}
else if(main.currentMapID < 40) { //deepending shadows until 40, 40+ full dark
a = (main.currentMapID - 11) / 30;
shadows.alpha = a;
}
* Draco18s implements the torch so that the player can see in deep shadows
Crap. Floor needs to know about the player now....
//shadows less dark if the player has the torch
if(shadows.visible && main.player.flags.hasTorch) { //hackney reference to the player
shadows.alpha /= 3;
}