import os
import pygame
import random
###################################################################
# 기본 초기화 (반드시 해야 하는 것듯)
pygame.init()

#  화면 크기 설정
screen_width = 480
screen_height = 640

screen = pygame.display.set_mode((screen_width, screen_height))

# 화면 타이틀
pygame.display.set_caption("똥피하기 게임")

# FPS
clock = pygame.time.Clock()
###################################################################

# 1. 사용자 세임 초기화 (배경화면, 게임 이미지, 좌표, 속도, 폰트 등)
current_path = os.path.dirname(__file__)  # 현재 파일의 위치
print(current_path)

background = pygame.image.load("%s/background.jpg" % (current_path))

character = pygame.image.load("%s/dog.jpg" % (current_path))
character_size = character.get_rect().size
character_width = character_size[0]
character_height = character_size[1]
character_x_pos = (screen_width / 2) - (character_width /2)
character_y_pos = screen_height - character_height

enemy = pygame.image.load("%s/ddong.jpg" % (current_path))
enemy_size = enemy.get_rect().size
enemy_width = enemy_size[0]
enemy_height = enemy_size[1]
enemy_x_pos = random.randint(0, screen_width - character_width)
enemy_y_pos = 0

game_font = pygame.font.Font(None, 40)


to_x = 0
character_speed = .3
enemy_speed = .5

score = 0


running = True 
while running:
    dt = clock.tick(60)

    # 2. 이벤트 처리(키보드, 마우스 등)
    for event in pygame.event.get(): 
        if event.type == pygame.QUIT:
            running = False
        
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                to_x -= character_speed
            elif event.key == pygame.K_RIGHT:
                to_x += character_speed
        
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                to_x = 0


    # 3. 게임 캐릭터 위치 정의
    character_x_pos += to_x * dt

    enemy_y_pos += enemy_speed * dt

    if enemy_y_pos > screen_height:
        enemy_y_pos = 0
        enemy_x_pos = random.randint(0, screen_width - character_width)
        score += 12


    if character_x_pos < 0:
        character_x_pos = 0
    elif character_x_pos > screen_width - character_width:
        character_x_pos = screen_width - character_width
    
    # 4. 충돌 처리
    character_rect = character.get_rect()
    character_rect.left = character_x_pos
    character_rect.top = character_y_pos

    enemy_rect = enemy.get_rect()
    enemy_rect.left = enemy_x_pos
    enemy_rect.top = enemy_y_pos


    if character_rect.colliderect(enemy_rect):
        print("게임오버")
        print("당신의 총 점수는: %s점 입니다." % (score))
        running = False

    # 5. 화면에 그리기

    screen.blit(background, (0, 0))
    screen.blit(character, (character_x_pos, character_y_pos))
    screen.blit(enemy, (enemy_x_pos, enemy_y_pos))

    total_score = game_font.render(str(score), True, (0, 0, 0))
    screen.blit(total_score, (10, 10))

    pygame.display.update()

pygame.quit()
f4a21e101ac2adb369dbb551ca71df9098b52e06
<mask token>

<mask token>
pygame.init()
<mask token>
pygame.display.set_caption('똥피하기 게임')
<mask token>
print(current_path)
<mask token>
while running:
    dt = clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                to_x -= character_speed
            elif event.key == pygame.K_RIGHT:
                to_x += character_speed
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                to_x = 0
    character_x_pos += to_x * dt
    enemy_y_pos += enemy_speed * dt
    if enemy_y_pos > screen_height:
        enemy_y_pos = 0
        enemy_x_pos = random.randint(0, screen_width - character_width)
        score += 12
    if character_x_pos < 0:
        character_x_pos = 0
    elif character_x_pos > screen_width - character_width:
        character_x_pos = screen_width - character_width
    character_rect = character.get_rect()
    character_rect.left = character_x_pos
    character_rect.top = character_y_pos
    enemy_rect = enemy.get_rect()
    enemy_rect.left = enemy_x_pos
    enemy_rect.top = enemy_y_pos
    if character_rect.colliderect(enemy_rect):
        print('게임오버')
        print('당신의 총 점수는: %s점 입니다.' % score)
        running = False
    screen.blit(background, (0, 0))
    screen.blit(character, (character_x_pos, character_y_pos))
    screen.blit(enemy, (enemy_x_pos, enemy_y_pos))
    total_score = game_font.render(str(score), True, (0, 0, 0))
    screen.blit(total_score, (10, 10))
    pygame.display.update()
