I'm creating a SHMUP type of game for my own amusement and I was having trouble on how I could change the "bullet spawner" position to another fixed position whenever I pressed a key, let's say I want an offensive playstyle and a defensive one, I wanted a visual difference and decided to close the bullets distance from the player, yet I do not know how, care to aid me?
Current situation:
class MainFire(pygame.sprite.Sprite):
def __init__(self, x, y, filename, posx, posy):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(os.path.join(img_folder, filename)).convert()
self.image.set_colorkey(WHITE)
self.rect = self.image.get_rect()
self.rect.centerx = x
self.rect.bottom = y
self.speedy = - 20
posx += self.rect.centerx
posy += self.rect.bottom
def update(self):
self.rect.y += self.speedy
if self.rect.bottom < 0:
self.kill()
class SubFire(pygame.sprite.Sprite):
def __init__(self, x, y, filename, posx, posy):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(os.path.join(img_folder, filename)).convert()
self.image.set_colorkey(WHITE)
self.rect = self.image.get_rect()
self.rect.centerx = x
self.rect.bottom = y
self.speedy = - 20
posx += self.rect.centerx
posy += self.rect.bottom
def update(self):
self.rect.y += self.speedy
if self.rect.bottom < 0:
self.kill()
elif self.rect.left < -10:
self.kill()
elif self.rect.right > GAMEWIDTH:
self.kill()
I reckon that if I fix posx and posy it would finally work, posx should add x and integer as posy with y (giving a new position to the bullet, the velocity is already established, the problem is "from where does the gun appear and not the bullet itself")