|
|
|
@ -0,0 +1,40 @@
|
|
|
|
|
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)
|