port from http://www.greenwood.co.jp/~k-aki/article/js_game_first/js_game_first.html