I'm currently making a rhythm game in Pygame and I have been trying to output "notes", but in my sprite class they are called enemies for a separate reason, based on the current time being the same(ish) to floats in a text file. However when I try to use the loop whether it be an infinite for loop or a while loop it cause the window to freeze whilst it's activated. I have tried pygame.event.pump() but that just makes it so that after the loop has ended it is no longer frozen.
Anything commented is what I have tried already.
import pygame
from sys import exit
class Enemies(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.image.load(r'\slime.png').convert_alpha()
self.image = pygame.transform.rotozoom(self.image,0,4)
self.rect = self.image.get_rect(center = (1040,-50))
# def d_notes(self):
# keys = pygame.key.get_pressed()
# if keys[pygame.K_SPACE]:
# maps = beat_read()
# temp = list(maps)
# note = 0
# p_note = 0
# for x in iter(int, 1):
# pygame.event.pump()
# pygame.event.pump()
# if p_note == len(maps):
# break
# current_time = (pygame.time.get_ticks() / 1000) - start_time
# x_lower = maps[note] - 0.02
# x_upper = maps[note] + 0.02
# if x_lower <= current_time <= x_upper:
# out = temp.pop(0)
# print(out)
# note = note + 1
# p_note = p_note + 1
def update(self):
self.rect.y +=5
#self.d_notes()
def beat_read():
with open(r'\simple.txt') as f:
ll = []
for x in f:
x = float(x)
ll.append(x)
ll = tuple(ll)
return ll
# def d_notes():
# maps = beat_read()
# temp = list(maps)
# note = 0
# p_note = 0
# for x in iter(int,1):
# pygame.event.pump()
# pygame.event.pump()
# if p_note == len(maps):
# break
# current_time = (pygame.time.get_ticks() / 1000) - start_time
# x_lower = maps[note] - 0.02
# x_upper = maps[note] + 0.02
# if x_lower <= current_time <= x_upper:
# out = temp.pop(0)
# print(out)
# note = note + 1
# p_note = p_note + 1
# print(note)
# print(maps)
# print(temp)
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((1366,850))
pygame.display.set_caption('Rhythmic')
game_active = False
enemies_group = pygame.sprite.Group()
enemies_group.add(Enemies())
background = pygame.image.load(r'\background.png').convert()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
game_active = True
start_time = pygame.time.get_ticks() / 1000
# maps = beat_read()
# temp = list(maps)
# note = 0
# p_note = 0
# for x in iter(int, 1):
# pygame.event.pump()
# pygame.event.pump()
# if p_note == len(maps):
# break
# current_time = (pygame.time.get_ticks() / 1000) - start_time
# x_lower = maps[note] - 0.02
# x_upper = maps[note] + 0.02
# if x_lower <= current_time <= x_upper:
# out = temp.pop(0)
# print(out)
# note = note + 1
# p_note = p_note + 1
if game_active:
# d_notes()
screen.blit(background,(0,0))
enemies_group.draw(screen)
enemies_group.update()
pygame.display.flip()
clock.tick(60)