代码拉取完成,页面将自动刷新
import pygame
from pygame.sprite import Sprite
class Alien(Sprite):
""" A class to represent a single alien in the fleet. """
def __init__(self, ai_settings, screen):
""" Initialize the alien and set its starting position. """
super().__init__()
self.screen = screen
self.ai_settings = ai_settings
# Load the alien image and set its rect attribute
self.image = pygame.image.load(r'images/alien.bmp')
self.rect = self.image.get_rect()
# Start each new alien near the top left of the screen.
self.rect.x = self.rect.width
self.rect.y = self.rect.height
# Store the alien's exact position.
self.x = float(self.rect.x)
def blitme(self):
""" Draw the alien at its current location. """
self.screen.blit(self.image, self.rect)
def check_edges(self):
""" Return True if aliens is at edge of screen. """
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):
""" Move the alien right. """
self.x += (self.ai_settings.alien_speed_factor \
* self.ai_settings.fleet_direction)
self.rect.x = self.x
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。