Плохая синхронизация с музыкой и обнаружение нажатия нотыPython

Программы на Python
Anonymous
Плохая синхронизация с музыкой и обнаружение нажатия ноты

Сообщение Anonymous »

Я хотел бы реализовать и усовершенствовать механизм синхронизации ритм-игры, чтобы обеспечить плавный игровой процесс. Система должна:
Синхронизироваться с музыкой:
Убедиться, что игровой процесс точно соответствует времени музыкальной дорожки.
Визуальные и интерактивные элементы должны быть идеально синхронизированы с ритм и ритм музыки.
Обнаружение нажатия ноты:
Реализуйте точное обнаружение нажатия нот.
Убедитесь, что игра точно регистрирует, когда игрок нажимает ноту, синхронизация с ритмом музыки.
Улучшите скорость реагирования, чтобы минимизировать задержку и повысить точность.
from os import truncate
import pygame # type: ignore
import sys
import tkinter as tk
from mainmenu import beatmap_selected
import time

# variables

white = (255, 255, 255)
black = (0, 0, 0)
blue = (0, 175, 255)
grey = (175, 175, 175)
yellow = (255, 235, 0)
green = (0, 225, 55)
purple = (215, 0, 225)

combo = 0

key1_color = grey
key2_color = grey
key3_color = grey
key4_color = grey

screen_width = 400 * 1.25
screen_height = 850
radius = (screen_width // 8) - 5

col1 = [50 * 1.25, -100, 0]
col2 = [150 * 1.25, -100, 1]
col3 = [250 * 1.25, -100, 2]
col4 = [350 * 1.25, -100, 3]

no_note = True

current_time = 0
start_time = 120 / 1000.0

perfect_timer = 0
perfect_note_hit = False

good_timer = 0
good_note_hit = False

bad_timer = 0
bad_note_hit = False

# counters
key_num_set = 0

# arrays

notes = []
seconds = []
circles_on_scene = []
keys = [False, False, False, False]

durations = []
# functions

def set_notes():
with open(f"beatmaps/{beatmap_selected}/notes.txt", "r", encoding="utf-8") as file:
lineas = file.readlines()
for linea in lineas:
note = linea.split()
seconds.append(float(note[0]))
notes.append(int(note[1]))
if len(note) > 2:
durations.append(float(note[2]))
else:
durations.append(
0
) # Si no hay duración especificada, se asume nota regular

def display_keys():
pygame.draw.circle(screen, key1_color, (col1[0], 700), radius)
pygame.draw.circle(screen, key2_color, (col2[0], 700), radius)
pygame.draw.circle(screen, key3_color, (col3[0], 700), radius)
pygame.draw.circle(screen, key4_color, (col4[0], 700), radius)

def create_circle():

global key_num_set
global no_note

key_num = notes[key_num_set]

if key_num == 1:
col = col1.copy()
color = white
elif key_num == 2:
col = col2.copy()
color = blue
elif key_num == 3:
col = col3.copy()
color = blue
elif key_num == 4:
col = col4.copy()
color = white
else:
no_note = True

if not no_note:
circles_on_scene.append((screen, color, col, radius))

key_num_set += 1

def perfect_note():

global perfect_timer
global perfect_note_hit

if perfect_note_hit:
screen.blit(perfect_text, perfect_center)
perfect_timer += 1
if perfect_timer >= 5:
perfect_note_hit = False
perfect_timer = 0

def good_note():

global good_timer
global good_note_hit

if good_note_hit:
screen.blit(good_text, good_center)
good_timer += 1
if good_timer >= 5:
good_note_hit = False
good_timer = 0

def bad_note():

global bad_timer
global bad_note_hit

if bad_note_hit:
screen.blit(bad_text, bad_center)
bad_timer += 1
if bad_timer >= 5:
bad_note_hit = False
bad_timer = 0

circle_speed = 2.5

def update_circles():
global combo
global perfect_note_hit
global good_note_hit
global bad_note_hit
global no_note

hit_detected = [
False
] * 4 # Bandera para detectar si una nota fue golpeada para cada columna

if not no_note:
for circle in circles_on_scene[:]:
pygame.draw.circle(
circle[0], circle[1], (circle[2][0], circle[2][1]), circle[3]
)
fpscirlcespeed = circle_speed * dt * targetfps
circle[2][1] += fpscirlcespeed

if (
seconds[seconds_set] - 0.03

Подробнее здесь: https://stackoverflow.com/questions/788 ... is-pressed

Вернуться в «Python»