screen.setup(600, 600) screen.title("Turtle Crossing Game") screen.tracer(0) turtle = Player() level = 1 car_manager = CarManager() score = Scoreboard() screen.listen() screen.onkey(turtle.move, "Up") game_is_on = True while game_is_on: time.sleep(0.1) car_manager.create_car() car_manager.move_cars(level) # detect when player hits the top edge if turtle.ycor() > 280: turtle.reset_position() level += 1 score.update_score(level) # detect when player collides with a car for car in car_manager.cars: if turtle.distance(car) <= 25: score.game_over() game_is_on = False screen.update() screen.exitonclick()
screen.listen() screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.left, "Left") screen.onkey(snake.right, "Right") while game_on: screen.update() time.sleep(.1) snake.move() #score = 0 if snake.head.distance(food) < 15: score_board.update() food.refresh() snake.extend() if snake.turtle_list[0].xcor() > 290 or snake.turtle_list[0].xcor( ) < -290 or snake.turtle_list[0].ycor() > 290 or snake.turtle_list[0].ycor( ) < -290: game_on = False score_board.game_over() for snek in snake.turtle_list[1:]: # if snek == snake.head: # pass if snake.head.distance(snek) < 5: game_on = False score_board.game_over() screen.exitonclick()