I built a Connect 4 game with Pygame and am trying to get it to run in a browser using pygbag, but I keep getting a page unresponsive error. When I try to run it in a browser there is a start button, and when I click that I get to see the connect 4 board, but then I get the page unresponsive error. Let me know if you know what could be causing this error. Here is my code for the main game loop:
async def main():
game_over = False
turn = AI
while not game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.MOUSEMOTION:
pygame.draw.rect(screen, BLACK, (0, 0, width, SQUARESIZE))
posx = event.pos[0]
if turn == PLAYER:
pygame.draw.circle(screen, RED, (posx, int(SQUARESIZE / 2)), RADIUS)
pygame.display.update()
if event.type == pygame.MOUSEBUTTONDOWN:
pygame.draw.rect(screen, BLACK, (0, 0, width, SQUARESIZE))
# print(event.pos)
# Ask for Player 1 Input
if turn == PLAYER:
posx = event.pos[0]
col = int(math.floor(posx / SQUARESIZE))
if is_valid_location(board, col):
row = get_next_open_row(board, col)
drop_piece(board, row, col, PLAYER_PIECE)
if winning_move(board, PLAYER_PIECE):
label = myfont.render("Player 1 wins!!", 1, RED)
screen.blit(label, (40, 10))
game_over = True
turn += 1
turn = turn % 2
# print_board(board)
draw_board(board)
# # Ask for Player 2 Input
if turn == AI and not game_over:
# col = random.randint(0, COLUMN_COUNT-1)
# col = pick_best_move(board, AI_PIECE)
col, minimax_score = minimax(board, 5, -math.inf, math.inf, True)
if is_valid_location(board, col):
# pygame.time.wait(500)
row = get_next_open_row(board, col)
drop_piece(board, row, col, AI_PIECE)
if winning_move(board, AI_PIECE):
label = myfont.render("Player 2 wins!!", 1, YELLOW)
screen.blit(label, (40, 10))
game_over = True
# print_board(board)
draw_board(board)
turn += 1
turn = turn % 2
if game_over:
pygame.time.wait(3000)
await asyncio.sleep(0)
asyncio.run(main())