Initial rewrite from https://github.com/StAidan/X-flixel