So I am making a zombie shooter game in pygame. I have a player – a zombie list – and a bullets list. all of them are rectangles. I need to detect the collision between all the bullets and all zombies. – i tried colliderect but and collidelist but that is between a object and a list. I want a
Tag: pygame
Pygame: How to display a new box when user clicks an area, and close the box when the user clicks again
I am new to python and pygame and I am developing a weather app as a project to learn both. I want to display a new rectangle when a user is clicking an area (=button) of the screen. The new rectangle should be visible until the user clicks again, this time anywhere on the screen. I have my main loop
Attribute Error: List object has no attribute CheckClick
In the Swap function, I am checking under some index a button class instance, which I checked using print statements, but for some reason it still gives me an error saying that it has no such attribute check click. Any tips on formatting are also welcome, I am just a beginner. I am using three different arrays to hold various
What does ”event.pos[0]” mean in the pygame library? I saw an example using it to get the X axis of the cursor and ignore the Y axis
I don’t understand how it works. I don’t know if I understood the purpose of this function wrong. I tried to search what posx=event.pos[0] means but all I found was that if you want to take x, write the code of posx,posy=pygame.mouse.get_pos() and then take posx. But I still can’t understand the method he followed in the example I saw.
How do I add a border to a sprite when the mouse hovers over it, and delete it after the mouse stops?
I have a sprite, and I want it to be so that when the mouse hovers over it, it places a small border around the sprite, and when it leaves, delete that border. How would I go about doing this? Sprite Class: I can add more code if required. Thank you! Answer Copy the image and draw a rectangle around
How do you shoot a bullet towards mouse in pygame at a constant speed?
I am trying to shoot a bullet towards my mouse in pygame, here is my code: I am confused on how to make this work, I think somehow I am rounding something, but even after I put float() in, it still is not working. Also, before when I used the mouse coordinates, it works, but when close to tank, it
Python/Pygame : “pygame.error: display Surface quit”
So, I’m making a game project, and I decided, for once, to make a custom class for my pygame window, like so : And, in the gameloop, I decided to make an instance of this class, and to call the method, like so : But when I try to run the main loop, it gives me this error message (that
Python Pygame after closing with pygame.quit() I can’t open it again without stoping the whole script and restarting it
I want to close the Pygame-Window after a specific event occurred and open it again after another event occurred without stopping the whole script. When I stop pygame with pygame.quit() and want to register a font or do whatever it gives me an error that says that pygame is not initialized so I coded it so it would call pygame.init()
How does Pygame know what is layer 1 (background) vs the sprites displayed on the screen?
My teacher was looking over my code today and wanted me to explain to him why I could use and pygame knew to make the bg.png file the background and the player/enemy.png in the foreground. I explained that maybe it was due to bg.png taking the HEIGHT and WIDTH arg therefore stretching the whole screen, but almost immediately I saw
How can a busy-wait loop be avoided for an event driven program?
I’m coding a chess game in python using pygame. One of the common tasks is the need to handle events, and the only way I know how to do it is like this: The while loop just keeps spinning, which is inefficient. In embedded programming, you can send the cpu to sleep until there is an interrupt. Is there a