import pygame
import random
# Inisialisasi Pygame
pygame.init()
# Ukuran layar
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
# Warna
white = (255, 255, 255)
black = (0, 0, 0)
# Judul dan ikon
pygame.display.set_caption("Game Musik")
icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)
# Memuat musik
pygame.mixer.music.load('music.mp3')
# Fungsi untuk menampilkan teks
def show_text(text, font_size, color, x, y):
font = pygame.font.Font(None, font_size)
text_surface = font.render(text, True, color)
screen.blit(text_surface, (x, y))
# Fungsi utama
def main():
running = True
score = 0
pygame.mixer.music.play(-1) # Memutar musik secara berulang
while running:
screen.fill(white)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
score += 1
show_text(f"Score: {score}", 36, black, 10, 10)
pygame.display.update()
pygame.quit()
if __name__ == "__main__":
main()
Tidak ada komentar:
Posting Komentar