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 Bazi ( Sprite ) :
""" 创建一个代表靶子的类. """
def __init__ ( self , ai_settings , screen ) :
""" 初始化靶子,并设置其起始位置 """
super ( Bazi , self ) . __init__ ( )
self . screen = screen
self . ai_settings = ai_settings
# 加载外来图像, 并设置其rect属性
self . image = pygame . image . load ( ' images/bazi.png ' )
self . rect = self . image . get_rect ( )
# 在屏幕左上角启动每个新靶子
self . rect . x = self . rect . width
self . rect . y = self . rect . height
# 存储靶子的准确位置
self . x = float ( self . rect . x )
def check_edges ( self ) :
""" 如果靶子在屏幕边缘, 则返回True。 """
screen_rect = self . screen . get_rect ( )
if self . rect . right > = screen_rect . right :
return True
elif self . rect . left < = 0 :
return True
def update ( self ) :
""" 靶子的移动(向左或者向右) """
self . x + = ( self . ai_settings . bazi_speed_factor *
self . ai_settings . fleet_direction )
self . rect . x = self . x
def blitme ( self ) :
""" 在当前位置绘制靶子 """
self . screen . blit ( self . image , self . rect )