This is a cookie clicker game I have been working on in python with turtle:
import turtle
clicks = 0
num = 1
def main():
screen = turtle.Screen()
screen.title("Cookie Clicker by Homare and Jonathan")
screen.bgcolor("#189df5")
# Cookie
cookie = turtle.Turtle()
screen.addshape("cookie.gif")
cookie.shape("cookie.gif")
cookie.penup()
cookie.backward(200)
cookie.speed(0)
# Upgrade 1 Button + draw
upgrade = turtle.Turtle()
upgrade.hideturtle()
upgrade.speed(0)
upgrade.penup()
upgrade.goto(7, 94)
upgrade.pendown()
upgrade.fillcolor('white')
upgrade.begin_fill()
for i in range(2):
upgrade.forward(340)
upgrade.left(90)
upgrade.forward(30)
upgrade.left(90)
upgrade.end_fill()
upgrade.penup()
upgrade.goto(7, 94)
upgrade.write("+1 Cookie/Click: 15 Cookies", font=("Courier", 20, "normal"))
# Upgrade 2 Button + draw
upgrade2 = turtle.Turtle()
upgrade2.hideturtle()
upgrade2.speed(0)
upgrade2.penup()
upgrade2.goto(7, 54)
upgrade2.pendown()
upgrade2.fillcolor('white')
upgrade2.begin_fill()
for i in range(2):
upgrade2.forward(340)
upgrade2.left(90)
upgrade2.forward(30)
upgrade2.left(90)
upgrade2.end_fill()
upgrade2.penup()
upgrade2.goto(7, 54)
upgrade2.write("x2 Cookie/Click: 100 Cookies", font=("Courier", 20, "normal"))
# Written Click Text
write_text(0, 200, f"Cookies: {clicks}")
cookie.onclick(clicked)
turtle.onscreenclick(up2click, 1)
turtle.onscreenclick(upgradeclick, 1)
turtle.listen()
screen.mainloop()
def upgradeclick(x, y):
global clicks
global num
if clicks >= 15:
if x > 0 and x < 341 and y > 94 and y < 124:
clicks -= 15
num += 1
counter.clear()
write_text(0, 200, f"Cookies: {clicks}")
def up2click(x, y):
global clicks
global num
if clicks >= 100:
if x > 0 and x < 341 and y > 54 and y < 84:
clicks -= 100
num *= 2
counter.clear()
write_text(0, 200, f"Cookies: {clicks}")
def clicked(x, y):
global clicks
global num
clicks += num
counter.clear()
write_text(0, 200, f"Cookies: {clicks}")
print(clicks)
def write_text(center_x, center_y, text):
''' Write text on the Screen '''
counter.speed(0)
counter.penup()
counter.hideturtle()
counter.goto(center_x, center_y)
counter.write(text, align="center", font=("Courier New", 32, "normal"))
counter = turtle.Turtle()
main()
When I run it, only the first upgrade (+1 cookie/click) works when I click on it, but when I click the second upgrade (x2 cookie/click), nothing seems to happen. What's supposed to happen is that 100 cookies get subtracted, then the cookies per click multiply by two, such as if you had 50 cookies per click it would multiply to 100 cookies per click.
It probably won't work because you don't have the cookie.gif, but I will try to post it on here. Just download a cookie gif and put it inside the same directory. Don't forget to change the name. Here is the video I used to put the cookie image in.