How can i get the first element from a sprite group in pygame - python

I create the sprite group land. For that, i use the class Landschaft and the while loop
How can i get from first sprite in the sprite group land rect.x , rect.y rect.w and rect.h ?
class Landschaft(pygame.sprite.Sprite):
def __init__(self,image):
pygame.sprite.Sprite.__init__(self)
self.image = image
#self.mask = pygame.mask.from_surface(self.image )
self.rect = self.image.get_rect()
#pygame.draw.ellipse(self.image, red, [self.rect.x,self.rect.y,self.rect.width,self.rect.height],3)
x=random.randrange(0, breite -60)
y=random.randrange(200, hoehe - 200)
self.rect.center = (x,y)
land = pygame.sprite.Group()
while len(land) < anzahl_gegenstaende:
ii = len(land)
img = pygame.image.load(f"Bilder/Gegenstaende/geg{ii}.png")
if ii == 0:
img = pygame.transform.scale(img,(breite))
else:
zb,zh = img.get_rect().size
scale_hoehe =100
scale_breite = int(100 * zb / zh)
#img = img.convert_alpha()
img = pygame.transform.scale(img,(scale_breite,scale_hoehe))
m = Landschaft(img)
if not pygame.sprite.spritecollide(m, land, False):
land.add(m)

A list of sprites from a pygame.sprite.Group can be obtained with the sprites() method:. Therefore the first sprite in the Group is:
first_sprite = group.sprites()[0]

Problem?
Your land = pygame.sprite.Group() prevents you from getting the first element from a sprite group in pygame. This is a fairly common problem. To get it you have to use sprites() as you did, but in a different way. You approached the solution with your code. You came close.
You have to write, as a solution to your problem, group.sprites() (with [0]) (not pygame.sprite.Group ()) to get from first sprite in the sprite group land rect.x, rect.y rect.w and rect.h
Solution?
The solution to your problem is:
class Landschaft(pygame.sprite.Sprite):
def __init__(self,image):
pygame.sprite.Sprite.__init__(self)
self.image = image
#self.mask = pygame.mask.from_surface(self.image )
self.rect = self.image.get_rect()
#pygame.draw.ellipse(self.image, red, [self.rect.x,self.rect.y,self.rect.width,self.rect.height],3)
x=random.randrange(0, breite -60)
y=random.randrange(200, hoehe - 200)
self.rect.center = (x,y)
land = group.sprites()[0]
while len(land) < anzahl_gegenstaende:
ii = len(land)
img = pygame.image.load(f"Bilder/Gegenstaende/geg{ii}.png")
if ii == 0:
img = pygame.transform.scale(img,(breite))
else:
zb,zh = img.get_rect().size
scale_hoehe =100
scale_breite = int(100 * zb / zh)
#img = img.convert_alpha()
img = pygame.transform.scale(img,(scale_breite,scale_hoehe))
m = Landschaft(img)
if not pygame.sprite.spritecollide(m, land, False):
land.add(m)

Related

How do i fix the hitbox for my pygame sprite barring resizing every image?

class Entity():
def __init__(self, char_type, x, y, scale):
self.char_type = char_type
self.flip = False
self.direction = 1
self.vel_y = 0
self.jump = False
self.attacking = False
self.animation_list = []
self.frame_index = 0
self.action = 0
self.update_time = pygame.time.get_ticks()
#load all images
animation_types = ['idle', 'run', 'jump', 'attack', 'death', 'hit']
for animation in animation_types:
#reset temporary list of images
temp_list = []
#count number of files in the folder
num_of_frames = len(os.listdir(f"img/{self.char_type}/{animation}"))
for i in range(num_of_frames-2):
img = pygame.image.load(f"img/{self.char_type}/{animation}/{i}.png")
img = pygame.transform.scale(img, (img.get_width()*scale,img.get_height()*3))
temp_list.append(img)
self.animation_list.append(temp_list)
self.image = self.animation_list[self.action][self.frame_index]
self.rect = self.image.get_rect()
self.rect.center = (x, y)
This is my first time attempting a pygame project and i'm having issues. Basically the frames are really big so the rectangle I made with self.rect = self.image.get_rect() to create the hitbox for my playable character is massive. what it looks like I tried solving this by using self.rect = self.image.get_bounding_rect()This did solve the issue with having a massive rectangle however it made the image which I drew using the following method
def draw(self, surface):
img = pygame.transform.flip(self.image, self.flip, False)
pygame.draw.rect(surface, (255, 0 , 0), self.rect)
surface.blit(img, self.rect)
to not be centered over the rectangle which should be its hitbox. That ended up looking like this. I think that the issue is that
See How to get the correct dimensions for a pygame rectangle created from an image and How can I crop an image with Pygame?:
Use pygame.Surface.get_bounding_rect() and pygame.Surface.subsurface to get a cropped region from your image.
e.g.:
original_image = pygame.image.load(f"img/{self.char_type}/{animation}/{i}.png")
crop_rect = original_image.get_bounding_rect()
cropped_image = original_image.subsurface(crop_rect).copy()
img = pygame.transform.scale(cropped_image,
(cropped_image.get_width()*scale, cropped_image.get_height()*3))