pygame.quit()

<mask token>
pygame.init()
screen_width = 480
screen_height = 640
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('똥피하기 게임')
clock = pygame.time.Clock()
current_path = os.path.dirname(__file__)
print(current_path)
background = pygame.image.load('%s/background.jpg' % current_path)
character = pygame.image.load('%s/dog.jpg' % current_path)
character_size = character.get_rect().size
character_width = character_size[0]
character_height = character_size[1]
character_x_pos = screen_width / 2 - character_width / 2
character_y_pos = screen_height - character_height
enemy = pygame.image.load('%s/ddong.jpg' % current_path)
enemy_size = enemy.get_rect().size
enemy_width = enemy_size[0]
enemy_height = enemy_size[1]
enemy_x_pos = random.randint(0, screen_width - character_width)
enemy_y_pos = 0
game_font = pygame.font.Font(None, 40)
to_x = 0
character_speed = 0.3
enemy_speed = 0.5
score = 0
running = True
while running:
    dt = clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                to_x -= character_speed
            elif event.key == pygame.K_RIGHT:
                to_x += character_speed
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                to_x = 0
    character_x_pos += to_x * dt
    enemy_y_pos += enemy_speed * dt
    if enemy_y_pos > screen_height:
        enemy_y_pos = 0
        enemy_x_pos = random.randint(0, screen_width - character_width)
        score += 12
    if character_x_pos < 0:
        character_x_pos = 0
    elif character_x_pos > screen_width - character_width:
        character_x_pos = screen_width - character_width
    character_rect = character.get_rect()
    character_rect.left = character_x_pos
    character_rect.top = character_y_pos
    enemy_rect = enemy.get_rect()
    enemy_rect.left = enemy_x_pos
    enemy_rect.top = enemy_y_pos
    if character_rect.colliderect(enemy_rect):
        print('게임오버')
        print('당신의 총 점수는: %s점 입니다.' % score)
        running = False
    screen.blit(background, (0, 0))
    screen.blit(character, (character_x_pos, character_y_pos))
    screen.blit(enemy, (enemy_x_pos, enemy_y_pos))
    total_score = game_font.render(str(score), True, (0, 0, 0))
    screen.blit(total_score, (10, 10))
    pygame.display.update()
pygame.quit()

import os
import pygame
import random
pygame.init()
screen_width = 480
screen_height = 640
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('똥피하기 게임')
clock = pygame.time.Clock()
current_path = os.path.dirname(__file__)
print(current_path)
background = pygame.image.load('%s/background.jpg' % current_path)
character = pygame.image.load('%s/dog.jpg' % current_path)
character_size = character.get_rect().size
character_width = character_size[0]
character_height = character_size[1]
character_x_pos = screen_width / 2 - character_width / 2
character_y_pos = screen_height - character_height
enemy = pygame.image.load('%s/ddong.jpg' % current_path)
enemy_size = enemy.get_rect().size
enemy_width = enemy_size[0]
enemy_height = enemy_size[1]
enemy_x_pos = random.randint(0, screen_width - character_width)
enemy_y_pos = 0
game_font = pygame.font.Font(None, 40)
to_x = 0
character_speed = 0.3
enemy_speed = 0.5
score = 0
running = True
while running:
    dt = clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                to_x -= character_speed
            elif event.key == pygame.K_RIGHT:
                to_x += character_speed
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                to_x = 0
    character_x_pos += to_x * dt
    enemy_y_pos += enemy_speed * dt
    if enemy_y_pos > screen_height:
        enemy_y_pos = 0
        enemy_x_pos = random.randint(0, screen_width - character_width)
        score += 12
    if character_x_pos < 0:
        character_x_pos = 0
    elif character_x_pos > screen_width - character_width:
        character_x_pos = screen_width - character_width
    character_rect = character.get_rect()
    character_rect.left = character_x_pos
    character_rect.top = character_y_pos
    enemy_rect = enemy.get_rect()
    enemy_rect.left = enemy_x_pos
    enemy_rect.top = enemy_y_pos
    if character_rect.colliderect(enemy_rect):
        print('게임오버')
        print('당신의 총 점수는: %s점 입니다.' % score)
        running = False
    screen.blit(background, (0, 0))
    screen.blit(character, (character_x_pos, character_y_pos))
    screen.blit(enemy, (enemy_x_pos, enemy_y_pos))
    total_score = game_font.render(str(score), True, (0, 0, 0))
    screen.blit(total_score, (10, 10))
    pygame.display.update()
