import pygame, sys
pygame.init()
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Level Devil - 난이도 조절 버전")
WHITE, BLACK, RED, BLUE, GREEN = (255,255,255), (0,0,0), (200,0,0), (0,0,200), (0,200,0)
# 난이도 (easy, normal, hard)
difficulty = "easy"
if difficulty == "easy":
player_speed = 6
jump_power = -18
traps = [pygame.Rect(500, 450, 50, 20)]
platforms = [pygame.Rect(0, 500, 800, 50), pygame.Rect(250, 500, 150, 20)]
elif difficulty == "normal":
player_speed = 5
jump_power = -15
traps = [pygame.Rect(400, 530, 50, 20), pygame.Rect(250, 430, 50, 20)]
platforms = [pygame.Rect(0, 550, 800, 50), pygame.Rect(200, 450, 100, 20), pygame.Rect(400, 350, 100, 20)]
elif difficulty == "hard":
player_speed = 4
jump_power = -13
traps = [
pygame.Rect(350, 530, 50, 20),
pygame.Rect(250, 430, 50, 20),
pygame.Rect(500, 330, 50, 20)
]
platforms = [pygame.Rect(0, 550, 800, 50), pygame.Rect(200, 480, 80, 20), pygame.Rect(400, 360, 80, 20)]
player = pygame.Rect(100, 500, 50, 50)
gravity, y_velocity, on_ground = 1, 0, False
goal = pygame.Rect(700, 300, 50, 80)
clock = pygame.time.Clock()
while True:
screen.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit()
keys = pygame.key.get_pressed()
if keys[pygame.K_a]: player.x -= player_speed
if keys[pygame.K_d]: player.x += player_speed
if keys[pygame.K_SPACE] and on_ground:
y_velocity = jump_power; on_ground = False
# 중력 적용
y_velocity += gravity
player.y += y_velocity
on_ground = False
# 플랫폼 충돌
for plat in platforms:
if player.colliderect(plat) and y_velocity >= 0:
player.y = plat.y - player.height
y_velocity = 0
on_ground = True
# 트랩 충돌
for trap in traps:
if player.colliderect(trap):
print("죽음! 다시 시작")
player.x, player.y = 100, 500
y_velocity = 0
# 출구
if player.colliderect(goal):
print("클리어! 🎉")
player.x, player.y = 100, 500
y_velocity = 0
# 그리기
pygame.draw.rect(screen, BLACK, player)
for plat in platforms: pygame.draw.rect(screen, GREEN, plat)
for trap in traps: pygame.draw.rect(screen, RED, trap)
pygame.draw.rect(screen, BLUE, goal)
pygame.display.flip()
clock.tick(60)



