로그인

검색

Python
2013.11.21 23:15

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

MoA
조회 수 504 추천 수 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()

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

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 Tool/etc Programming 게시판 관련 2 MoA 2014.11.01 2477
247 서버 Design a Basic Search Engine (Google or Bing) | System Design Interview Prep OBG 2023.05.27 143
246 Tool/etc 잡담) AWS에 서버 띄워 놓으니 벼라별 리퀘스트가 다 날아 오네요 OBG 2023.03.11 144
245 Python FastAPI 톺아보기 - 부제: python 백엔드 봄은 온다 OBG 2023.01.25 146
244 Tool/etc 쿠버네티스 클러스터 OBG 2022.11.11 148
243 Site 개발에 도움되는 사이트 (초보 개발자 꿀팁) OBG 2023.01.28 148
242 Site 10 Useful/Fun/Weird Github Repos You Have to Play Around With OBG 2023.12.28 149
241 Tool/etc AWS 망 분리하기 OBG 2022.09.06 150
240 Deeplearning Reinforcement Learning for Dynamic Pricing Suggestion OBG 2023.04.01 153
239 서버 Debugging Node.js Memory Leaks: How to Detect, Solve or Avoid Them in Applications OBG 2023.07.04 154
238 Python 2048 Game in Python OBG 2022.09.22 155
237 Tool/etc How to stop programmers to copy the code from GitHub when they leave the company? OBG 2024.01.02 156
236 Deeplearning 추천 시스템 OBG 2023.03.30 157
235 Tool/etc AWS VPC 피어링 OBG 2022.11.03 157
234 Web Creating A Fixed-Length Queue In JavaScript Using Arrays OBG 2022.09.14 161
233 Deeplearning Keras를 활용한 주식 가격 예측 OBG 2022.09.02 161
232 Deeplearning The State of AI & Art 2022 1 OBG 2022.10.06 167
231 Tool/etc "Node.js를 떠나며" - express를 만든 TJ의 글 OBG 2022.06.23 168
230 서버 Golang Tutorial for Node.js Developers, Part I.: Getting started OBG 2022.06.16 170
229 Deeplearning Stable Diffusion OBG 2022.09.27 172
228 Site 모든 개발자를위한 10 가지 특별한 GitHub 리포지토리 OBG 2023.12.28 173
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15