Refactor game mechanics into engine.c