Exemple #1
0
    def fire(self):
        """
        The calculations used to determine how a bullet will fire from the player.

        Inputs
        ============================================================================
        None

        Outputs
        ============================================================================
        None
        """
        # Angle of attack
        angle_radians = math.pi / 2 - math.radians(self.rotation)
        # Starting position
        ship_radius = self.image.width / 2
        bullet_x = self.x + math.cos(angle_radians) * ship_radius
        bullet_y = self.y + math.sin(angle_radians) * ship_radius
        # Creating the bullet
        new_bullet = bullet.Bullet(bullet_x, bullet_y, batch=self.batch)
        # Velocity
        bullet_vx = (self.velocity_x +
                     math.cos(angle_radians) * self.bullet_speed)
        bullet_vy = (self.velocity_y +
                     math.sin(angle_radians) * self.bullet_speed)
        new_bullet.velocity_x = bullet_vx
        new_bullet.velocity_y = bullet_vy
        # Adding the to the draw list
        self.new_objects.append(new_bullet)
Exemple #2
0
 def fire(self):
     angle_radians = -math.radians(self.rotation)
     ship_radius = self.image.width / 2
     bullet_x = self.x + math.cos(angle_radians) * ship_radius
     bullet_y = self.y + math.sin(angle_radians) * ship_radius
     new_bullet = bullet.Bullet(bullet_x, bullet_y, batch=self.batch)
     bullet_vx = (self.velocity_x +
                  math.cos(angle_radians) * self.bullet_speed)
     bullet_vy = (self.velocity_y +
                  math.sin(angle_radians) * self.bullet_speed)
     new_bullet.velocity_x = -bullet_vx
     new_bullet.velocity_y = -bullet_vy
     self.new_objects.append(new_bullet)
Exemple #3
0
 def fire(self):
     angle_radian = -math.radians(self.rotation)
     ship_radius = self.image.width / 2 + 20
     bullet_x = self.x + ship_radius * math.cos(angle_radian)
     bullet_y = self.y + ship_radius * math.sin(angle_radian)
     new_bullet = bullet.Bullet(x=bullet_x, y=bullet_y, batch=self.batch)
     bullet_vx = self.velocity_x + self.bullet_speed * math.cos(
         angle_radian)
     bullet_vy = self.velocity_y + self.bullet_speed * math.sin(
         angle_radian)
     new_bullet.velocity_x = bullet_vx
     new_bullet.velocity_y = bullet_vy
     self.new_objects.append(new_bullet)
Exemple #4
0
    def fire(self):
        "发射子弹"
        angle_radians = -math.radians(self.rotation)  #将角度转换成弧度并逆转方向

        "计算子弹的位置并实例化它"
        ship_radius = self.image.width // 2
        bullet_x = self.x + math.cos(angle_radians) * ship_radius
        bullet_y = self.y + math.sin(angle_radians) * ship_radius
        new_bullet = bullet.Bullet(bullet_x, bullet_y, batch=self.batch)

        "子弹速度的计算"
        bullet_vx = self.velocity_x + math.cos(
            angle_radians) * self.bullet_speed
        bullet_vy = self.velocity_y + math.sin(
            angle_radians) * self.bullet_speed
        new_bullet.velocity_x, new_bullet.velocity_y = bullet_vx, bullet_vy

        "把子弹加到new_objects列表,主循环会把它加到game_objects中"
        self.new_objects.append(new_bullet)

        resources.bullet_sound.play()
Exemple #5
0
def fire_bullet(ai_settings, screen, ship, bullets):
    # 创建子弹加入编组
    if len(bullets) < ai_settings.bullet_allowed:
        new_bullet = bullet.Bullet(ai_settings, screen, ship)
        bullets.add(new_bullet)