This is code from html5 game book