# detect paddle collision with red blocks for block in blocks.list_of_red_blocks: if ball.distance(block) < 40: blocks.remove(blocks.list_of_red_blocks, block) ball.bounce_y() scoreboard.red_point() if not red_contact_first_time: red_contact_first_time = True red_contact = True # increase speed if both orange and red blocks have been hit if red_contact and orange_contact: red_contact = False orange_contact = False ball.increase_speed() # out of lives if lives == 0: scoreboard.gameover() game_is_on = False # no blocks remaining if len(blocks.list_of_yellow_blocks) == 0 and len(blocks.list_of_green_blocks) == 0 \ and len(blocks.list_of_orange_blocks) == 0 and len(blocks.list_of_red_blocks) == 0: scoreboard.win() game_is_on = False screen.exitonclick()
screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.left, "Left") screen.onkey(snake.right, "Right") game_is_on = True while game_is_on: screen.update() time.sleep(0.1) snake.move() # Detect collision with food. if snake.head.distance(food) < 15: food.refresh() score.add_score() snake.extend() # Detect collision with wall. if snake.head.xcor() > 280 or snake.head.xcor() < -280 or snake.head.ycor( ) > 280 or snake.head.ycor() < -280: game_is_on = False score.gameover() # Detect collision with tail. for segment in snake.segments[1:]: if snake.head.distance(segment) < 10: game_is_on = False score.gameover() screen.exitonclick()