I'm completely new to prgramming and python/pygame (and I'm german so please exuse me for the suboptimal english).
Well,
I created a Sprite:
class Holzfaeller_sprite(pygame.sprite.Sprite):
def __init__ (self, width = 20, height = 20):
#super(Holzfaeller_sprite, self).__init__()
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((width, height))
self.image = pygame.image.load("holzfaeller.png")
self.rect = self.image.get_rect()
def set_position(self, x, y):
self.rect.x = x
self.rect.y = y
Then I created a group and added the sprite to it:
baut_group = pygame.sprite.Group()
a_Baut = Holzfaeller_sprite()
b_Baut = Festung_sprite()
baut_group.add(a_Baut, b_Baut)
In my gameloop I want to check, if the sprite got clicked on or not with:
elif event.type == pygame.MOUSEBUTTONDOWN and holzfaeller is False and festung is False:
if a_Baut.rect.collidepoint(possi):
anklickbar = False
print("not working")
elif b_Baut.rect.collidepoint(possi):
anklickbar = False
print("not working")
elif anklickbar is True:
tilemap_1[possi_y][possi_x] = 0
Well that is working out great but it's gonna be a lot of work and code to add to the line elif event.type == pygame.MOUSEBUTTONDOWN and holzfaeller is False and festung is False
.
So I asked my self, if there is a possibility to check if the possition, where I clicked on is a sprite of a specific sprite group.
I hope you understand, what i mean.
Thanks!