- Jul 25, 2021
- 1,256
- 519
I created yesterday a Post where i showed that i have created a pong game with Chat-GPT. Today i want to show you my Cookie Clicker game.
I have created this game in 1 Minute
cookie.png
I have created this game in 1 Minute
cookie.png
Python:
import pygame
import sys
# Initialization of Pygame
pygame.init()
# Screen configuration
SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Cookie Clicker")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BROWN = (160, 82, 45)
# Font
font = pygame.font.Font(None, 36)
# Cookie button
cookie_img = pygame.image.load("cookie.png")
cookie_img = pygame.transform.scale(cookie_img, (200, 200))
cookie_rect = cookie_img.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
# Game variables
cookies = 0
cps = 0 # Cookies per second
auto_clicker_cost = 10
# Game clock
clock = pygame.time.Clock()
# Main game loop
def main():
global cookies, cps, auto_clicker_cost
running = True
last_cps_update = pygame.time.get_ticks()
while running:
screen.fill(WHITE)
# Event processing
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if cookie_rect.collidepoint(event.pos):
cookies += 1
# Upgrade purchase
upgrade_rect = pygame.Rect(50, 500, 200, 50)
if upgrade_rect.collidepoint(event.pos) and cookies >= auto_clicker_cost:
cookies -= auto_clicker_cost
cps += 1
auto_clicker_cost = int(auto_clicker_cost * 1.5)
# Generate automatic cookies
current_time = pygame.time.get_ticks()
if current_time - last_cps_update >= 1000: # Every 1 second
cookies += cps
last_cps_update = current_time
# Display cookie
screen.blit(cookie_img, cookie_rect.topleft)
# Display points
score_text = font.render(f"Cookies: {cookies}", True, BLACK)
screen.blit(score_text, (50, 50))
# Display upgrade
upgrade_text = font.render(f"Auto-Clicker (Cost: {auto_clicker_cost})", True, BLACK)
upgrade_rect = pygame.Rect(50, 500, upgrade_text.get_width() + 16, 50)
pygame.draw.rect(screen, BROWN, upgrade_rect)
screen.blit(upgrade_text, (upgrade_rect.x + 10, upgrade_rect.y + 10))
# Display CPS
cps_text = font.render(f"CPS: {cps}", True, BLACK)
screen.blit(cps_text, (50, 100))
# Update screen
pygame.display.flip()
# Limit frame rate
clock.tick(60)
pygame.quit()
sys.exit()
if __name__ == "__main__":
main()
Last edited: