ship
This commit is contained in:
parent
fce4e234b0
commit
ed06427872
17
ship.py
17
ship.py
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue