You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import pygame
from pygame . sprite import Sprite
class Bullet ( Sprite ) :
""" 用于管理从人那里发射的子弹的类 """
def __init__ ( self , ai_settings , screen , man ) :
""" 在船的当前位置创建一个项目符号对象 """
super ( Bullet , self ) . __init__ ( )
self . screen = screen
# 在( 0,0) 处创建bullet rect, 然后设置正确的位置
self . rect = pygame . Rect ( 0 , 0 , ai_settings . bullet_width ,
ai_settings . bullet_height )
self . rect . centerx = man . rect . centerx
self . rect . top = man . rect . top
# 存储项目符号位置的十进制值
self . y = float ( self . rect . y )
self . color = ai_settings . bullet_color
self . speed_factor = ai_settings . bullet_speed_factor
def update ( self ) :
""" 把子弹移到屏幕上. """
# 更新子弹(项目符号)的小数位置
self . y - = self . speed_factor
# 更新rect位置
self . rect . y = self . y
def draw_bullet ( self ) :
""" 把子弹画到屏幕上. """
pygame . draw . rect ( self . screen , self . color , self . rect )