최근 할 것도 없고 심심해서 간단한 게임 하나 만들어보려 합니다.
색 맞추는 게임입니다.
import pygame
import math
pygame.init()
screen_width = 960
screen_height = 720
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("What color is it?")
# 시작
def start():
clock = pygame.time.Clock()
Logo = pygame.image.load("image\\RIS.png")
Logo_width = Logo.get_size()[0] * 100 # 100 기본값
Logo_height = Logo.get_size()[1] * 100 # 100 기본값
Logo = pygame.transform.scale(Logo, (Logo_width, Logo_height))
Logo_tmp_x = screen_width / 2 # 이미지 중심
Logo_tmp_y = screen_height / 2 # 이미지 중심
Logo_x = Logo_tmp_x - Logo_width / 2
Logo_y = Logo_tmp_y - Logo_height / 2
circle_x = Logo_tmp_x # Logo와 같이 있음
circle_y = Logo_tmp_y
diameter = math.sqrt((Logo_width / 2) ** 2 * 2) # 자동
c_R, c_G, c_B = 255, 255, 255
Guide = pygame.image.load("image\\click to play.png")
Guide_width = Guide.get_size()[0]
Guide_height = Guide.get_size()[1]
Guide = pygame.transform.scale(Guide, (Guide_width, Guide_height))
Guide_x = 230
Guide_y = 400
back_rect_y = screen_height
i = 0
running = True
while running:
dt = clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT or event.type == pygame.MOUSEBUTTONDOWN:
running = False
Logo_x = Logo_tmp_x - Logo_width / 2
Logo_y = Logo_tmp_y - Logo_height / 2
circle_x = Logo_tmp_x # Logo와 같이 있음
circle_y = Logo_tmp_y
diameter = int(math.sqrt((Logo_width / 2) ** 2 * 2)) # 자동
screen.fill((0, 0, 0))
screen.blit(Guide, (Guide_x, Guide_y))
if i != 3:
pygame.draw.rect(screen, (0, 0, 0), [0, 0, screen_width, back_rect_y])
back_circle = pygame.draw.circle(screen, (c_R, c_G, c_B), (circle_x, circle_y), diameter)
screen.blit(Logo, (Logo_x, Logo_y))
pygame.display.update()
# 1
if i == 0:
i = 1
# 2
elif i == 1:
if Logo_width > 100: # Logo original width length pixel
Logo_width -= 300
Logo_height -= 300
Logo = pygame.transform.scale(Logo, (Logo_width, Logo_height))
else:
i = 2
pygame.time.delay(1000)
# 3
elif i == 2:
if Logo_tmp_y <= screen_height / 4:
i = 3
else:
Logo_tmp_y -= 6
main()
def main():
screen_width = 960
screen_height = 720
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("main")
clock = pygame.time.Clock()
# circle state
circle_x, circle_y = screen_width / 2, screen_height / 4
diameter = 100
R, G, B = 200, 200, 200
running = True
while running:
dt = clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = false
screen.fill([0, 0, 0])
pygame.draw.circle(screen, [R, G, B], (circle_x, circle_y), diameter)
pygame.display.update()
pygame.quit()
start()
시작 부분만 간단(?)하게 만들었습니다.
하던 도중 최적화 문제와 몇 초 기다리게 하는 것에서 time 라이브러리를 쓸지 고민하다 pygame 내에 자체적으로 있는 비슷한 기능이 있길래 채택했습니다.
이미지는 직접 쓸 수는 있지만 그림판이 더 편해서 그림판으로 그렸습니다.
쓰실 분들은 쓰셔도 됩니다.
앞으로 더 만들어갈 계획입니다.
'게임 개발' 카테고리의 다른 글
[유니티] 크기 조절할 때 중심 고정하는 법 (0) | 2025.01.27 |
---|---|
[Web] 스도쿠 구현하기 마지막 (0) | 2024.11.15 |
[Web] 스도쿠 구현하기 (2) | 2024.11.14 |
[Python] 스도쿠 만들기 (다른 방식) (0) | 2024.11.12 |
[Python] 스도쿠 만들기 (12) | 2024.11.06 |