[파이썬] 간단한 클릭커 게임 만들기(with pygame)

pygame을 활용하여 간단한 클릭커 게임을 만들어 볼 수 있다. 이 게임은 단지 마우스를 클릭했을 때 점수를 올라가도록 만든 아주 단순한 게임으로 거지 키우기 같은 포인트를 획득하여 아이템을 사는 동작들은 구현되어 있지 않지만 이 기본예제를 토대로 만들어 볼 수 있다.

pygmae을 활용한 간단한 클릭커 게임 만들기

게임의 목적: 마우스를 클릭 할 때 점수가 올라가는 구성을 배우는 것
게임의 동작 방법 : 빈 화면에 마우스 좌클릭을 할 경우 점수가 올라 가도록 구현된 매커니즘

## 파이썬 코드##

import pygame
import sys

# 초기화
pygame.init()

# 화면 설정
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("클릭커 게임")

# 색깔 정의
white = (255, 255, 255)
font = pygame.font.Font(None, 36)

score = 0

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:  # 왼쪽 마우스 클릭
                score += 1

    # 배경 지우기
    screen.fill(white)

    # 점수 표시
    score_text = font.render(f"Score: {score}", True, (0, 0, 0))
    screen.blit(score_text, (10, 10))

    pygame.display.flip()

클릭커 게임

Loading

댓글 남기기