print("select background color")
print("1.BLACK 2.RED 3.GREEN 4.BLUE 5.MINT 6.YELLOW 7.ORANGE\n8.PURPLE 9.PINK 10.LIME 11.BROWN 12.GRAY 13.CORAL 14.PIG\n15.OLIVE 16.WINE 17.PEACH 18.IVORY 19.BEIGE")
cc = int(input())-1
import pygame # 1. pygame 선언
import random
import time
import data.colorList as dc
pygame.init() # 2. pygame 초기화
# 3. pygame에 사용되는 전역변수 선언
a = [dc.BLACK, dc.RED, dc.GREEN, dc.BLUE, dc.MINT, dc.YELLOW, dc.ORANGE, dc.PURPLE, dc.PINK, dc.LIME, dc.BROWN, dc.GRAY, dc.CORAL, dc.PIG, dc.OLIVE, '''dc.WINE, dc.PEACH, dc.IVORY, dc.BEIGE''']
size = [600, 800]
screen = pygame.display.set_mode(size)
done = False
clock = pygame.time.Clock()
# def startGame():
def runGame():
bomb_image = pygame.image.load('bomb.png')
bomb_image = pygame.transform.scale(bomb_image, (50, 50))
bombs = []
l = 3
for i in range(5):
rect = pygame.Rect(bomb_image.get_rect())
rect.left = random.randint(0, size[0])
rect.top = -100
dy = random.randint(3, 9)
bombs.append({'rect': rect, 'dy': dy})
person_image = pygame.image.load('person.png')
person_image = pygame.transform.scale(person_image, (100, 100))
person = pygame.Rect(person_image.get_rect())
person.left = size[0] // 2 - person.width // 2
person.top = size[1] - person.height
person_dx = 0
person_dy = 0
life = []
life_image = pygame.image.load('life.png')
life_image = pygame.transform.scale(life_image, (50, 50))
life.append(pygame.Rect(life_image.get_rect()))
life.append(pygame.Rect(life_image.get_rect()))
life.append(pygame.Rect(life_image.get_rect()))
starttime = int(time.time())
global done
while not done:
clock.tick(30)
screen.fill(a[cc])
timetime = int(time.time())
sysfont = pygame.font.SysFont(None, 72)
text = sysfont.render(str(timetime-starttime), True, (255, 255, 255)) # BLUE = (0, 0, 255)
screen.blit(text, (0, 0))
for i in range(l):
life[i].left=size[0] // 2 - (i+1)*life[i].width
life[i].top = 0
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
break
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
person_dx = -5
elif event.key == pygame.K_RIGHT:
person_dx = 5
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
person_dx = 0
elif event.key == pygame.K_RIGHT:
person_dx = 0
for bomb in bombs:
bomb['rect'].top += bomb['dy']
if bomb['rect'].top > size[1]:
bombs.remove(bomb)
rect = pygame.Rect(bomb_image.get_rect())
rect.left = random.randint(0, size[0])
rect.top = -100
dy = random.randint(3, 9)
bombs.append({'rect': rect, 'dy': dy})
person.left = person.left + person_dx
if person.left < 0:
person.left = 0
elif person.left > size[0] - person.width:
person.left = size[0] - person.width
screen.blit(person_image, person)
for i in range(l):
screen.blit(life_image, life[i])
for bomb in bombs:
if bomb['rect'].colliderect(person):
bomb['rect'].top -= 777
bomb['rect'].left = random.randint(0, size[0])
l = l - 1
if l == 0:
done = True
screen.blit(bomb_image, bomb['rect'])
pygame.display.update()
endtime = int(time.time())
score = endtime - starttime
print('score :', score, 'sec', sep=' ')
runGame()
pygame.quit()
# life 사진이 여러개가 안뜸
# 시간초 어디에서 셀지 명령문도 모르겠음
top of page

실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
2025.09.21
2025.09.21
댓글 1개
좋아요
댓글(1)
더 이상 게시물에 대한 댓글 기능이 지원되지 않습니다. 자세한 사항은 사이트 소유자에게 문의하세요.
bottom of page