'pygame.Surface' object has no attribute 'rect' despite the code being identical right before it and working just fine?

I just need to get some sprites going on a game project, and I got one of them going but 2, 3 and, 4 are just refusing to work and are giving me the error, "'pygame.Surface' object has no attribute 'rect'" Here is my code leading up to the error: It isn't all of my code, but hopefully enough to see the issue.
import pygame
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
YELLOW = (255,255,0)
score = 0
play = 0
class Sprite(pygame.sprite.Sprite):
def __init__(self,filename):
super().__init__()
self.image = pygame.image.load(filename).convert()
self.image.set_colorkey(BLACK)
self.rect = self.image.get_rect()
class Player(Sprite):
def update(self):
# Get the current mouse position. This returns the position
# as a list of two numbers.
pos = pygame.mouse.get_pos()
# Now see how the mouse position is different from the current
# player position. (How far did we move?)
diff_x = self.rect.x - pos[0]
diff_y = self.rect.y - pos[1]
# Loop through each block that we are carrying and adjust
# it by the amount we moved.
# Now wet the player object to the mouse location
self.rect.x = pos[0]
self.rect.y = pos[1]
class Block(pygame.sprite.Sprite):
def __init__(self, color, width, height):
# Call the parent class (Sprite) constructor
super().__init__()
# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
self.image = pygame.Surface([width, height])
self.image.fill(color)
# Fetch the rectangle object that has the dimensions of the image
# image.
# Update the position of this object by setting the values
# of rect.x and rect.y
self.rect = self.image.get_rect()
#class Sound():
#def play(filename):
#pygame.mixer.music.load(filename)
# Initialize Pygame
pygame.init()
# Set the height and width of the screen
screen_width = 750
screen_height = 500
screen = pygame.display.set_mode([screen_width, screen_height])
pygame.display.set_caption("LARP")
# This is a list of 'sprites.' Each block in the program is
# added to this list. The list is managed by a class called 'Group.'
block_list = pygame.sprite.Group()
#TITLE SCREEN
title_image = pygame.image.load("title.png").convert_alpha()
quit_image = pygame.image.load("quit.png").convert_alpha()
logo_image = pygame.image.load("logo.png").convert_alpha()
background_image = pygame.image.load("title_screen.png").convert_alpha()
map_image = pygame.image.load("map.png").convert_alpha()
quit_block = pygame.sprite.Group()
start_block = pygame.sprite.Group()
Title = pygame.mixer.Sound("title_song.wav")
Map = pygame.mixer.Sound("map_song.wav")
#PLAYER
player_image = pygame.image.load("player.png").convert_alpha()
#CUTSCENES
cutscene_1 = pygame.image.load("cutscene_1.png").convert_alpha()
continue_button = pygame.image.load("cont.png").convert_alpha()
continue_list = pygame.sprite.Group()
#NUMBERS
one = pygame.image.load("one.png").convert_alpha()
two = pygame.image.load("two.png").convert_alpha()
three = pygame.image.load("three.png").convert_alpha()
four = pygame.image.load("four.png").convert_alpha()
lvlselect = pygame.sprite.Group()
#OTHER
back_button = pygame.image.load("back.png").convert_alpha()
back_butt = pygame.sprite.Group()
# This is a list of every sprite.
# All blocks and the player block as well.
player_list = pygame.sprite.Group()
all_sprites_list = pygame.sprite.Group()
#for i in range(50):
#This represents a block
#block = Block(BLACK, 20, 15)
#Set a random location for the block
#block.rect.x = random.randrange(screen_width)
#block.rect.y = random.randrange(screen_height)
#Add the block to the list of objects
#block_list.add(block)
#all_sprites_list.add(block)
#TITLE SCREEN
title = Sprite("title.png")
title.rect.x = 340
title.rect.y = 230
all_sprites_list.add(title)
start_block.add(title)
quitg = Sprite("quit.png")
quitg.rect.x = 340
quitg.rect.y = 350
all_sprites_list.add(quitg)
quit_block.add(quitg)
logo = Sprite("logo.png")
logo.rect.y = 90
logo.rect.x = 310
all_sprites_list.add(logo)
block_list.add(logo)
#CUTSCENE
continues = Sprite("cont.png")
continues.rect.x = 608
continues.rect.y = 466
continue_list.add(continues)
#NUMBERS
one = Sprite("one.png")
one.rect.x = 55
one.rect.y = 410
two.rect.x = 155
two.rect.y = 410
three.rect.x = 255
three.rect.y = 410
four.rect.x = 355
four.rect.y = 410
lvlselect.add(one)
lvlselect.add(two)
lvlselect.add(three)
lvlselect.add(four)
#OTHER
back = Sprite("back.png")
back.rect.x = 0
back.rect.y = 12
back_butt.add(back)
#PLAYER
player = Player("player.png")
player_list.add(player)
all_sprites_list.add(player)
You need tp create Sprite objects for two, three and for, like you do it for one:
one = Sprite("one.png")
two = Sprite("two.png")
three = Sprite("three.png")
four = Sprite("four.png")
You don't need the Surface objects at all:
one = pygame.image.load("one.png").convert_alpha()
two = pygame.image.load("two.png").convert_alpha()
three = pygame.image.load("three.png").convert_alpha()
four = pygame.image.load("four.png").convert_alpha()

