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 bgm/bubble_bobble.wav
Binary file not shown.
Binary file added bgm/click.wav
Binary file not shown.
Binary file added bgm/game_over.wav
Binary file not shown.
Binary file added bgm/pingpongbat.wav
Binary file not shown.
40 changes: 28 additions & 12 deletions games/pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@

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)
# # modify +++++++++++++++++++++++++++++++++++++++ 오은상

game_over = pygame.mixer.Sound("bgm/game_over.wav") # 종료 bgm
pingpong = pygame.mixer.Sound("bgm/pingpongbat.wav") # 게임 효과음
music = os.path.join('bgm','bubble_bobble.wav')
bgm = pygame.mixer.Sound(music)
bgm.play(-1)
bgm.set_volume(0.3)

music2 = os.path.join('bgm',"game_over.wav")
game_over = pygame.mixer.Sound(music2)

music3 = os.path.join('bgm',"pingpongbat.wav")
pingpong = pygame.mixer.Sound(music3)

music4 = os.path.join('bgm', "click.wav")
click = pygame.mixer.Sound(music4)
# # +++++++++++++++++++++++++++++++++++++++++++


screen = pygame.display.set_mode((640,480),0,32)
Expand Down Expand Up @@ -232,11 +241,14 @@ def intro():
continue
if event.type == pygame.MOUSEBUTTONDOWN:
if StartButton.isOver(pos):
click.play()
i=False
elif RankingButton.isOver(pos):
click.play()
i=False
pg_rank()
elif QuitButton.isOver(pos):
click.play()
pygame.quit()
quit()
image = pygame.image.load(pong_title_path)
Expand Down Expand Up @@ -335,13 +347,13 @@ def action():
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)
pingpong.play()

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)
pingpong.play()

if circle_x < 5.:
bar2_score += 1
Expand All @@ -354,18 +366,21 @@ def action():
if circle_y <= 10.:
speed_y = -speed_y
circle_y = 10.
#pygame.mixer.Sound.play(pingpong)
pingpong.play()

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


#modify **************************************************** 오은상

if bar2_score == 10: # ai가 10점 달성시 종료 bgm
c.execute("INSERT INTO users('username', 'score', 'regdate') VALUES(?,?,?)", \
('playern', bar1_score, nowDatetime))
pygame.mixer.music.stop()
pygame.mixer.Sound.play(game_over)
bgm.stop()
game_over.play()
game_over.set_volume(0.3)
# 게임 오버 메시지
msg = font.render("Game Over", True, (255, 255, 0))
Expand All @@ -377,6 +392,7 @@ def action():
pygame.quit()
exit()

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


pygame.display.update()
Expand Down