#NEWLINE# def step( self , dt ) : #NEWLINE# #INDENT# '\n            Perform one step of game emulation.\n        ' #NEWLINE# dt /= 1000.0 #NEWLINE# self . ticks += 1 #NEWLINE# self . screen . fill ( self . BG_COLOR ) #NEWLINE# self . _handle_player_events ( ) #NEWLINE# self . score += self . rewards [ 'tick' ] #NEWLINE# hit = pygame . sprite . collide_rect ( self . player . head , self . food ) #NEWLINE# if hit : #NEWLINE# #INDENT# self . score += self . rewards [ 'positive' ] #NEWLINE# self . player . grow ( ) #NEWLINE# self . food . new_position ( self . player ) #NEWLINE# #UNINDENT# hits = pygame . sprite . spritecollide ( self . player . head , self . player . body_group , False ) #NEWLINE# if ( len ( hits ) > 0 ) : #NEWLINE# #INDENT# self . lives = ( - 1 ) #NEWLINE# #UNINDENT# x_check = ( ( self . player . head . pos . x < 0 ) or ( ( self . player . head . pos . x + ( self . player_width / 2 ) ) > self . width ) ) #NEWLINE# y_check = ( ( self . player . head . pos . y < 0 ) or ( ( self . player . head . pos . y + ( self . player_width / 2 ) ) > self . height ) ) #NEWLINE# if ( x_check or y_check ) : #NEWLINE# #INDENT# self . lives = ( - 1 ) #NEWLINE# #UNINDENT# if ( self . lives <= 0.0 ) : #NEWLINE# #INDENT# self . score += self . rewards [ 'loss' ] #NEWLINE# #UNINDENT# self . player . update ( dt ) #NEWLINE# self . player . draw ( self . screen ) #NEWLINE# self . food . draw ( self . screen )