Tuesday, May 26, 2015
Day Four: Death
Thursday, May 14, 2015
Day Three: Interaction
Saturday, May 9, 2015
Day Two: Color
Seems simple enough doesn't it? Well there's a lot of mind-numbing, classy stuff going on behind the scenes. Like Classes. In order to get the Morgs to belong to a "Species" with its own colors, I have to define each species and that means classes. Defining a class is like looking out at the universe and dividing it into things with names. What things in your game's universe are similar and numerous enough that they deserve their own class? How can you reduce the idea of that thing down into a set of attributes?
To get more technical, instead of having an array of active morg transforms, which I would need to dig around in to find the associated scripts anytime I wanted to know something interesting about that morg, I have an array of active morgs... of class "Morg", a custom class I defined to have all the interesting information easily available. No more game object > find > getComponents just to get at the relevant script. If a script is needed, it's part of the classmember I pull directly from the array.
I also started using statics as a way of having some of the variables from gameMaster available and synchronized across all scripts. It's useful for gameSpeed and overall population and such. Again, as with classes, I don't have to pull an instance of the script I need into the script I'm working with just to get at that variable. If it's marked as static, all my scripts seem to know about it. I was thinking the word for that was a "global" but the C# purists of the web warn me all over the place not to use globals. Actually, quite a few warnings against statics too, but it's just what I needed... they recommend something called a "Singleton" instead.... wtf? Now that's new.
To get even more technical, I needed three new classes to pull this off. "Morg" is the workhorse, it contains references to the MorgMotion script and the transform in addition to the usual stuff that defines an individual morg (like age and energy and name). The stuff I actually need in runtime. "MorgDef" is a class of morg definitions. Like a gallery of platonic forms. Where "Morg" is a group of Individuals, this is a group of Species. This is where I associate the type of morg with all the attributes that typify its Species, like its color (and eventually behaviour). And finally "cColor" ("Color" is already a built-in static class) where I define my own custom colors because Unity's defaults aren't pretty enough.
Thursday, May 7, 2015
Day One: Motion
I cracked open Unity again and it felt pretty good! Making a bunch of these guys spawn and bounce off the walls was easy enough.
So I went a bit further, started putting in UI. A game speed slider that goes from 1x to 256x, and a separate "Pause" button, like the old flash version. It's important that I don't just increase the speed of the morgs. At higher speeds, the morgs could zip right by each other without interacting, producing a totally different simulation at 256 than at 1, and I don't want that. I use sub-steps. All the morgs' motion is under a for loop that iterates S number of times per frame, where S is the gamespeed. So, at 256x the morgs are going through every single incremental movement they would have at 1x, they're just doing it 256 times before the program renders a frame. 256 seems to be about the limit beyond which I can't detect if it's actually going any faster. It does get choppier though, which must mean it's dropping frames. Have to look into that if I really want to have a 256 speed and still be able to say the simulation will play out exactly the same...
Also, added a highlight marker thing so you can follow around a particular morg. When you're focused on one, its individual stats will probably be displayed somewhere eventually. That's a feature the flash version didn't have, and it seems obvious now...
Subscribe to:
Posts (Atom)