The 2D game lib is a basic framework for creating 2D platformer type games in StarCraft 2 which makes gratuitous use translate kinetics (a new data type added in 3.0). With some modifications, the game lib could be used to for any games with a WASD / 8 directional movement controls or even just games with basic 2D physics (tetris, angry birds, flappy bird, canabalt, etc).
The X and Y velocity of each unit is stored as a custom value. Every game tick, the velocity for each unit is applied via a combination of translate kinetics. Since a maximum of 4100 kinetics can be applied at once, kinetic data is broken into digits (X 1.0, 2.0, 3.0, etc / 0.1, 0.2, 0.3, etc / 0.01 , 0.02, 0.03) and direction (+X for right, -X for left, +Y for up, -Y for down). Because these kinetics have a duration of 0.0625, there is no stacking of applied kinetics across game ticks, allowing units to be moved accurately. Kinetic application occurs in the "Translate Unit Horizontally" and "Translate Unit Vertically" function (inside the Translate Unit function that's run for each active unit in the "Each Game Tick" trigger).
The attached library's "Each Game Tick trigger" runs a host other functions to simulate 2D platformer physics, such as applying friction or air resistance based on unit state, basic collision, speculative contact, and applying gravity.
You can modify game data such as hero move speed, jump height, restitution (bounciness) or game data data such as gravity strength, friction, and air resistance in the Global Record Variables.
Known Issues / Caveats
Maximum horizontal and vertical unit velocity is 9.99 map units per game tick (0.0625 seconds). This could be increased by adding more kinetic data, but does anything really need to move that fast?
Top right / left corners of units may unrealistically clip through bottom corners of static collision units due to the position of the top side collision test. This will be fixed in the next version by using multiple top side collision tests.
Storing unit data (move speed, jump height, etc) in records is less than ideal. A better solution will be implemented.
Fast moving units may clip through 0.5 x 0.5 sized static collision units. I generally advise against using them (but had to create the pipe in Super Sonya Bros 1-1)
Support for slopes! This will allow for Sonic-like levels
Further Optimization. Please let me know if any code screams "optimize me". Current candidate areas include kinetic application and speculative contact functions (speculative contact is the most resource intensive operation by far).
Requested Features. Leave a request in this thread and I'll give it a shot.
To ArcaneDurandel/ArcanePariah for an introductory exploration of kinetic data, and for designing a kinetic wizard so I didn't have to write all 108 kinetic / apply / remove / remove all effects by hand.
Various 2D platformer game dev tutorials and stack exchange threads. Particularly this one.