code I found online, modifying to my game(survival game)