-1

I would like to create a connect 4 program. Everything is fine but I would like to animate the falling of the bricks.

A quick and dirty solution is working fine (Brick is falling in front of the grid) but I would like the falling of the bricks behind the grid.

I found something in the net (how to make circular surface in pygame).

import pygame
pygame.init()
window = pygame.display.set_mode((750, 750))

color = (255,255,255)
run = True
z = 20
while run:
    z += 5
    #print(z)
    background = pygame.Surface(window.get_size())   
    pygame.draw.rect(background, color, (10, 10 + z, 100, 100))


    size = background.get_size()
    cropped_background = pygame.Surface(size, pygame.SRCALPHA)
    for x in range(5):
        for y in range(5):
            pygame.draw.ellipse(cropped_background, (255,255,255,255), (((x*100) + (x*10) +10) , ((y*100) + (y*10) +10), 100,100))
            cropped_background.blit(background, (0, 0), special_flags=pygame.BLEND_RGBA_MIN)

    window.fill(255)
    window.blit(cropped_background, (0, 0))
    pygame.display.update()

Can someone explain me why it is going into freeze mode and have a solution for me?

But if I animate this, python is going into freeze mode after a couple of seconds.

  • 1
    You are not going through the pygame event loop and checking for, say, quit events. I suggest looking at some extremely basic existing pygame projects to see how they all do it. That line, `for event in pygame.event.get()`, that you see in app pygame projects? It turns out it's actually extremely important. Don't get in the habit of ignoring code you don't understand; if you don't understand it, learn what it does. – Random Davis Aug 31 '23 at 18:38
  • Ok thanks a lot. Unti now I used pygame.event.get() only for users interactions and I implement at least the Quit statement. Doesn't know that it have consequences if I doesn't use it. – TripleM259 Sep 01 '23 at 09:29

0 Answers0