Trying to write a game engine in js