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).

edited by bobbyiliev

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.

×
Submit an Answer
1 answer

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

  • I’m not looking for any specific tutorial, I’m just trying to add a bit of code to my app to make objects fly out of another object every time it is pressed. If you could take a look at it that would be great. Alongside all of that maybe you could send me some pygame tutorials as I’m just beginning it.

    Thank you,
    John