• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Variable/Game Organization, Parenting, etc.

K

Kululu17

Guest
Hello – I am just about to convert my main project, Rocket Frame 87 from 1.4 to 2, and wanted to overhaul/cleanup my code and organization. There are two areas where I have a compromise solution that works, but I wonder if there is a better way. The game is an explorer/building sim.

1. Stuff inside stuff inside stuff. For this game you control colonists, and one of the key features is crafting. Crafting happens inside the workshop. You assign a colonist to a workshop, and the workshop can now produce stuff. If the colonist has specific tool, or skill, there is a crafting bonus. Right now, when a colonist picks up a tool, the tool instance is destroyed, and the colonist instance is updated to show he has a specific tool (pretty much like any inventory management). If the colonist is assigned to a workshop, the instance is destroyed and all the parameters (including any inventory they are carrying) is copied to a (very large) global array, and the workshop instance only saves the relevant parameters (like bonuses, and the key in the array for the colonist in question). Move the colonist out of the workshop and a new instance is created, with parameters copied from the global array. What alternate approaches could there be?

2. Parenting: There is an object "Avatar" that is the parent for colonists, NPCs, monsters, etc. It contains all the code for movement, collision, combat, etc. Monsters are a child of this as are colonists. Colonists use the same basic variables, and add additional variable for stuff like inventory which a monster won't have. There is a duplication of information between the global colonist array, which is used to "back up" information for when a colonist goes inside a building, or leaves the main map, but all interaction (like pulling combat parameters, or movement speed) is done from the instance. I could have the information for stuff like combat get pulled directly from the colonist array, but then I would lose the consistency that I have now with always being able to reference Avatar level variables regardless of if combat is for example colonist vs colonist, or colonist vs monster, or monster vs monster.

Any suggestions on alternate/better ways to organize?



Thanks in advance!
 
Top