This commit is contained in:
206530220 2021-06-18 14:56:05 +08:00
parent fce4e234b0
commit ed06427872
1 changed files with 16 additions and 1 deletions

17
ship.py
View File

@ -27,4 +27,19 @@ class Ship(Sprite):
self.moving_up = False
self.moving_down = False
def update(self):
"""根据移动标志调整飞船的位置"""
# 更新飞船的center值而不是rect
if self.moving_right and self.rect.right < self.screen_rect.right:
self.centerx += self.ai_settings.ship_speed_factor
if self.moving_left and self.rect.left > 0:
self.centerx -= self.ai_settings.ship_speed_factor
if self.moving_up and self.rect.top > 0:
self.centery -= self.ai_settings.ship_speed_factor
if self.moving_down and self.rect.bottom < self.screen_rect.bottom:
self.centery += self.ai_settings.ship_speed_factor
# 根据self.center更新rect对象
self.rect.centerx = self.centerx
self.rect.centery = self.centery