1 Star 0 Fork 0

zhuo木鸟/AlienInvasionGame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
alien.py 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zhuowoodbird/alien-invasion-game.git
[email protected]:zhuowoodbird/alien-invasion-game.git
zhuowoodbird
alien-invasion-game
AlienInvasionGame
master

搜索帮助