if bullet.xcor() > 380 or bullet.xcor() < -380: bullet.hideturtle() bullet_is_ready = True # Detect Asteroid Collision with top and bottom walls asteroid.bounce_y() # Detect Asteroid Collision with left and walls asteroid.bounce_x() #Detect if collision and makes asteroids bounce against themselves for a in asteroid.asteroids: # Detect Collision with Spaceship and Asteroid if spaceship.distance(a) < 35: print("COLLISION") scoreboard.reset() # game_is_on = False # Detect Collision with Bullet and Asteroid if bullet.distance(a) < 30 and bullet.distance(spaceship) > 5: setup_bullet() bullet.hideturtle() bullet_is_ready = True a.goto(-10000, 0) scoreboard.add_one_to_score() score += 1 print("COLLISION WITH BULLET score: ", score) screen.exitonclick()
screen.listen() 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() # collision with food if snake.head.distance(food) < 13: food.refresh() snake.extend() score.increase_score() #collision with walls if snake.head.xcor() > 290 or snake.head.xcor() < -290 or snake.head.ycor( ) > 290 or snake.head.ycor() < -290: score.reset() snake.reset() # collision with tail for segment in snake.segments[1:]: if snake.head.distance(segment) < 10: score.reset() snake.reset() screen.exitonclick()
sco = Scoreboard() screen.listen() screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.right, "Right") screen.onkey(snake.left, "Left") game_is_on = True while game_is_on: screen.update() time.sleep(0.1) snake.move() if snake.head.distance(food) < 15: food.refresh() snake.extend() sco.increase_score() if snake.head.xcor() > 280 or snake.head.xcor() < -300 or snake.head.ycor( ) > 277 or snake.head.ycor() < -280: sco.reset() snake.reset() for seg in snake.segment[1:]: if snake.head.distance(seg) < 10: sco.reset() snake.reset() screen.exitonclick()