import pygame # 1. pygame 선언 import random import time import data.colorList as dc cc = 1 pygame.init() # 2. pygame 초기화 # 3. pygame에 사용되는 전역변수 선언 a = [dc.BLACK, dc.RED, dc.GREEN, dc.BLUE, dc.MINT, dc.YELLOW, dc.ORANGE, dc.PURPLE, dc.PINK, dc.LIME, dc.BROWN, dc.GRAY, dc.CORAL, dc.PIG, dc.OLIVE, dc.WINE, dc.PEACH, dc.IVORY, dc.BEIGE] size = [600, 800] screen = pygame.display.set_mode(size) done = False clock = pygame.time.Clock() def startGame(): global cc global done while not done: screen.fill(dc.WHITE) sysfont = pygame.font.SysFont(None, 64) text = sysfont.render("Select Background Color", True, (0, 0, 0)) screen.blit(text, (0, 0)) sysfont = pygame.font.SysFont(None, 32) text = sysfont.render("Press Space To Select", True, (0, 0, 0)) screen.blit(text, (0, 40)) for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: cc -= 1 elif event.key == pygame.K_RIGHT: cc += 1 elif event.key == pygame.K_UP: cc -= 4 elif event.key == pygame.K_DOWN: cc += 4 elif event.key == pygame.K_SPACE: done = True pygame.display.update() def runGame(): global cc bomb_image = pygame.image.load('bomb.png') bomb_image = pygame.transform.scale(bomb_image, (50, 50)) bombs = [] l = 3 for i in range(5): rect = pygame.Rect(bomb_image.get_rect()) rect.left = random.randint(0, size[0]) rect.top = -100 dy = random.randint(3, 9) bombs.append({'rect': rect, 'dy': dy}) person_image = pygame.image.load('person.png') person_image = pygame.transform.scale(person_image, (100, 100)) person = pygame.Rect(person_image.get_rect()) person.left = size[0] // 2 - person.width // 2 person.top = size[1] - person.height person_dx = 0 person_dy = 0 life = [] life_image = pygame.image.load('life.png') life_image = pygame.transform.scale(life_image, (50, 50)) life.append(pygame.Rect(life_image.get_rect())) life.append(pygame.Rect(life_image.get_rect())) life.append(pygame.Rect(life_image.get_rect())) starttime = int(time.time()) global done while not done: clock.tick(30) screen.fill(a[cc-1]) timetime = int(time.time()) sysfont = pygame.font.SysFont(None, 72) text = sysfont.render(str(timetime-starttime), True, (255, 255, 255)) # BLUE = (0, 0, 255) screen.blit(text, (0, 0)) for i in range(l): life[i].left=size[0] // 2 - (i+1)*life[i].width life[i].top = 0 for event in pygame.event.get(): if event.type == pygame.QUIT: done = True break elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: person_dx = -5 elif event.key == pygame.K_RIGHT: person_dx = 5 elif event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: person_dx = 0 elif event.key == pygame.K_RIGHT: person_dx = 0 for bomb in bombs: bomb['rect'].top += bomb['dy'] if bomb['rect'].top > size[1]: bombs.remove(bomb) rect = pygame.Rect(bomb_image.get_rect()) rect.left = random.randint(0, size[0]) rect.top = -100 dy = random.randint(3, 9) bombs.append({'rect': rect, 'dy': dy}) person.left = person.left + person_dx if person.left < 0: person.left = 0 elif person.left > size[0] - person.width: person.left = size[0] - person.width screen.blit(person_image, person) for i in range(l): screen.blit(life_image, life[i]) for bomb in bombs: if bomb['rect'].colliderect(person): bomb['rect'].top -= 777 bomb['rect'].left = random.randint(0, size[0]) l = l - 1 if l == 0: done = True screen.blit(bomb_image, bomb['rect']) pygame.display.update() endtime = int(time.time()) score = endtime - starttime print('score :', score, 'sec', sep=' ') startGame() done = False runGame() pygame.quit() BLACK = (0, 0, 0) RED = (255, 0, 0) GREEN = (0, 128, 0) BLUE = (25, 25, 255) MINT = (0, 222, 255) YELLOW = (234, 188, 0) ORANGE = (255, 81, 0) PURPLE = (148, 0, 235) PINK = (255, 55, 177) LIME = (128, 255, 0) BROWN = (111, 60, 0) GRAY = (127, 127, 127) CORAL = (255, 99, 111) PIG = (255, 182, 193) OLIVE = (142, 147, 40) WINE = (111, 11, 44) PEACH = (255, 170, 80) IVORY = (235, 226, 211) BEIGE = (177, 155, 133) WHITE = (255, 255, 255)