This repository was archived by the owner on Mar 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsolucao_desafio3.py
More file actions
57 lines (43 loc) · 1.43 KB
/
solucao_desafio3.py
File metadata and controls
57 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SOLUÇÃO DO DESAFIO 3
---
Construa um jogo com dois retângulos na tela.
Cada um deve tocar uma música específica ao
ser clicado.
"""
import pygame
from pathlib import Path
DIRETORIO_ATUAL = str(Path(__file__).parent.absolute())
pygame.mixer.pre_init(44100, 16, 2, 1024)
pygame.init()
tela = pygame.display.set_mode([130, 70])
clock = pygame.time.Clock()
quadro1 = pygame.Rect(10, 10, 50, 50)
quadro2 = pygame.Rect(70, 10, 50, 50)
musicas = [
DIRETORIO_ATUAL + "/src/musicas/musica1.wav",
DIRETORIO_ATUAL + "/src/musicas/musica2.wav",
]
executando = True
while executando:
for evento in pygame.event.get():
if evento.type == pygame.QUIT:
executando = False
if evento.type == pygame.MOUSEBUTTONDOWN:
if quadro1.collidepoint(pygame.mouse.get_pos()):
pygame.mixer.music.stop()
pygame.mixer.music.load(musicas[0])
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play()
elif quadro2.collidepoint(pygame.mouse.get_pos()):
pygame.mixer.music.stop()
pygame.mixer.music.load(musicas[1])
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play()
pygame.draw.rect(tela, (255, 0, 0), quadro1)
pygame.draw.rect(tela, (0, 255, 0), quadro2)
clock.tick(30)
pygame.display.update()
pygame.quit()