Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added games/bgm/bubble_bobble.mp3
Binary file not shown.
Binary file added games/bgm/game_over.wav
Binary file not shown.
Binary file added games/bgm/pingpongbat.wav
Binary file not shown.
32 changes: 32 additions & 0 deletions games/pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@

pygame.init()

pygame.mixer.init()
pygame.mixer.music.load("bgm/bubble_bobble.mp3") # 게임 bgm
pygame.mixer.music.set_volume(0.3) # volume 조절 1 ~ 0.1
pygame.mixer.music.play(-1)

game_over = pygame.mixer.Sound("bgm/game_over.wav") # 종료 bgm
pingpong = pygame.mixer.Sound("bgm/pingpongbat.wav") # 게임 효과음


screen = pygame.display.set_mode((640,480),0,32)

#Creating 2 bars, a ball and background.
Expand Down Expand Up @@ -167,10 +176,14 @@ def paused():
if circle_y >= bar1_y - 7.5 and circle_y <= bar1_y + 42.5:
circle_x = 20.
speed_x = -speed_x
pygame.mixer.Sound.play(pingpong)

if circle_x >= bar2_x - 15.:
if circle_y >= bar2_y - 7.5 and circle_y <= bar2_y + 42.5:
circle_x = 605.
speed_x = -speed_x
pygame.mixer.Sound.play(pingpong)

if circle_x < 5.:
bar2_score += 1
circle_x, circle_y = 320., 232.5
Expand All @@ -182,9 +195,28 @@ def paused():
if circle_y <= 10.:
speed_y = -speed_y
circle_y = 10.
pygame.mixer.Sound.play(pingpong)

elif circle_y >= 457.5:
speed_y = -speed_y
circle_y = 457.5
pygame.mixer.Sound.play(pingpong)

if bar2_score == 10: # ai가 10점 달성시 종료 bgm
pygame.mixer.music.stop()
pygame.mixer.Sound.play(game_over)
game_over.set_volume(0.3)
# 게임 오버 메시지
msg = font.render("Game Over", True, (255, 255, 0))
screen.blit(msg, (230,260))
pygame.display.update()

# 4초 대기후 나가기
pygame.time.delay(4000)
pygame.quit()
exit()



pygame.display.update()

Expand Down
Binary file added games/rank.db
Binary file not shown.