Python Forum
[PyGame] shooting system in asteroid games
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] shooting system in asteroid games
#1
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?
Reply
#2
Here an example.
syafiq14 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Fun games to help with Low_Ki_ 2 4,049 May-10-2017, 01:23 AM
Last Post: Low_Ki_

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020