pygame.quit()

import os
import pygame
import random
###################################################################
# 기본 초기화 (반드시 해야 하는 것듯)
pygame.init()

#  화면 크기 설정
screen_width = 480
screen_height = 640

screen = pygame.display.set_mode((screen_width, screen_height))

# 화면 타이틀
pygame.display.set_caption("똥피하기 게임")

# FPS
clock = pygame.time.Clock()
###################################################################

# 1. 사용자 세임 초기화 (배경화면, 게임 이미지, 좌표, 속도, 폰트 등)
current_path = os.path.dirname(__file__)  # 현재 파일의 위치
print(current_path)

background = pygame.image.load("%s/background.jpg" % (current_path))

character = pygame.image.load("%s/dog.jpg" % (current_path))
character_size = character.get_rect().size
character_width = character_size[0]
character_height = character_size[1]
character_x_pos = (screen_width / 2) - (character_width /2)
character_y_pos = screen_height - character_height

enemy = pygame.image.load("%s/ddong.jpg" % (current_path))
enemy_size = enemy.get_rect().size
enemy_width = enemy_size[0]
enemy_height = enemy_size[1]
enemy_x_pos = random.randint(0, screen_width - character_width)
enemy_y_pos = 0

game_font = pygame.font.Font(None, 40)


to_x = 0
character_speed = .3
enemy_speed = .5

score = 0


running = True 
while running:
    dt = clock.tick(60)

    # 2. 이벤트 처리(키보드, 마우스 등)
    for event in pygame.event.get(): 
        if event.type == pygame.QUIT:
            running = False
        
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                to_x -= character_speed
            elif event.key == pygame.K_RIGHT:
                to_x += character_speed
        
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                to_x = 0


    # 3. 게임 캐릭터 위치 정의
    character_x_pos += to_x * dt

    enemy_y_pos += enemy_speed * dt

    if enemy_y_pos > screen_height:
        enemy_y_pos = 0
        enemy_x_pos = random.randint(0, screen_width - character_width)
        score += 12


    if character_x_pos < 0:
        character_x_pos = 0
    elif character_x_pos > screen_width - character_width:
        character_x_pos = screen_width - character_width
    
    # 4. 충돌 처리
    character_rect = character.get_rect()
    character_rect.left = character_x_pos
    character_rect.top = character_y_pos

    enemy_rect = enemy.get_rect()
    enemy_rect.left = enemy_x_pos
    enemy_rect.top = enemy_y_pos


    if character_rect.colliderect(enemy_rect):
        print("게임오버")
        print("당신의 총 점수는: %s점 입니다." % (score))
        running = False

    # 5. 화면에 그리기

    screen.blit(background, (0, 0))
    screen.blit(character, (character_x_pos, character_y_pos))
    screen.blit(enemy, (enemy_x_pos, enemy_y_pos))

    total_score = game_font.render(str(score), True, (0, 0, 0))
    screen.blit(total_score, (10, 10))

    pygame.display.update()

pygame.quit()