Closed Schnitzyy closed 1 year ago
most likely an infinite loop, that's what the simulator will help solving in next release.
Could you show whole project or at very least the game loop part
async def main():
while True:
global game_running, score, player_gravity
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if game_running:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
if player_rect.bottom == 300:
player_gravity = -20
if event.type == pygame.MOUSEBUTTONDOWN:
if player_rect.collidepoint((event.pos)):
if player_rect.bottom == 300:
player_gravity = -20
else:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
if not game_running:
game_running = True
start_time = pygame.time.get_ticks()
if game_running:
score = display_score()
# Draw a surface
SCREEN.blit(sky_surf, (0,0))
SCREEN.blit(ground_surf, ground_rect)
# Obstacle Movement
# obstacle_rect_list = obstacle_movement(obstacle_rect_list)
# Player
player_gravity += 1
player_rect.y += player_gravity
if player_rect.bottom > 300:
player_rect.bottom = 300
SCREEN.blit(player_surf, player_rect)
display_score()
# pygame.draw.rect(SCREEN,'#c0e8ec', score_rect)
# pygame.draw.rect(SCREEN,'#c0e8ec', score_rect, 10)
# SCREEN.blit(score_surf, score_rect)
SCREEN.blit(snail_surf, snail_rect)
snail_rect.left -= random.randint(3,4)
if snail_rect.right <= 0:
snail_rect.x = 800
# Collisions
if snail_rect.colliderect(player_rect):
game_running = False
else:
SCREEN.fill((94,129,162))
SCREEN.blit(player_stand, player_stand_rect)
SCREEN.blit(start_text_surf1, start_text_surf1_rect)
score_message = test_font.render(f'Your score: {score}', False, (111,196,169))
score_message_rect = score_message.get_rect(center = (400, 330))
if score == 0:
SCREEN.blit(start_text_surf2, start_text_surf2_rect)
else:
SCREEN.blit(score_message, score_message_rect)
snail_rect.left = 800
if event.type == obstacle_timer and game_running:
obstacle_rect_list.append(snail_surf.get_rect(bottomright = (random.randint(900, 1100), 300)))
# end_music()
# Update everything
pygame.display.update()
clock.tick(60)
await asyncio.sleep(0)
asyncio.run(main())
try adding one indent level before await asyncio.sleep(0)
Oh okay that worked previously when I kept an indent there it gave me an error, but it works now. BTW does pygbag not support sound?
it does but some browsers will not tolerate .mp3, but all go along with .ogg, you should have a look to https://pygame-web.github.io "IMPORTANT ALL" section, other restrictions can apply
for background music, prefer the module pygame.mixer.music it has been optimized for web