moveleft false moveright false moveup false movedown false movespeed run the game loop while true check for events for event in pygame event get() if event type =quit pygame quit( sys exit( if event type =keydown change the keyboard variables if event key =k_left or event key =ord(' ') moveright false moveleft true if event key =k_right or event key =ord(' ') moveleft false moveright true if event key =k_up or event key =ord(' ') movedown false moveup true if event key =k_down or event key =ord(' ') moveup false movedown true if event type =keyup if event key =k_escape pygame quit( sys exit( if event key =k_left or event key =ord(' ') moveleft false if event key =k_right or event key =ord(' ') moveright false if event key =k_up or event key =ord(' ') moveup false if event key =k_down or event key =ord(' ') movedown false if event key =ord(' ') player top random randint( windowheight player height player left random randint( windowwidth player width