draw the member of a group in pygame

I want to draw the single images of the group land. but i got only the image gegend[0]
class Landschaft(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = gegend[0]
self.rect = self.image.get_rect()
self.rect.x = random.randrange(40, breite -20)
self.rect.y = random.randrange(100, hoehe - 200)
gegend = []
for i in range(10):
img = pygame.image.load(f"Bilder/ballons/ballon{i}.png")
img = pygame.transform.scale(img,(175,175))
gegend.append(img)
land = pygame.sprite.Group()
while len(land) < 3:
m = Landschaft()
land.add(m)
land.draw(screen)
Make the image an argument of the constructor:
class Landschaft(pygame.sprite.Sprite):
def __init__(self, image):
pygame.sprite.Sprite.__init__(self)
self.image = image
self.rect = self.image.get_rect()
self.rect.x = random.randrange(40, breite -20)
self.rect.y = random.randrange(100, hoehe - 200)
Pass different images to the constructor when you create the objects. e.g.: choose a random image form the list gegend with random.choice:
land = pygame.sprite.Group()
while len(land) < 3:
image = random.choice(gegend)
m = Landschaft(image)
land.add(m)
Or show the first 3 images from the list:
for i in range(3):
m = Landschaft(gegend[i])
land.add(m)

Sprite Is Not Rotating Towards The Player Properly How Do I Fix This? [duplicate]

This question already has answers here:
How do I rotate an image around its center using Pygame?
(6 answers)
How do I make my player rotate towards mouse position?
(1 answer)
Closed 2 years ago.
I am trying to make my sprites rotate towards the player, but the rotation is out of place. Here is a video of the behaviour.
I am not sure how to fix this,
Sprite class
#-------------------------------- enemy shoots left and right
shotsright = pygame.image.load("canss.png")
class enemyshoot:
def __init__(self,x,y,height,width,color):
self.x = x
self.y =y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
self.health = 10
self.hitbox = (self.x + -20, self.y + 30, 31, 57)
#-------------------------------------------------------
# Make a Reference Copy of the bitmap for later rotation
self.shootsright = pygame.image.load("canss.png")
self.shootsright = pygame.transform.scale(self.shootsright,(self.shootsright.get_width()-150,self.shootsright.get_height()-150))
self.image = self.shootsright
self.rect = self.image.get_rect()
self.position = pygame.math.Vector2( (200, 180) )
self.isLookingAtPlayer = False
def draw(self):
self.rect.topleft = (self.x,self.y)
window.blit(self.image, self.rect)
self.hits = (self.x + 20, self.y, 28,60)
pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 60, 100, 10)) # NEW
pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 60, 100 - (5 * (10 - self.health)), 10))
self.hitbox = (self.x + 200, self.y + 200, 51, 65)
def lookAt( self, coordinate ):
# Rotate image to point in the new direction
delta_vector = coordinate - self.position
radius, angle = delta_vector.as_polar()
self.image = pygame.transform.rotate(self.shootsright, -angle)
# Re-set the bounding rectangle and position since
# the dimensions and centroid will have (probably) changed.
current_pos = self.rect.center
self.rect = self.image.get_rect()
self.rect.center = current_pos
black = (0,0,0)
enemyshooting = []
platformGroup = pygame.sprite.Group
platformList = []
level = [" p p p p p ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",]
for iy, row in enumerate(level):
for ix, col in enumerate(row):
if col == "p":
new_platforms = enemyshoot(ix*10, iy*50, 10,10,(255,255,255))
enemyshooting.append(new_platforms)
this is the rotating part
class enemyshoot:
def __init__(self,x,y,height,width,color):
# [................]
#-------------------------------------------------------
# Make a Reference Copy of the bitmap for later rotation
self.shootsright = pygame.image.load("canss.png")
self.shootsright = pygame.transform.scale(self.shootsright,(self.shootsright.get_width()-150,self.shootsright.get_height()-150))
self.image = self.shootsright
self.rect = self.image.get_rect()
self.position = pygame.math.Vector2( (200, 180) )
def lookAt( self, coordinate ):
# Rotate image to point in the new direction
delta_vector = coordinate - pygame.math.Vector2(self.rect.center)
radius, angle = delta_vector.as_polar()
self.image = pygame.transform.rotate(self.shootsright, -angle)
# Re-set the bounding rectangle and position since
# the dimensions and centroid will have (probably) changed.
current_pos = self.rect.center
self.rect = self.image.get_rect()
self.rect.center = current_pos
This is where I call the LookAt function to face the player:
# so instead of this
for enemyshoot in enemyshooting:
if not enemyshoot.isLookingAtPlayer:
enemyshoot.lookAt((playerman.x, playerman.y))
The rotation is out of place, and I can't figure out how to fix it. I am trying to make the mouth of the cannon rotate towards the player because that's where the bullets will append from.
I concur with everything #Rabbid76 says in the above answer.
I suspect part of your problem may be that the "human readable" part of the bitmap is not centered around the bitmap's centroid. Thus when rotated, it "sweeps" through an arc, rather than being rotated "around itself". (The preserving of the centre co-ordinate is an important step here to maintain a smooth rotation about the centroid of the object).
Consider the two bitmaps (the image on the right has a large 3/4 transparent section top-left):
Both are rotated around their centroid, but since the visible part on the 2nd image is not centred, it rotates weirdly.
So ensure your actual bitmap is centred within itself.
Reference Code:
import pygame
import random
# Window size
WINDOW_WIDTH = 800
WINDOW_HEIGHT = 400
WINDOW_SURFACE = pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE
DARK_BLUE = ( 3, 5, 54 )
class RotationSprite( pygame.sprite.Sprite ):
def __init__( self, image, x, y, ):
pygame.sprite.Sprite.__init__(self)
self.original = image
self.image = image
self.rect = self.image.get_rect()
self.rect.center = ( x, y )
# for maintaining trajectory
self.position = pygame.math.Vector2( ( x, y ) )
self.velocity = pygame.math.Vector2( ( 0, 0 ) )
def lookAt( self, co_ordinate ):
# Rotate image to point in the new direction
delta_vector = co_ordinate - self.position
radius, angle = delta_vector.as_polar()
self.image = pygame.transform.rotozoom( self.original, -angle, 1 )
# Re-set the bounding rectagle
current_pos = self.rect.center
self.rect = self.image.get_rect()
self.rect.center = current_pos
### initialisation
pygame.init()
pygame.mixer.init()
window = pygame.display.set_mode( ( WINDOW_WIDTH, WINDOW_HEIGHT ), WINDOW_SURFACE )
pygame.display.set_caption( "Rotation Example" )
### Missiles!
rotation_sprites = pygame.sprite.Group()
rotation_image1 = pygame.image.load( 'rot_offcentre_1.png' )
rotation_image2 = pygame.image.load( 'rot_offcentre_2.png' )
rotation_sprites.add( RotationSprite( rotation_image1, WINDOW_WIDTH//3, WINDOW_HEIGHT//2 ) )
rotation_sprites.add( RotationSprite( rotation_image2, 2*( WINDOW_WIDTH//3 ), WINDOW_HEIGHT//2 ) )
### Main Loop
clock = pygame.time.Clock()
done = False
while not done:
# Handle user-input
for event in pygame.event.get():
if ( event.type == pygame.QUIT ):
done = True
elif ( event.type == pygame.MOUSEBUTTONUP ):
# On mouse-click
pass
# Record mouse movements for positioning the paddle
mouse_pos = pygame.mouse.get_pos()
for m in rotation_sprites:
m.lookAt( mouse_pos )
rotation_sprites.update()
# Update the window, but not more than 60 FPS
window.fill( DARK_BLUE )
rotation_sprites.draw( window )
pygame.display.flip()
# Clamp FPS
clock.tick_busy_loop(60)
pygame.quit()
self.position is set in the constructor, but it is not updated. Use the self.rect.center to compute the direction vector:
delta_vector = coordinate - pygame.math.Vector2(self.rect.center)
Use math.atan2 to compute the angle of rotation:
(See How do I make my player rotate towards mouse position?)
angle = (180 / math.pi) * math.atan2(-delta_vector.x, -delta_vector.y)
Setting the rectangle position in draw struggles with rotating the sprite in lookAt. Note the size of the rotated rectangle is enlarged. See How do I rotate an image around its center using Pygame?.
I recommend to set the look-at position in lookAt and to compute the rotated image in draw:
class enemyshoot:
def __init__(self,x,y,height,width,color):
# [...]
self.look_at_pos = (x, y)
def draw(self):
self.rect = self.shootsright.get_rect(topleft = (self.x, self.y))
dx = self.look_at_pos[0] - self.rect.centerx
dy = self.look_at_pos[1] - self.rect.centery
angle = (180 / math.pi) * math.atan2(-dx, -dy)
self.image = pygame.transform.rotate(self.shootsright, angle)
self.rect = self.image.get_rect(center = self.rect.center)
window.blit(self.image, self.rect)
self.hits = (self.x + 20, self.y, 28,60)
pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 60, 100, 10)) # NEW
pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 60, 100 - (5 * (10 - self.health)), 10))
self.hitbox = (self.x + 200, self.y + 200, 51, 65)
def lookAt(self, coordinate):
self.look_at_pos = coordinate

Pygame collision detection not working with rotated image

I don't understand why the sprite collision detection is not taking the image rotation into account.
I tried different functions but they didn't work out for me.
CarSprites.py:
import pygame, math, random
class CarSprite(pygame.sprite.Sprite):
MIN_FORWARD_SPEED = 5
ACCELERATION = 2
TURN_SPEED = 5
IS_DUMMY = False
def __init__(self, image, position, direction):
pygame.sprite.Sprite.__init__(self)
self.src_image = pygame.transform.scale(pygame.image.load(image), (51, 113))
self.position = position
self.rect = self.src_image.get_rect()
self.rect.center = self.position
self.speed = 0
self.direction = direction
self.k_left = self.k_right = self.k_down = self.k_up = 0
def update(self, deltat):
# SIMULATION
#speed
self.speed += (self.k_up + self.k_down)
if self.speed < self.MIN_FORWARD_SPEED:
self.speed = self.MIN_FORWARD_SPEED
self.speed += (self.k_up + self.k_down)
if self.speed > self.MIN_FORWARD_SPEED * 2:
self.speed = self.MIN_FORWARD_SPEED * 2
#direction
self.direction += (self.k_right + self.k_left)
x, y = self.position
rad = self.direction * math.pi / 180
x += -self.speed*math.sin(rad)
y += -self.speed*math.cos(rad)
self.position = (x, y)
self.image = pygame.transform.rotate(self.src_image, self.direction)
self.rect = self.image.get_rect()
self.rect.center = self.position
#Emulate friction with road and wind
if self.speed > self.MIN_FORWARD_SPEED :
self.speed += -0.1
class DummyCarSprite(pygame.sprite.Sprite):
#MIN_FORWARD_SPEED = 5
#MIN_REVERSE_SPEED = 10.1
#MAX_FORWARD_SPEED_ABOVE_MIN = 5
#ACCELERATION = 2
#TURN_SPEED = 5
def __init__(self, image, position, direction):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.transform.scale(pygame.image.load(image), (51, 113))
self.position = position
self.rect = self.image.get_rect()
self.rect.center = self.position
self.speed = 0
self.direction = direction
self.k_left = self.k_right = self.k_down = self.k_up = 0
if random.randint(0,1) == 1 :
self.direction = self.direction + 180
game.py
def GetDummyCars() :
allDummyCars = [
#Row1
#DummyCarSprite(getCarImage(), (211.9915431212928, 209.36603413022453), 180),
#DummyCarSprite(getCarImage(), (268.9915431212928, 209.36603413022453), 180),
DummyCarSprite(getCarImage(), (325.9915431212928, 209.36603413022453), 180),
DummyCarSprite(getCarImage(), (382.9915431212928, 209.36603413022453), 180)
#etc. etc.
]
dummyCars = []
for dummyCar in allDummyCars :
if random.randint(0,1) == 1 :
dummyCars.append(dummyCar)
return pygame.sprite.RenderPlain(*dummyCars)
playerCar = CarSprite(playerCarImagePath, (1550, 100), 90)
playerCar_group = pygame.sprite.RenderPlain(playerCar)
dummyCar_group = GetDummyCars()
#collisions with dummy cars
dummyCarCollisions = pygame.sprite.groupcollide(playerCar_group, dummyCar_group)
if dummyCarCollisions != {}:
lose_condition = True
playerCar.src_image = pygame.image.load('images/collision.png')
seconds = 0
playerCar.speed = 0
playerCar.MIN_FORWARD_SPEED = 0
playerCar.MAX_FORWARD_SPEED_ABOVE_MIN = 0
playerCar.k_right = 0
playerCar.k_left = 0
I would like to find a way to detect collision between the sprites in the 2 car groups, or collision between the player sprite and the dummycar_group (each would work out for me) that takes the rotation of the image into account.
What happens now is when I steer the car, the car image rotates but it looks like the collision detection doesn't see that.
Is there a better function i can use that could handle this?
My full source code: dropbox
I found this question very interesting and fun to work on and fix! Thanks for posting!
I have found the problem and it is rather unfortunate. Your code runs perfectly from what I have seen. The problem is that pygame uses rectangles for collision detection which are not precise enough.
You are applying the rotation to the image but that just makes it bigger and less accurate. I have highlighted the problem with the addition of rendiering debug lines in the GameLoop function.
# draw some debug lines
pygame.draw.rect(screen, (255, 0, 0), playerCar.rect, 1)
for dummyCar in dummyCar_group.sprites():
pygame.draw.rect(screen, (0, 0, 255), dummyCar.rect, 1)
Add these lines in and you shall see for yourself.
The only solution that I can think of is to add in the functionality to use polygons for collision detection yourself.
The way I would implement this is to:
Stop using the rect attribute of all Sprites for collision detection and stop using any methods for collision detection that use the underlying Rects, e.g pygame.sprite.spritecollide().
add a pointlist field to all sprites that need it which will store all the points of the polygon
Implement your own function that takes in two lists of points and returns if they overlap
I hope that this answer helped you and if you have any further questions please feel free to post a comment below!

Categories

Resources