Question

How to get objects fly out of another object in pygame.

I’m not sure how to get objects to fly out another object every time it is pressed. It’s just like Cookie Clicker. This is Pygame code(turtle). This is all my code so far:

import turtle

wn = turtle.Screen()
wn.title("Cake Clicker by @.......")
wn.bgpic("backg for app.gif")

wn.register_shape("cake2.gif")

cake2 = turtle.Turtle()
cake2.shape("cake2.gif")
cake2.speed(0)

clicks = 0

pen = turtle.Turtle()
pen.hideturtle()
pen.color("black")
pen.penup()
pen.goto(0, 400)
pen.write(f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))


def clicked(x, y):
    global clicks
    clicks += 1
    pen.clear()
    pen.write(f"Clicks: {clicks}", align="center", font=("Courier New", 32, "normal"))


cake2.onclick(clicked)

wn.mainloop()

If you could respond to me with some help or the correct code, that would be great. All I need is to have a small cake picture jump out of the larger cake in the center when it is clicked (pressed).


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

Is there a specific tutorial that you are following? I could take a look at it and check out the prerequisites, it is possible that something is missing.

I tried running the code that you’ve provided and it is not returning any errors.

Best, Bobby