import pygame # 1. pygame 선언
pygame.init() # 2. pygame 초기화
# 3. pygame에 사용되는 전역변수 선언
WHITE = (255, 255, 255)
size = [400, 300]
screen = pygame.display.set_mode(size)
done = False
clock = pygame.time.Clock()
# pygame에 사용하도록 비행기 이미지를 호출
airplane = pygame.image.load('plane.png')
airplane = pygame.transform.scale(airplane, (60, 45))
# 4. pygame 무한루프
def runGame():
global done, airplane
x = 20
y = 24
while not done:
clock.tick(10)
screen.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# 방향키 입력에 대한 이벤트 처리
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
y -= 10
elif event.key == pygame.K_DOWN:
y += 10
elif event.key == pygame.K_LEFT:
x -= 10
elif event.key == pygame.K_RIGHT:
x+= 10
screen.blit(airplane, (x, y))
pygame.display.update()
runGame()
pygame.quit()
https://drive.google.com/drive/folders/1P7-ibtlJKUEet1lbqkSAg7N8RyxOza_o
https://ai-creator.tistory.com/529?category=807420
제안 : 폭탄피하기게임 업그레이드 ( 새로운 아이템, 스코어, 생명 등등... )top of page

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



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.CHEESE 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.CHEESE, dc.IVORY, dc.BEIGE] size = [600, 800] screen = pygame.display.set_mode(size) done = False clock = pygame.time.Clock() def runGame(): starttime = int(time.time()) 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_image = pygame.image.load('life.png') life_image = pygame.transform.scale(life_image, (250, 250)) life = pygame.Rect(life_image.get_rect()) life.left=size[0] // 2 - life.width // 2 life.top = size[0] global done while not done: clock.tick(30) screen.fill(a[cc]) 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 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 사진이 안뜲 # 시간초 어디에서 셀지 명령문도 모르겠음