로그인

검색

Python
2013.11.21 23:15

[첫게임 만들기] 9. 사운드

MoA
조회 수 3543 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄 첨부

이제 거의 다 왔다. 8강까지 제작한 게임으로도 충분히 재밌게 즐길 수 있다. 하지만 그래도 뭔가 아쉽다라는 느낌이 든다. 사운드가 없다.

사운드를 출력하기 위해 mixer를 초기화하고 사운드를 불러온다. 3번 코드 다음에 추가한다.

 

# 3.1 - mixer 초기화
pygame.mixer.init()

# 3.2 - 사운드를 불러온다
hit = pygame.mixer.Sound("resources/audio/explode.wav")
enemy = pygame.mixer.Sound("resources/audio/enemy.wav")
shoot = pygame.mixer.Sound("resources/audio/shoot.wav")
hit.set_volume(0.05)
enemy.set_volume(0.05)
shoot.set_volume(0.05)

# 배경 음악
pygame.mixer.music.load('resources/audio/moonlight.wav')
pygame.mixer.music.play(-1, 0.0)
pygame.mixer.music.set_volume(0.25)

이제 필요한 곳에 사운드를 삽입하면 된다.

 

# section 6.4.2.1의 if badrect.left<64: 구문 안 마지막에
hit.play()
# section 6.4.2.2의 if badrect.colliderect(bullrect): 구문 안 마지막에
enemy.play()
# section 8의 if event.type==pygame.MOUSEBUTTONDOWN: 구문 안 마지막에
shoot.play()

이제 모든 작업이 끝났다. 다음에는 코드를 정리하고 배포하는 것까지 시도해보자.

?

  1. Programming 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views15456
    read more
  2. AWS 망 분리하기

    Date2022.09.06 CategoryTool/etc ByOBG Views2801
    Read More
  3. AWS VPC 피어링

    Date2022.11.03 CategoryTool/etc ByOBG Views3048
    Read More
  4. ASCII 3D 렌더러 만들기

    Date2024.06.03 CategoryGraphic ByOBG Views2284
    Read More
  5. AS3 Code Library

    Date2013.10.11 CategoryLibrary ByMoA Views6857
    Read More
  6. Anthropic, LLM의 내부를 이해하는데 있어 상당한 진전을 보임

    Date2024.06.03 CategoryLLM ByOBG Views2265
    Read More
  7. AI-hub 공공데이터를 활용하여 한국어-영어 번역 LLM 만들기

    Date2025.01.14 CategoryLLM ByOBG Views1570
    Read More
  8. Address Bar Install for Progressive Web Apps on the Desktop

    Date2021.12.15 CategoryWeb ByOBG Views2462
    Read More
  9. A Beginner's Guide to Prompt Engineering with GitHub Copilot

    Date2024.04.04 CategoryLLM ByOBG Views1786
    Read More
  10. 2048게임 높은 점수 얻기 위한 알고리즘

    Date2014.03.29 CategoryAlgorithm ByMoA Views3161
    Read More
  11. 2048 Game in Python

    Date2022.09.22 CategoryPython ByOBG Views2940
    Read More
  12. 2024년 가장 조회수 높은 소프트웨어 엔지니어링 발표들

    Date2025.02.18 CategorySite ByOBG Views1406
    Read More
  13. 2016년에 자바스크립트를 배우는 기분

    Date2016.12.27 CategoryTool/etc ByMoA Views2615
    Read More
  14. 10 Useful/Fun/Weird Github Repos You Have to Play Around With

    Date2023.12.28 CategorySite ByOBG Views2803
    Read More
  15. #pragma

    Date2013.07.28 CategoryAPI/MFC ByMoA Views2618
    Read More
  16. "Node.js를 떠나며" - express를 만든 TJ의 글

    Date2022.06.23 CategoryTool/etc ByOBG Views2401
    Read More
  17. [한빛미디어] 머신러닝·딥러닝 도서 선택 가이드

    Date2023.06.11 CategoryDeeplearning ByOBG Views2652
    Read More
  18. [첫게임 만들기] 9. 사운드

    Date2013.11.21 CategoryPython ByMoA Views3543
    Read More
  19. [첫게임 만들기] 8. Win or Lose

    Date2013.11.21 CategoryPython ByMoA Views3210
    Read More
  20. [첫게임 만들기] 7. 게임 정보 표시

    Date2013.11.21 CategoryPython ByMoA Views3929
    Read More
  21. [첫게임 만들기] 6. 적을 해치우자

    Date2013.11.21 CategoryPython ByMoA Views3717
    Read More
Board Pagination Prev 1 ... 6 7 8 9 10 11 12 13 14 15 Next
/ 15