How do I detect collision in pygame?

In PyGame, basic collision detection can be done using pygame.Rect objects. The Rect object offers various methods for detecting collisions between objects. Note that even the collision of a rectangular object with a circular object such as a paddle and a ball in Pong game can be roughly detected by a collision between two rectangular … Read more

Object to shoot a projectile

I usually add bullets in this way: I pass the group that contains all sprites and the bullet group to the player instance and add new bullets to these group in the player’s handle_event method. import pygame as pg from pygame.math import Vector2 pg.init() screen = pg.display.set_mode((640, 480)) screen_rect = screen.get_rect() FONT = pg.font.Font(None, 24) … Read more

tech