How do you get pygame to give warning when player touches side of screen?

Define a pygame.Rect object for the player: player_rect = pygame.Rect(w, y, width, height) or get a rectangle from the player image (player_image): player_rect = player_image.get_Rect(topleft = (x, y)) Get the rectangle of the display Surface (screen) screen_rect = screen.get_rect() Evaluate if the player is out of the screen: if player_rect.left < screen_rect.left or player_rect.right < … Read more

Pygame – Issues creating projectiles, “add() argument after * must be an iterable, not int”

The issue is not the pygame.sprite.Group.add operation, but the obejct you want to add is not a pygame.sprite.Sprite object, because the object is not constructed at all. You missed to the super call in the constructor of Projectile. Furthermore the name of the constructor has to be __init__ rather _init_: class Projectile(pygame.sprite.Sprite): #Initialize values def … Read more

How to Flip Image in Pygame

See pygame.transform.flip(): flip(Surface, xbool, ybool) -> Surface This can flip a Surface either vertically, horizontally, or both. pygame.transform.flip() flips creates a new Surface from the source Surface which is flipped. e.g: my_flipped_image = pygame.transform.flip(my_image, True, False);

Can’t install pygame on mac

EDIT: I realized that these steps were originally intended for python3. It should still work for python2, but I can’t confirm, it’s just the best answer I have. Assuming you are using the newest macOS, here are the steps I used to install pygame. Try and uninstall what you installed for pygame previously, I’m not … Read more

How do you properly implement gravity to a free floating space object and some sort of friction when thrusting in opposite direction

When you press UP you don’t have to change the speed, but you have to set the acceleration: self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) self.acc += vec(PLAYER_ACC, 0).rotate(-self.rot) Add the acceleration to the velocity: self.vel += self.acc I recommend limiting the maximum. However, I recommend doing this separately for each direction: max_vel = 2 self.vel[0] = max(-max_vel, … Read more

pygame.sprite.LayeredUpdates.move_to_front() does not work

pygame.sprite.LayeredUpdates is a Group object that manages pygame.sprite.Sprite objects. pygame.sprite.LayeredUpdates.move_to_front is a Method Objects. The argument of pygame.sprite.LayeredUpdates.move_to_front must be a pygame.sprite.Sprite objects contained in the Group: Brings the sprite to front, changing sprite layer to topmost layer Therefore you must create a Group layered_group = pygame.sprite.LayeredUpdates() That contains pygame.sprite.Sprite objects. In the following my_sprite … Read more