I am creating a type Space Invader game, with a ship which can fire a bullet from its position, with direction velocity.
When I create a bullet from key input, the update method in Bullet affects the Players position and velocity as well, almost as it reference to the same values as Player. I want the bullet to fire from the players position and velocity.
class Player(pygame.sprite.Sprite):
def __init__(self, bullet_list):
super().__init__()
self.pos = Vector2(100,100)
self.vel = Vector2(1,1)
self.bullet_list = bullet_list
def input(self):
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
self.bullet_list.add(Bullet(self.pos, self.vel))
def update():
self.input()
class Bullet(pygame.sprite.Sprite):
def __init__(self, pos, vel):
super().__init__()
self.pos = pos
self.vel = vel
def update():
self.pos += vel
while True:
bullets = pygame.sprite.group()
players = pygame.sprite.group(Player1(bullets))
bullets.update()
players.update()
Tried to add the bullet in the main loop, but with same results.