Skip to content
Advertisement

Tag: pygame

Pygame Collision detection `colliderect()`

While going through the docs of pygame, there was a method of pygame called colliderect() that is used to test if two rect objects have overlapped. colliderect() test if two rectangles overlap colliderect(Rect) -> bool Returns true if any portion of either rectangle overlap (except the top+bottom or left+right edges). In the last line , it said except the top+bottom

Pong in Pygame won’t count score

This is what I’ve got set-up, and I don’t want to be hand-fed the code as this is for a school project. I am still working on collision but I am not sure why the score being displayed isn’t being updated. I tried to set up the score update as a Dot method and then implement that method into the

Pygame: how to write event-loop polymorphically

I’m some-what new to pygame, and while trying to get back into it, I found the advice “replace your conditionals with polymorphism.” Most pygame tutorials recommend using the “for event in pygame.event.get()” loop and then using a conditional to determine if any particular event has occured. 1: How do I write that code using a polymorphic function 2: Is it

Function name not defined error when i try to use recursion

I want to make a player that can shoot bullets. To do this i tried defining a shoot function that gets called when space bar is pressed. The function looks like this (p is the player object btw): I was hoping that the function would keep calling itself and the bullet would keep moving forward. However what actually happens is

Pygame window not showing up

I recently downloaded pygame on my Mac, but for some reason, the window does not pop up with the screen or anything. I don’t get an error message, it just runs but doesn’t actually pop up a display. Answer Your code is currently starting, drawing a red rectangle in a window, and then ending immediatly. You should probably wait for

Pygame collision with masks

I have made a putt-putt game and now I want to add a slanted wall type. Because of this, I need to use masks for the collision (until now I have just used rects). I have spent hours learning about masks and trying to figure out why my code won’t work. There are no errors, the collision just isn’t detected.

Advertisement