資源簡介
python小游戲《外星人入侵》,源碼下載,包括矢量圖和代碼部分。

代碼片段和文件信息
import?pygame
from?pygame.sprite?import?Sprite
class?Alien(Sprite):
‘‘‘表示單個外星人的類‘‘‘
def?__init__(selfai_settingsscreen):
‘‘‘初始化外星人并設置其起始位置‘‘‘
super(Alienself).__init__()
self.screen=screen
self.ai_settings=ai_settings
#加載外星人圖像,并設置其rect屬性
self.image=pygame.image.load(‘images/alien.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.imageself.rect)
def?update(self):
‘‘‘向右移動外星人‘‘‘
self.x+=self.ai_settings.alien_speed_factor
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
def?update(self):
‘‘‘向左或向右移動外星人‘‘‘
self.x+=(self.ai_settings.alien_speed_factor*self.ai_settings.fleet_direction)
self.rect.x=self.x
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-25?00:12??__pycache__\
?????文件????????1646??2018-04-18?22:00??__pycache__\alien.cpython-36.pyc
?????文件????????1266??2018-04-16?22:58??__pycache__\bullet.cpython-36.pyc
?????文件????????1258??2018-04-22?09:42??__pycache__\button.cpython-36.pyc
?????文件????????6304??2018-04-25?00:12??__pycache__\game_functions.cpython-36.pyc
?????文件?????????815??2018-04-23?21:12??__pycache__\game_stats.cpython-36.pyc
?????文件????????2669??2018-04-24?20:29??__pycache__\scoreboard.cpython-36.pyc
?????文件????????1419??2018-04-24?20:41??__pycache__\settings.cpython-36.pyc
?????文件????????1588??2018-04-24?20:45??__pycache__\ship.cpython-36.pyc
?????文件????????1233??2018-04-18?21:36??alien.py
?????文件????????1344??2018-04-26?23:47??alien_invasion.py
?????文件?????????984??2018-04-16?22:46??bullet.py
?????文件????????1047??2018-04-19?22:52??button.py
?????文件????????7327??2018-04-25?00:12??game_functions.py
?????文件?????????502??2018-04-23?20:58??game_stats.py
?????目錄???????????0??2018-04-24?20:33??images\
?????文件???????10494??2018-04-17?09:24??images\alien.bmp
?????文件????????5061??2018-04-24?20:07??images\ship.bmp
?????文件????????7046??2018-04-13?22:43??images\ship1.bmp
?????文件??????117824??2018-04-13?22:44??images\ship2.bmp
?????文件????????2466??2018-04-24?20:29??scoreboard.py
?????文件????????1197??2018-04-24?20:41??settings.py
?????文件????????1449??2018-04-24?20:45??ship.py
- 上一篇:Flask項目實戰-超市商品管理平臺
- 下一篇:LBP算法實現
評論
共有 條評論