How to make COOKIE CLICKER in python with PYGAME - playegndary.com

How to make COOKIE CLICKER in python with PYGAME

Geek
Views: 3028
Like: 45
how to make a cookie clicker type of game.

Stuff i use
IDE:
Theme: Default Dark Mode

11 Comments

  1. Geek can you make an auto rain joiner for bloxflip pls

  2. How would you change the image of the cookie?

  3. how do you fix the issue with clicking once on the upgrade button causes it to buy multiple upgrades?

  4. here is the code (without the addition of assets) for anyone wanting to copy and paste:

    import pygame

    import sys

    class Game:

    def __init__(self):

    self.cookies = 0

    self.cookie_per_click = 1

    self.cookie = pygame.Rect(400 – 150, 300 – 150, 300, 300)

    self.cookie_colour = "#522920"

    self.clicked = False

    self.upgrade_btn = pygame.Rect(10, 50, 185, 75)

    self.upgrade1_cost = 15

    self.game_font = pygame.font.Font(None, 27)

    def upgrade(self):

    self.upgrade1_description = self.game_font.render(f"+{self.cookie_per_click} cookie per click.", True, "#ffffff")

    self.display_cost = text_font.render(f"Cost: {str(self.upgrade1_cost)}", True, "#ffffff")

    pygame.draw.rect(screen, "#488ebd", self.upgrade_btn, border_radius=15)

    screen.blit(self.display_cost, (15, 85))

    screen.blit(self.upgrade1_description, (15, 55))

    def draw_score(self):

    self.display_cookies = text_font.render(f"Cookies: {str(self.cookies)}", True, "#ffffff")

    screen.blit(self.display_cookies, (0, 565))

    def click_button(self):

    self.mouse_pos = pygame.mouse.get_pos()

    if self.cookie.collidepoint(self.mouse_pos):

    if pygame.mouse.get_pressed()[0]:

    self.clicked = True

    else:

    if self.clicked:

    self.cookies += self.cookie_per_click

    self.clicked = False

    if self.upgrade_btn.collidepoint(self.mouse_pos):

    if pygame.mouse.get_pressed()[0]:

    if self.cookies >= self.upgrade1_cost:

    self.cookies -= self.upgrade1_cost

    self.upgrade1_cost *= 2

    self.cookie_per_click += 1

    pygame.draw.rect(screen, self.cookie_colour, self.cookie, border_radius=150)

    def render(self):

    self.click_button()

    self.draw_score()

    self.upgrade()

    pygame.init()

    width = 800

    height = 600

    game = Game()

    screen = pygame.display.set_mode(size=(width, height))

    pygame.display.set_caption("Cookie Clicker")

    text_font = pygame.font.Font(None, 50)

    title = text_font.render("Cookie Clicker", True, "#000000")

    clock = pygame.time.Clock()

    while True:

    screen.fill("#0000ff")

    for event in pygame.event.get():

    if event.type == pygame.QUIT:

    pygame.quit()

    sys.exit()

    screen.blit(title, (270, 15))

    game.render()

    pygame.display.update()

    clock.tick(60)

  5. this dosent work for me it all ways says missing 1 required positonal argument: 'self'

Leave a Reply

Your email address will not be published.