Posts

Showing posts from September, 2015

Magic enums

Image
There's a talk (click here to go to it)  from WWDC 2015 which discusses uses of Swift enumerations in its second half. When I first watched it, I was somewhat suspicious that it was overhyping enums as "magical unicorn solutions" to all problems. However, as I've worked on my game, I've found a great deal of use cases for enums. Here are some examples of how I've used enums and what I've learned about them: Raw values limited, computed vars unlimited I made function that checks if two rectangles intersect in any of the four cardinal directions by using subrectangles (see the diagram below).  I use the function to allow the player to jump only when standing on top of the ground. (I actually use a spiffy PhysicsSensor class more often than this function, but more on that later). ... and therefore it is legal for the player to jump. Note: I actually run this check by enumerating over all of the obstacles in the scene, as the player could be standing