コード例 #1
0
ファイル: main.py プロジェクト: rushali09/python-project-20
while hello_kitty:
    screen.update()
    time.sleep(0.5)
    snake.move()

    # Detect collision with food
    if snake.segments[0].distance(food) < 15:
        food.refresh()
        snake.grow()
        score.increase_score()

    # Detect collision with wall
    if snake.segments[0].xcor() > 280 or snake.segments[0].xcor() < -280 or snake.segments[0].ycor() > 280 or snake.segments[0].xcor() < -280:
        hello_kitty = False
        score.game_over()

    for segment in snake.segments[1:]:
        if snake.segments[0].distance(segment) < 10:
            hello_kitty = False
            score.game_over()









コード例 #2
0
ファイル: main.py プロジェクト: tduong10101/100-days-python
while current_lane < LAST_LANE_POS:
    num_car = random.randint(1,MAX_CAR)
    lane = Lane(SCREEN_WIDTH,current_lane,num_car)
    lanes.append(lane)
    
    current_lane += LANE_SPACE

score_board = ScoreBoard()

screen.onkey(fun=turtle.move, key="Up")

while game_is_on:
    
    time.sleep(sleep_time)
    if turtle.ycor() >= 290:
        score_board.increase_level()
        turtle.restart()
        sleep_time *=.8
        for lane in lanes:
            lane.reset_lane()

    for lane in lanes:
        lane.move()
        for car in lane.car_list:
            if turtle.distance(car) < 20:
                game_is_on = False                   
                    
    screen.update()

score_board.game_over()    
screen.exitonclick()