currently, i’m using all four keys to steer the snake left, right, up and down. I’m wondering how can i only use left and right key to move the snake around. can anyone guide me how to do that? Answer Define the directions as follows: 0: move up 1: move right 2: move down 3: move right When right is
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
Why does it ignore my continue in the for-loop? [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 3 years ago. Improve this question
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
Unable to install pygame on Python via pip (Windows 10)
Currently unable to install Pygame via pip: Getting this message: Concerned by it being termed an EOF error, is this an error in the module itself? Answer There’s dev versions available as of now. Get them via
Could not open resource file, pygame error: “FileNotFoundError: No such file or directory.”
Answer The resource (image, font, sound, etc.) file path has to be relative to the current working directory. The working directory is possibly different from the directory of the python file. It is not enough to put the files in the same directory or sub directory. You also need to set the working directory. Alternatively, you can create an absolute
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.