• 大小: 31KB
    文件类型: .zip
    金币: 2
    下载: 2 次
    发布日期: 2021-06-18
  • 语言: Python
  • 标签: python  

资源简介

Python编程——从入门到实践外星人入侵项目代码,内含各个代码文件,包括外星人入侵项目中需要用到的图片

资源截图

代码片段和文件信息

import pygame
from pygame.sprite import Sprite
class Alien(Sprite):
    “““表示单个外星人的类“““
    def __init__(self ai_settingsscreen):
        “““初始化外星人并设置起始位置“““
        super(Alien self).__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        # 加载外星人图像,并设置其rect属性
        self.image = pygame.image.load(“C:\python项目文件\飞机大战\images\lien.bmp“)
        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 blitme(self):
        “““在指定位置绘制外星人“““
        self.screen.blit(self.image self.rect)

    def update(self):
        “““向左或右移动外星人“““
        self.x += (self.ai_settings.alien_speed_factor * self.ai_settings.fleet_direction)
        self.rect.x = self.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

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-04-17 10:09  飞机大战\
     目录           0  2020-04-17 10:09  飞机大战\.idea\
     目录           0  2020-04-17 10:09  飞机大战\.idea\inspectionProfiles\
     文件         228  2020-01-16 16:02  飞机大战\.idea\inspectionProfiles\profiles_settings.xml
     文件         210  2020-01-16 16:04  飞机大战\.idea\misc.xml
     文件         276  2020-01-16 16:02  飞机大战\.idea\modules.xml
     文件       52096  2020-04-17 10:08  飞机大战\.idea\workspace.xml
     文件         398  2020-01-16 16:04  飞机大战\.idea\飞机大战.iml
     目录           0  2020-04-17 10:09  飞机大战\__pycache__\
     文件        1519  2020-01-29 14:27  飞机大战\__pycache__\alien.cpython-37.pyc
     文件        1264  2020-01-17 14:34  飞机大战\__pycache__\bullet.cpython-37.pyc
     文件        1244  2020-02-03 15:18  飞机大战\__pycache__\button.cpython-37.pyc
     文件        6437  2020-04-17 09:34  飞机大战\__pycache__\game_functions.cpython-37.pyc
     文件         816  2020-03-30 17:04  飞机大战\__pycache__\game_stats.cpython-37.pyc
     文件        2649  2020-03-30 17:11  飞机大战\__pycache__\scoreboard.cpython-37.pyc
     文件        1414  2020-04-17 08:18  飞机大战\__pycache__\setting.cpython-37.pyc
     文件        1700  2020-04-16 20:57  飞机大战\__pycache__\ship.cpython-37.pyc
     文件        1324  2020-01-29 14:12  飞机大战\alien.py
     文件        1626  2020-04-16 20:17  飞机大战\alien_invasion.py
     文件        1125  2020-01-17 13:34  飞机大战\bullet.py
     文件        1189  2020-02-03 15:18  飞机大战\button.py
     文件        8799  2020-04-17 09:34  飞机大战\game_functions.py
     文件         577  2020-03-30 16:41  飞机大战\game_stats.py
     目录           0  2020-04-17 10:09  飞机大战\images\
     文件       10494  2016-06-15 02:16  飞机大战\images\lien.bmp
     文件        8694  2016-06-15 02:16  飞机大战\images\ship.bmp
     文件        2833  2020-03-30 17:11  飞机大战\scoreboard.py
     文件        1466  2020-04-17 08:18  飞机大战\setting.py
     文件        2314  2020-04-16 20:57  飞机大战\ship.py

评论

共有 条评论