hi
- User
hi
- Assistant
Hello! How can I assist you today?
- User
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
hi
Hello! How can I assist you today?
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
fix this: import turtle import random
win = turtle.Screen() win.title("Flappy Bird") win.bgcolor("sky blue") win.setup(width=800, height=600) win.tracer(0)
gravity = -2
bird = turtle.Turtle() bird.speed(0) bird.shape("circle") bird.color("yellow") bird.penup() bird.goto(-200, 0) bird.dy = 0
pipe_gap = 150 pipe_width = 40 pipes = []
score = 0 score_display = turtle.Turtle() score_display.speed(0) score_display.color("black") score_display.penup() score_display.hideturtle() score_display.goto(0, 260) score_display.write(f"Score: {score}", align="center", font=("Courier", 24, "normal"))
def flap(): bird.dy = 15
def create_pipe(): top_height = random.randint(150, 350) bottom_height = 600 - top_height - pipe_gap
top_pipe = turtle.Turtle()
top_pipe.speed(0)
top_pipe.shape("square")
top_pipe.color("green")
top_pipe.shapesize(stretch_wid=top_height / 20, stretch_len=pipe_width / 20)
top_pipe.penup()
top_pipe.goto(400, 300)
pipes.append(top_pipe)
bottom_pipe = turtle.Turtle()
bottom_pipe.speed(0)
bottom_pipe.shape("square")
bottom_pipe.color("green")
bottom_pipe.shapesize(stretch_wid=bottom_height / 20, stretch_len=pipe_width / 20)
bottom_pipe.penup()
bottom_pipe.goto(400, -300 + bottom_height)
pipes.append(bottom_pipe)
def check_collision(): for pipe in pipes: if bird.xcor() + 10 > pipe.xcor() - pipe_width / 2 and bird.xcor() - 10 < pipe.xcor() + pipe_width / 2: if bird.ycor() + 10 > 300 - pipe.shapesize()[0] * 20 or bird.ycor() - 10 < -300 + pipe.shapesize()[0] * 20: return True if bird.ycor() > 290 or bird.ycor() < -290: return True return False
win.listen() win.onkeypress(flap, "space")
pipe_timer = 0 while True: win.update()
# Gravity
bird.dy += gravity
bird.sety(bird.ycor() + bird.dy)
# Create pipes periodically
pipe_timer += 1
if pipe_timer > 100:
create_pipe()
pipe_timer = 0
# Move pipes
for pipe in pipes:
pipe.setx(pipe.xcor() - 5)
# Remove off-screen pipes
pipes = [pipe for pipe in pipes if pipe.xcor() > -400]
# Check for collision
if check_collision():
score_display.clear()
score_display.write(f"Game Over! Final Score: {score}", align="center", font=("Courier", 24, "bold"))
break
# Increment score for passing pipes
for pipe in pipes:
if pipe.xcor() < -200 and pipe.xcor() > -205: # Pass through the gap
score += 0.5
score_display.clear()
score_display.write(f"Score: {int(score)}", align="center", font=("Courier", 24, "normal"))
Your code is almost complete, but there are a few issues that need attention. Here's a revised version with comments explaining the fixes:
import turtle
import random
# Set up the screen
win = turtle.Screen()
win.title("Flappy Bird")
win.bgcolor("sky blue")
win.setup(width=800, height=600)
win.tracer(0)
# Gravity variable
gravity = -0.5 # Adjusted gravity value for smoother movement
# Bird
bird = turtle.Turtle()
bird.speed(0)
bird.shape("circle")
bird.color("yellow")
bird.penup()
bird.goto(-200, 0)
bird.dy = 0
# Pipes
pipe_gap = 150
pipe_width = 40
pipes = []
# Score
score = 0
score_display = turtle.Turtle()
score_display.speed(0)
score_display.color("black")
score_display.penup()
score_display.hideturtle()
score_display.goto(0, 260)
score_display.write(f"Score: {score}", align="center", font=("Courier", 24, "normal"))
# Functions
def flap():
bird.dy = 8 # Adjusted flap power for better control
def create_pipe():
top_height = random.randint(150, 350)
bottom_height = 600 - top_height - pipe_gap
# Creating top pipe
top_pipe = turtle.Turtle()
top_pipe.speed(0)
top_pipe.shape("square")
top_pipe.color("green")
top_pipe.shapesize(stretch_wid=top_height / 20, stretch_len=pipe_width / 20)
top_pipe.penup()
top_pipe.goto(400, 300 - top_height / 2)
pipes.append(top_pipe)
# Creating bottom pipe
bottom_pipe = turtle.Turtle()
bottom_pipe.speed(0)
bottom_pipe.shape("square")
bottom_pipe.color("green")
bottom_pipe.shapesize(stretch_wid=bottom_height / 20, stretch_len=pipe_width / 20)
bottom_pipe.penup()
bottom_pipe.goto(400, -300 + bottom_height / 2)
pipes.append(bottom_pipe)
# Collision detection
def check_collision():
for pipe in pipes:
if bird.xcor() + 10 > pipe.xcor() - pipe_width / 2 and bird.xcor() - 10 < pipe.xcor() + pipe_width / 2:
if bird.ycor() + 10 > pipe.ycor() + (pipe.shapesize()[0] * 10) or bird.ycor() - 10 < pipe.ycor() - (pipe.shapesize()[0] * 10):
return True
if bird.ycor() > 290 or bird.ycor() < -290:
return True
return False
# Keyboard binding
win.listen()
win.onkeypress(flap, "space")
# Main game loop
pipe_timer = 0
while True:
win.update()
# Gravity
bird.dy += gravity
bird.sety(bird.ycor() + bird.dy)
# Create pipes periodically
pipe_timer += 1
if pipe_timer > 100:
create_pipe()
pipe_timer = 0
# Move pipes
for pipe in pipes:
pipe.setx(pipe.xcor() - 3) # Adjusted pipe speed for balance
# Remove off-screen pipes
pipes = [pipe for pipe in pipes if pipe.xcor() > -400]
# Check for collision
if check_collision():
score_display.clear()
score_display.write(f"Game Over! Final Score: {int(score)}", align="center", font=("Courier", 24, "bold"))
break
# Increment score for passing pipes
for pipe in pipes:
if -205 < pipe.xcor() < -200: # Pass through the gap
score += 0.5
score_display.clear()
score_display.write(f"Score: {int(score)}", align="center", font=("Courier", 24, "normal"))
Run this code, and your Flappy Bird clone should work as expected. Adjust parameters if needed to better suit your gameplay preferences.
Not yet included in a published release.