Python Forum

Full Version: shooting system in asteroid games
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm making a game like the classic asteroid game, I can make the movement and acceleration but I don't understand how to make the shooting system similar to the original game.

code :

class Player(pygame.sprite.Sprite):
    def __init__(self, image, width, height, pos, rot, folder="space game pack\ship"):
        super().__init__()
        self.width = width
        self.height = height
        self.image = load_image(image, folder, width, height, rot)
        self.original_image = self.image
        self.rect = self.image.get_rect(center=pos)
        self.position = pygame.math.Vector2(pos)
        self.direction = pygame.math.Vector2(0, 1)
        self.speed = 0
        self.angle_speed = 0
        self.angle = 0
        self.health = 100
     
   """
   another function
   """
   
   def update(self):
       if self.angle_speed != 0:
           self.direction.rotate_ip(self.angle_speed)
           self.angle += self.angle_speed
           self.image = pygame.transform.rotate(self.original_image, -self.angle)
           self.rect = self.image.get_rect(center=self.rect.center)
       self.position += self.direction * self.speed
       self.rect.center = self.position


class Laser:
    def __init__(self, pos):
        self.img = load_image("laser_2.png", "space game pack\laser", 16, 16, 0)
        self.pos = pygame.math.Vector2(pos)
        self.speed = 1

    # direction -> player direction
    def move(self, direction):
        self.pos -= direction * self.speed
    
    def draw(self, window):
        window.blit(self.img, self.pos)
with the code above makes the bullet or laser follow the direction according to the player's direction, but not the direction of the image (the image doesn't rotate in the same direction), the bullet is also not integrated with the player, and the bullet or laser appears only once

how to make the feature?
Here an example.